From 4a4586a59ad7235a8ccb8dd0a1bc614a23669649 Mon Sep 17 00:00:00 2001 From: eliben Date: Sun, 6 Nov 2011 15:49:37 +0200 Subject: [PATCH] added description for location_expr kinda works vs. readelf! --- elftools/dwarf/descriptions.py | 5 ++++- elftools/dwarf/location_expr.py | 4 +++- tests/test_dwarf_location_expr.py | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/elftools/dwarf/descriptions.py b/elftools/dwarf/descriptions.py index 9cef354..950ff43 100644 --- a/elftools/dwarf/descriptions.py +++ b/elftools/dwarf/descriptions.py @@ -9,6 +9,7 @@ from collections import defaultdict from .constants import * +from .location_expr import LocationExpressionDumper def describe_attr_value(attr, die, section_offset): @@ -218,7 +219,9 @@ def _location_list_extra(attr, die, section_offset): if attr.form in ('DW_FORM_data4', 'DW_FORM_data8'): return '(location list)' else: - return '<> %s %s' % (attr.value, type(attr.value)) + location_expr_dumper = LocationExpressionDumper(die.cu.structs) + location_expr_dumper.process_expr(attr.value) + return '(' + location_expr_dumper.get_str() + ')' _EXTRA_INFO_DESCRIPTION_MAP = defaultdict( diff --git a/elftools/dwarf/location_expr.py b/elftools/dwarf/location_expr.py index 0040559..09445d7 100644 --- a/elftools/dwarf/location_expr.py +++ b/elftools/dwarf/location_expr.py @@ -223,6 +223,8 @@ class GenericLocationExprVisitor(object): add('DW_OP_breg%s' % n, self._make_visitor_arg_struct(self.structs.Dwarf_sleb128(''))) + add('DW_OP_fbreg', + self._make_visitor_arg_struct(self.structs.Dwarf_sleb128(''))) add('DW_OP_regx', self._make_visitor_arg_struct(self.structs.Dwarf_uleb128(''))) add('DW_OP_bregx', @@ -262,7 +264,7 @@ class LocationExpressionDumper(GenericLocationExprVisitor): 'DW_OP_const4u', 'DW_OP_const4s', 'DW_OP_constu', 'DW_OP_consts', 'DW_OP_pick', 'DW_OP_plus_uconst', 'DW_OP_bra', 'DW_OP_skip', 'DW_OP_fbreg', 'DW_OP_piece', 'DW_OP_deref_size', - 'DW_OP_xderef_size', 'DW_OP_regx', 'DW_OP_fbreg', ]) + 'DW_OP_xderef_size', 'DW_OP_regx',]) for n in range(0, 32): self._ops_with_decimal_arg.add('DW_OP_breg%s' % n) diff --git a/tests/test_dwarf_location_expr.py b/tests/test_dwarf_location_expr.py index b6c2198..d0d6ab0 100644 --- a/tests/test_dwarf_location_expr.py +++ b/tests/test_dwarf_location_expr.py @@ -24,6 +24,11 @@ class TestLocationExpressionDumper(unittest.TestCase): self.visitor.process_expr([0x74, 0x82, 0x01]) self.assertEqual(self.visitor.get_str(), 'DW_OP_breg4: 130') + + self.setUp() + self.visitor.process_expr([0x91, 0x82, 0x01]) + self.assertEqual(self.visitor.get_str(), + 'DW_OP_fbreg: 130') self.setUp() self.visitor.process_expr([0x9d, 0x8f, 0x0A, 0x90, 0x01]) -- 2.30.2