From b688d001ee77e7c8ca536ced974ef713424c11e2 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 6 Mar 2018 14:16:41 +0100 Subject: [PATCH] Fix DW_CFA_remember_state (#184) * Fix #103 * Fix description for DW_CFA_def_cfa_expression * Add test file for issue #103 --- elftools/dwarf/callframe.py | 4 +++- elftools/dwarf/descriptions.py | 3 ++- test/testfiles_for_readelf/issue103.elf | Bin 0 -> 7376 bytes 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 test/testfiles_for_readelf/issue103.elf diff --git a/elftools/dwarf/callframe.py b/elftools/dwarf/callframe.py index e64c745..bcef78d 100644 --- a/elftools/dwarf/callframe.py +++ b/elftools/dwarf/callframe.py @@ -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. diff --git a/elftools/dwarf/descriptions.py b/elftools/dwarf/descriptions.py index 3a07607..eb20333 100644 --- a/elftools/dwarf/descriptions.py +++ b/elftools/dwarf/descriptions.py @@ -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 index 0000000000000000000000000000000000000000..8c37a7cc32ba5ca23b90584a3240579309fa54c5 GIT binary patch literal 7376 zcmcgxeQZb7cP>(FSS8&x~THkIsm?mNdH zFRo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