Add option to show/hide debug info
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
9bd0cf4980
commit
bd7cbef0c0
20
main.py
20
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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user