From 0ef702383ac9879a93e54b3e539238524233fe76 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Thu, 30 May 2024 07:28:47 +0200 Subject: [PATCH] Rework location of structure members Signed-off-by: Juraj Oravec --- main.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index 7499100..4bf7a7d 100644 --- a/main.py +++ b/main.py @@ -167,10 +167,13 @@ class Bear(): entry['type'] = safe_DIE_name(die_type, '?') - if 'DW_AT_data_member_location' in die_type.attributes: - entry['offset'] = die_type.attributes['DW_AT_data_member_location'].value * 8 - if 'address' in entry: - entry['address'] = hex(int(entry['address'], 16) + die_type.attributes['DW_AT_data_member_location'].value) + if ('DW_AT_member_location' in die_type.attributes) or ('DW_AT_data_member_location' in die_type.attributes): + at_member_location_name = 'DW_AT_member_location' if 'DW_AT_member_location' in die_type.attributes else 'DW_AT_data_member_location' + + if LocationParser.attribute_has_location(die_type.attributes[at_member_location_name], die_type.cu['version']): + ll = self.parse_location(die_type, die_type.attributes[at_member_location_name]) + lloc = self.dump_expr(die_type, ll.loc_expr) + entry['address'] = hex(int(entry['address'], 16) + lloc[0].args[0]) if 'DW_AT_type' in die_type.attributes and die_type.tag not in ['DW_TAG_base_type', 'DW_TAG_structure_type', 'DW_TAG_array_type']: # Check if the type is a redefinition of a base type @@ -210,20 +213,19 @@ class Bear(): child_entry = dict() child_entry['name'] = safe_DIE_name(child_die, '?') - if 'DW_AT_data_bit_offset' in child_die.attributes: - child_offset_bit = child_die.attributes['DW_AT_data_bit_offset'].value - if child_offset_bit >= 8: - child_offset = child_offset + math.floor(child_offset_bit / 8) - child_offset_bit = child_offset_bit - math.floor(child_offset_bit / 8) * 8 - if 'address' in entry: - child_entry['address'] = hex(int(entry['address'], 16) + child_offset) + if ('DW_AT_member_location' in child_die.attributes) or ('DW_AT_data_member_location' in child_die.attributes): + at_member_location_name = 'DW_AT_member_location' if 'DW_AT_member_location' in child_die.attributes else 'DW_AT_data_member_location' + + if LocationParser.attribute_has_location(child_die.attributes[at_member_location_name], child_die.cu['version']): + ll = self.parse_location(child_die, child_die.attributes[at_member_location_name]) + lloc = self.dump_expr(child_die, ll.loc_expr) + child_entry['address'] = hex(int(entry['address'], 16) + lloc[0].args[0]) + else: + child_entry['address'] = entry['address'] self.truly_resolve_type(child_entry, typ_die) - if ('size_byte' in child_entry) and ('DW_AT_data_bit_offset' not in child_die.attributes) and ('DW_AT_bit_offset' not in child_die.attributes): - child_offset = child_offset + child_entry['size_byte'] - child_dies.append(child_entry) entry['children'] = child_dies elif die_type.tag == 'DW_TAG_array_type':