elf_mem_map: decode arrays (first dimension)

This commit is contained in:
Yuri D'Elia 2021-06-02 18:30:25 +02:00 committed by DRracer
parent 1de3fa51c9
commit 29b8c89ec2

View File

@ -54,17 +54,33 @@ def get_elf_globals(path):
# recurse on type to find the final storage definition
type_DIE = DIE
byte_size = None
array_len = None
while True:
if 'DW_AT_byte_size' in type_DIE.attributes:
byte_size = type_DIE.attributes.get('DW_AT_byte_size')
if 'DW_AT_type' not in type_DIE.attributes:
break
type_DIE = type_DIE.get_DIE_from_attribute('DW_AT_type')
if type_DIE.tag == 'DW_TAG_array_type':
# fetch the first dimension (if known)
range_DIE = next(type_DIE.iter_children())
if range_DIE.tag == 'DW_TAG_subrange_type' and \
'DW_AT_upper_bound' in range_DIE.attributes:
array_len = range_DIE.attributes['DW_AT_upper_bound'].value + 1
if byte_size is None:
continue
size = byte_size.value
grefs.append(Entry(name, loc, size))
if array_len is None or array_len == 1:
# plain entry
grefs.append(Entry(name, loc, size))
elif size == 1:
# string
grefs.append(Entry('{}[]'.format(name), loc, array_len))
else:
# expand array entries
for i in range(array_len):
grefs.append(Entry('{}[{}]'.format(name, i), loc+size*i, size))
return grefs