From: Pierre-Marie de Rodat Date: Tue, 10 Mar 2020 12:46:46 +0000 (+0100) Subject: readelf.py: minor enhancements for debugging (#294) X-Git-Tag: v0.27~48^2~1 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ecc5a2d7981fd1c9550f58ae2c9edf553ae08a44;p=pyelftools.git readelf.py: minor enhancements for debugging (#294) * readelf.py: add an option to show traceback on error * readelf.py: flush stdout before printing to sys.stderr This is necessary to make error messages appear after any display that was emitted before the error actually happened. --- diff --git a/scripts/readelf.py b/scripts/readelf.py index 3a075fd..2ff229a 100755 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -10,6 +10,7 @@ import argparse import os, sys import string +import traceback import itertools # Note: zip has different behaviour between Python 2.x and 3.x. # - Using izip ensures compatibility. @@ -1396,6 +1397,10 @@ def main(stream=None): help=( 'Display the contents of DWARF debug sections. can ' + 'one of {info,decodedline,frames,frames-interp}')) + argparser.add_argument('--traceback', + action='store_true', dest='show_traceback', + help='Dump the Python traceback on ELFError' + ' exceptions from elftools') args = argparser.parse_args() @@ -1440,7 +1445,10 @@ def main(stream=None): if args.debug_dump_what: readelf.display_debug_dump(args.debug_dump_what) except ELFError as ex: + sys.stdout.flush() sys.stderr.write('ELF error: %s\n' % ex) + if args.show_traceback: + traceback.print_exc() sys.exit(1)