From: Eli Bendersky Date: Thu, 15 Dec 2011 07:04:42 +0000 (+0200) Subject: some unit tests for describe_CFI_instructions X-Git-Tag: v0.10~37 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=55a04b98c222a42baa4ed6800231c59407441b16;p=pyelftools.git some unit tests for describe_CFI_instructions --- diff --git a/elftools/dwarf/callframe.py b/elftools/dwarf/callframe.py index 09f80d4..3f6b735 100644 --- a/elftools/dwarf/callframe.py +++ b/elftools/dwarf/callframe.py @@ -212,7 +212,7 @@ class CallFrameInfo(object): args = [struct_parse( structs.Dwarf_dw_form['DW_FORM_block'], self.stream)] elif opcode in (DW_CFA_expression, DW_CFA_val_expression): - arsg = [ + args = [ struct_parse(structs.Dwarf_uleb128(''), self.stream), struct_parse( structs.Dwarf_dw_form['DW_FORM_block'], self.stream)] diff --git a/elftools/dwarf/descriptions.py b/elftools/dwarf/descriptions.py index 91037d3..0a45065 100644 --- a/elftools/dwarf/descriptions.py +++ b/elftools/dwarf/descriptions.py @@ -94,13 +94,13 @@ def describe_CFI_instructions(entry): s += ' %s: %s\n' % (name, instr.args[0]) elif name == 'DW_CFA_def_cfa_expression': expr_dumper = ExprDumper(entry.structs) - expr_str = dumper.process_expr(instr.args[0]) - s += ' %s: (%s)\n' % (name, expr_str) + expr_dumper.process_expr(instr.args[0]) + s += ' %s: (%s)\n' % (name, expr_dumper.get_str()) elif name == 'DW_CFA_expression': expr_dumper = ExprDumper(entry.structs) - expr_str = dumper.process_expr(instr.args[1]) + expr_dumper.process_expr(instr.args[1]) s += ' %s: %s (%s)\n' % ( - name, _full_reg_name(instr.args[0]), expr_str) + name, _full_reg_name(instr.args[0]), expr_dumper.get_str()) else: s += ' %s: \n' % name diff --git a/tests/test_callframe.py b/tests/test_callframe.py index 839b118..5f7b00c 100644 --- a/tests/test_callframe.py +++ b/tests/test_callframe.py @@ -5,6 +5,8 @@ sys.path.extend(['.', '..']) from elftools.dwarf.callframe import ( CallFrameInfo, CIE, FDE, instruction_name, CallFrameInstruction) from elftools.dwarf.structs import DWARFStructs +from elftools.dwarf.descriptions import (describe_CFI_instructions, + set_global_machine_arch) class TestCallFrame(unittest.TestCase): @@ -12,7 +14,7 @@ class TestCallFrame(unittest.TestCase): self.assertIsInstance(instr, CallFrameInstruction) self.assertEqual(instruction_name(instr.opcode), name) self.assertEqual(instr.args, args) - + def test_spec_sample_d6(self): # D.6 sample in DWARFv3 s = StringIO() @@ -88,6 +90,27 @@ class TestCallFrame(unittest.TestCase): self.assertInstruction(entries[1].instructions[20], 'DW_CFA_nop', []) + def test_describe_CFI_instructions(self): + # The data here represents a single CIE + data = ('' + + '\x16\x00\x00\x00' + # length + '\xff\xff\xff\xff' + # CIE_id + '\x03\x00\x04\x7c' + # version, augmentation, caf, daf + '\x08' + # return address + '\x0c\x07\x02' + + '\x10\x02\x07\x03\x01\x02\x00\x00\x06\x06') + s = StringIO(data) + + structs = DWARFStructs(little_endian=True, dwarf_format=32, address_size=4) + cfi = CallFrameInfo(s, len(data), structs) + entries = cfi.get_entries() + + set_global_machine_arch('x86') + self.assertEqual(describe_CFI_instructions(entries[0]), + ( ' DW_CFA_def_cfa: r7 (edi) ofs 2\n' + + ' DW_CFA_expression: r2 (edx) (DW_OP_addr: 201; DW_OP_deref; DW_OP_deref)\n')) + + if __name__ == '__main__': unittest.main()