From 29b8c89ec2a7df5cf9dfcef693702890fe1c65e0 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 2 Jun 2021 18:30:25 +0200 Subject: [PATCH] elf_mem_map: decode arrays (first dimension) --- tools/elf_mem_map | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/elf_mem_map b/tools/elf_mem_map index 32f178dc..e518083d 100755 --- a/tools/elf_mem_map +++ b/tools/elf_mem_map @@ -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