Add option to not expand array elements

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2024-08-26 01:08:56 +02:00
parent bd7272f365
commit 557ed8c84b
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B

12
main.py
View File

@ -15,6 +15,7 @@ configuration = {
'include_file_name': False,
'print_debug_info': False,
'all_members': False,
'no_array_expand': False,
}
supported_types = [
@ -295,12 +296,16 @@ class Bear():
self.flat_list.append(flat_entry)
if 'children' in entry:
if 'children' in entry and 'number_of_elements' not in entry:
for kid in entry['children']:
self.pettanko(kid, flat_entry['name'])
if 'number_of_elements' in entry:
for index in range(0, entry['number_of_elements']):
step = 1
if configuration['no_array_expand']:
step = entry['number_of_elements'] - 1
for index in range(0, entry['number_of_elements'], step):
kid = flat_entry.copy()
kid['name'] = '{name}[{index}]'.format(name=flat_entry['name'], index=index)
@ -366,6 +371,8 @@ def main():
help='Print debug infor when parsing DWARF')
parser.add_argument('-a', '--all-members', dest='all_members', action='store_true',
help='Print information of all children')
parser.add_argument('-e', '--no-array-expand', dest='no_array_expand', action='store_true',
help='Print only first and last array elements')
parser.add_argument('--version', action='version',
version='%(prog)s {version}'.format(version=SCRIPT_VERSION))
@ -374,6 +381,7 @@ def main():
configuration['include_file_name'] = args.include_file_name
configuration['print_debug_info'] = args.print_debug_info
configuration['all_members'] = args.all_members
configuration['no_array_expand'] = args.no_array_expand
if not args.elf_file:
parser.print_help()