Fix DW_CFA_remember_state (#184)
authoremersion <contact@emersion.fr>
Tue, 6 Mar 2018 13:16:41 +0000 (14:16 +0100)
committerEli Bendersky <eliben@users.noreply.github.com>
Tue, 6 Mar 2018 13:16:41 +0000 (05:16 -0800)
* Fix #103

* Fix description for DW_CFA_def_cfa_expression

* Add test file for issue #103

elftools/dwarf/callframe.py
elftools/dwarf/descriptions.py
test/testfiles_for_readelf/issue103.elf [new file with mode: 0644]

index e64c745cae6ff09ed50a149d955d723980d0968b..bcef78d79a2b901d6e753876501e817ea8c9689b 100644 (file)
@@ -567,9 +567,11 @@ class CFIEntry(object):
                 else:
                     cur_line.pop(instr.args[0], None)
             elif name == 'DW_CFA_remember_state':
-                line_stack.append(cur_line)
+                line_stack.append(copy.deepcopy(cur_line))
             elif name == 'DW_CFA_restore_state':
+                pc = cur_line['pc']
                 cur_line = line_stack.pop()
+                cur_line['pc'] = pc
 
         # The current line is appended to the table after all instructions
         # have ended, if there were instructions.
index 3a0760783ab5e8ea337d91b33f4c7cb51caad984..eb20333f0a2e1dc92f735853a3bdb2215bd680d8 100644 (file)
@@ -104,7 +104,8 @@ def describe_CFI_instructions(entry):
         elif name == 'DW_CFA_def_cfa_expression':
             expr_dumper = ExprDumper(entry.structs)
             expr_dumper.process_expr(instr.args[0])
-            s += '  %s: (%s)\n' % (name, expr_dumper.get_str())
+            # readelf output is missing a colon for DW_CFA_def_cfa_expression
+            s += '  %s (%s)\n' % (name, expr_dumper.get_str())
         elif name == 'DW_CFA_expression':
             expr_dumper = ExprDumper(entry.structs)
             expr_dumper.process_expr(instr.args[1])
diff --git a/test/testfiles_for_readelf/issue103.elf b/test/testfiles_for_readelf/issue103.elf
new file mode 100644 (file)
index 0000000..8c37a7c
Binary files /dev/null and b/test/testfiles_for_readelf/issue103.elf differ