Add option to parse only members of STRUCT, UNION

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2024-05-29 22:33:11 +02:00
parent e0b5edca57
commit 54c3267e04
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B

10
main.py
View File

@ -15,6 +15,7 @@ SCRIPT_VERSION = '0.1.0'
configuration = { configuration = {
'include_file_name': False, 'include_file_name': False,
'print_debug_info': False, 'print_debug_info': False,
'all_members': False,
} }
supported_types = [ supported_types = [
@ -194,6 +195,9 @@ class Bear():
child_offset = 0 child_offset = 0
child_offset_bit = 0 child_offset_bit = 0
for child_die in die_type._children: for child_die in die_type._children:
if child_die.tag != 'DW_TAG_member' and not configuration['all_members']:
continue
if 'DW_AT_type' in child_die.attributes: if 'DW_AT_type' in child_die.attributes:
typ_die = child_die.get_DIE_from_attribute('DW_AT_type') typ_die = child_die.get_DIE_from_attribute('DW_AT_type')
elif child_die.tag in supported_types: elif child_die.tag in supported_types:
@ -230,6 +234,9 @@ class Bear():
load_children(die_type) load_children(die_type)
child_entries = [] child_entries = []
for child_die in die_type._children: for child_die in die_type._children:
if child_die.tag != 'DW_TAG_member' and not configuration['all_members']:
continue
if 'DW_AT_type' in child_die.attributes: if 'DW_AT_type' in child_die.attributes:
typ_die = child_die.get_DIE_from_attribute('DW_AT_type') typ_die = child_die.get_DIE_from_attribute('DW_AT_type')
elif child_die.tag in supported_types: elif child_die.tag in supported_types:
@ -351,6 +358,8 @@ def main():
help='Display filename at the beginning') help='Display filename at the beginning')
parser.add_argument('--print-debug-info', dest='print_debug_info', action='store_true', parser.add_argument('--print-debug-info', dest='print_debug_info', action='store_true',
help='Print debug infor when parsing DWARF') help='Print debug infor when parsing DWARF')
parser.add_argument('--all-members', dest='all_members', action='store_true',
help='Print information of all children')
parser.add_argument('--version', action='version', parser.add_argument('--version', action='version',
version='%(prog)s {version}'.format(version=SCRIPT_VERSION)) version='%(prog)s {version}'.format(version=SCRIPT_VERSION))
@ -358,6 +367,7 @@ def main():
configuration['include_file_name'] = args.include_file_name configuration['include_file_name'] = args.include_file_name
configuration['print_debug_info'] = args.print_debug_info configuration['print_debug_info'] = args.print_debug_info
configuration['all_members'] = args.all_members
if not args.elf_file: if not args.elf_file:
parser.print_help() parser.print_help()