Exemple #1
0
 def testSuccessUnwind(self):
     self.assertEqual(
         [
             FunctionUnwind(address=0x100,
                            size=1024,
                            address_unwinds=(
                                AddressUnwind(
                                    address_offset=0x0,
                                    unwind_type=UnwindType.RETURN_TO_LR,
                                    sp_offset=0,
                                    registers=(),
                                ),
                                AddressUnwind(
                                    address_offset=0x200,
                                    unwind_type=UnwindType.RETURN_TO_LR,
                                    sp_offset=0,
                                    registers=(),
                                ),
                            ))
         ],
         list(
             GenerateUnwinds([
                 FunctionCfi(size=1024,
                             address_cfi=(
                                 AddressCfi(address=0x100,
                                            unwind_instructions='RETURN'),
                                 AddressCfi(address=0x300,
                                            unwind_instructions='RETURN'),
                             ))
             ],
                             parsers=[MockReturnParser()])))
Exemple #2
0
    def testReadFunctionCfiTombstoneFiltered(self):
        input_lines = [
            'STACK CFI INIT 0 50 .cfa: sp 0 + .ra: lr',  # Tombstone function.
            'STACK CFI 2 .cfa: sp 24 + .ra: .cfa - 4 + ^ r4: .cfa - 16 + ^ '
            'r5: .cfa - 12 + ^ r7: .cfa - 8 + ^',
            'STACK CFI INIT 15b6490 4 .cfa: sp 0 + .ra: lr',
        ]

        f = io.StringIO(''.join(line + '\n' for line in input_lines))

        self.assertEqual([
            FunctionCfi(4, (AddressCfi(0x15b6490, '.cfa: sp 0 + .ra: lr'), ))
        ], list(ReadFunctionCfi(f)))
Exemple #3
0
 def testInvalidInitialUnwindInstructionAsserts(self):
     self.assertRaises(
         AssertionError, lambda: list(
             GenerateUnwinds([
                 FunctionCfi(size=1024,
                             address_cfi=(
                                 AddressCfi(address=0x100,
                                            unwind_instructions='UNKNOWN'),
                                 AddressCfi(address=0x200,
                                            unwind_instructions='RETURN'),
                             ))
             ],
                             parsers=[MockReturnParser()])))
Exemple #4
0
    def testReadFunctionCfiMultipleFunctions(self):
        input_lines = [
            'STACK CFI INIT 15b6490 4 .cfa: sp 0 + .ra: lr',
            'STACK CFI 2 .cfa: sp 24 + .ra: .cfa - 4 + ^ r4: .cfa - 16 + ^ '
            'r5: .cfa - 12 + ^ r7: .cfa - 8 + ^',
            'STACK CFI INIT 15b655a 26 .cfa: sp 0 + .ra: lr',
            'STACK CFI 15b655c .cfa: sp 8 + .ra: .cfa - 4 + ^ r4: .cfa - 8 + ^',
        ]

        f = io.StringIO(''.join(line + '\n' for line in input_lines))

        self.assertEqual([
            FunctionCfi(0x4, (
                AddressCfi(0x15b6490, '.cfa: sp 0 + .ra: lr'),
                AddressCfi(
                    0x2, '.cfa: sp 24 + .ra: .cfa - 4 + ^ r4: .cfa - 16 + ^ '
                    'r5: .cfa - 12 + ^ r7: .cfa - 8 + ^'),
            )),
            FunctionCfi(0x26, (
                AddressCfi(0x15b655a, '.cfa: sp 0 + .ra: lr'),
                AddressCfi(0x15b655c,
                           '.cfa: sp 8 + .ra: .cfa - 4 + ^ r4: .cfa - 8 + ^'),
            )),
        ], list(ReadFunctionCfi(f)))