changeset 7c58fc1ec5dc in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=7c58fc1ec5dc
description:
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:
2 files changed, 1 insertion(+), 3 deletions(-)
src/SConscript | 2 --
src/python/m5/main.py | 2 +-
diffs (99 lines):
diff -r f0a0c8f23c06 -r 7c58fc1ec5dc src/SConscript
--- a/src/SConscript Thu Oct 09 04:58:23 2008 -0700
+++ b/src/SConscript Thu Oct 09 04:58:23 2008 -0700
@@ -61,8 +61,9 @@
class PySourceFile(object):
invalid_sym_char = re.compile('[^A-z0-9_]')
- def __init__(self, package, source):
- filename = str(source)
+ def __init__(self, package, tnode):
+ snode = tnode.srcnode()
+ filename = str(tnode)
pyname = basename(filename)
assert pyname.endswith('.py')
name = pyname[:-3]
@@ -70,7 +71,8 @@
path = package.split('.')
else:
path = []
- modpath = path
+
+ modpath = path[:]
if name != '__init__':
modpath += [name]
modpath = '.'.join(modpath)
@@ -78,13 +80,17 @@
arcpath = path + [ pyname ]
arcname = joinpath(*arcpath)
- self.tnode = source
- self.snode = source.srcnode()
+ debugname = snode.abspath
+ if not exists(debugname):
+ debugname = tnode.abspath
+
+ self.tnode = tnode
+ self.snode = snode
self.pyname = pyname
self.package = package
self.modpath = modpath
self.arcname = arcname
- self.filename = filename
+ self.debugname = debugname
self.compiled = File(filename + 'c')
self.assembly = File(filename + '.s')
self.symname = "PyEMB_" + self.invalid_sym_char.sub('_', modpath)
@@ -849,7 +855,7 @@
dst = file(str(target[0]), 'w')
pysource = py_sources_tnodes[source[0]]
- compiled = compile(src, pysource.snode.path, 'exec')
+ compiled = compile(src, pysource.debugname, 'exec')
marshalled = marshal.dumps(compiled)
compressed = zlib.compress(marshalled)
data = compressed
diff -r f0a0c8f23c06 -r 7c58fc1ec5dc src/python/m5/main.py
--- a/src/python/m5/main.py Thu Oct 09 04:58:23 2008 -0700
+++ b/src/python/m5/main.py Thu Oct 09 04:58:23 2008 -0700
@@ -338,7 +338,10 @@
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 @@
# 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:
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev