From bd7cbef0c0331cfa48441538bb229b9d5ec85a1a Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Sun, 12 May 2024 21:53:15 +0200 Subject: [PATCH] Add option to show/hide debug info Signed-off-by: Juraj Oravec --- main.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index a53679f..46c7dfb 100644 --- a/main.py +++ b/main.py @@ -8,16 +8,23 @@ from dwex import formats from elftools.dwarf.locationlists import LocationParser, LocationExpr from elftools.dwarf.dwarf_expr import DWARFExprParser, DWARFExprOp, DW_OP_opcode2name from dwex.dwarfone import DWARFExprParserV1 +from pprint import pprint SCRIPT_VERSION = '0.1.0' configuration = { 'include_file_name': False, + 'print_debug_info': False, } def eprint(*args, **kwargs): - print(*args, file=sys.stderr, **kwargs) + if configuration['print_debug_info']: + print(*args, file=sys.stderr, **kwargs) + +def epprint(*args, **kwargs): + if configuration['print_debug_info']: + pprint(*args, stream=sys.stderr, **kwargs) class DWARFParseError(Exception): @@ -171,6 +178,10 @@ class Bear(): for child_die in die_type._children: if 'DW_AT_type' in child_die.attributes: typ_die = child_die.get_DIE_from_attribute('DW_AT_type') + else: + eprint('Child DIE with no type information') + epprint(child_die) + continue child_entry = dict() child_entry['name'] = safe_DIE_name(child_die, '?') @@ -201,6 +212,10 @@ class Bear(): for child_die in die_type._children: if 'DW_AT_type' in child_die.attributes: typ_die = child_die.get_DIE_from_attribute('DW_AT_type') + else: + eprint('Child DIE with no type information') + epprint(child_die) + continue child_entry = dict() child_entry['name'] = safe_DIE_name(child_die, '?') @@ -310,12 +325,15 @@ def main(): help='ELF file to try to extract symbols') parser.add_argument('--include-file-name', dest='include_file_name', action='store_true', help='Display filename at the beginning') + parser.add_argument('--print-debug-info', dest='print_debug_info', action='store_true', + help='Print debug infor when parsing DWARF') parser.add_argument('--version', action='version', version='%(prog)s {version}'.format(version=SCRIPT_VERSION)) args = parser.parse_args() configuration['include_file_name'] = args.include_file_name + configuration['print_debug_info'] = args.print_debug_info if not args.elf_file: parser.print_help()