elf_mem_map: decode arrays (first dimension)
This commit is contained in:
parent
1de3fa51c9
commit
29b8c89ec2
@ -54,17 +54,33 @@ def get_elf_globals(path):
|
|||||||
# recurse on type to find the final storage definition
|
# recurse on type to find the final storage definition
|
||||||
type_DIE = DIE
|
type_DIE = DIE
|
||||||
byte_size = None
|
byte_size = None
|
||||||
|
array_len = None
|
||||||
while True:
|
while True:
|
||||||
if 'DW_AT_byte_size' in type_DIE.attributes:
|
if 'DW_AT_byte_size' in type_DIE.attributes:
|
||||||
byte_size = type_DIE.attributes.get('DW_AT_byte_size')
|
byte_size = type_DIE.attributes.get('DW_AT_byte_size')
|
||||||
if 'DW_AT_type' not in type_DIE.attributes:
|
if 'DW_AT_type' not in type_DIE.attributes:
|
||||||
break
|
break
|
||||||
type_DIE = type_DIE.get_DIE_from_attribute('DW_AT_type')
|
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:
|
if byte_size is None:
|
||||||
continue
|
continue
|
||||||
size = byte_size.value
|
size = byte_size.value
|
||||||
|
|
||||||
|
if array_len is None or array_len == 1:
|
||||||
|
# plain entry
|
||||||
grefs.append(Entry(name, loc, size))
|
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
|
return grefs
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user