diff options
author | Nathan Binkert <nate@binkert.org> | 2008-10-09 04:58:23 -0700 |
---|---|---|
committer | Nathan Binkert <nate@binkert.org> | 2008-10-09 04:58:23 -0700 |
commit | 68c75c589b2e006292f623bd6428754d7d590f01 (patch) | |
tree | ad9af6c1660326fc9f435190387b4893284aa05a /src/python/m5 | |
parent | 886c5f8fe5011bf9a610d2bc3cb3bb010c592510 (diff) | |
download | gem5-68c75c589b2e006292f623bd6428754d7d590f01.tar.xz |
pdb: Try to make pdb work better.
I've done a few things here. First, I invoke the script a little bit
differently so that pdb doesn't get confused. Second, I've stored the
actual filename in the module's __file__ so that pdb can find the
source file on your machine.
Diffstat (limited to 'src/python/m5')
-rw-r--r-- | src/python/m5/main.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/python/m5/main.py b/src/python/m5/main.py index 66a422efa..1f9a21899 100644 --- a/src/python/m5/main.py +++ b/src/python/m5/main.py @@ -338,7 +338,10 @@ def main(): sys.argv = arguments sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path - scope = { '__file__' : sys.argv[0], + filename = sys.argv[0] + filedata = file(filename, 'r').read() + filecode = compile(filedata, filename, 'exec') + scope = { '__file__' : filename, '__name__' : '__m5_main__' } # we want readline if we're doing anything interactive @@ -348,11 +351,24 @@ def main(): # if pdb was requested, execfile the thing under pdb, otherwise, # just do the execfile normally if options.pdb: - from pdb import Pdb - debugger = Pdb() - debugger.run('execfile("%s")' % sys.argv[0], scope) + import pdb + import traceback + + pdb = pdb.Pdb() + try: + pdb.run(filecode, scope) + except SystemExit: + print "The program exited via sys.exit(). Exit status: ", + print sys.exc_info()[1] + except: + traceback.print_exc() + print "Uncaught exception. Entering post mortem debugging" + t = sys.exc_info()[2] + while t.tb_next is not None: + t = t.tb_next + pdb.interaction(t.tb_frame,t) else: - execfile(sys.argv[0], scope) + exec filecode in scope # once the script is done if options.interactive: |