branch : pmacs2
This commit is contained in:
moculus 2009-03-21 19:41:14 +00:00
parent 18686df3d2
commit aed3461c37
1 changed files with 0 additions and 88 deletions

88
edb.py
View File

@ -1,88 +0,0 @@
#! /usr/bin/env python
"""Another Python debugger."""
import os, pdb, sys, time, traceback
__all__ = ["run", "pm", "Pdb", "runeval", "runctx", "runcall", "set_trace",
"post_mortem", "help"]
class Edb(pdb.Pdb):
def cmdloop(self, intro=None):
stop = False
while not stop:
sys.stdout.write(self.prompt)
sys.stdout.flush()
line = sys.stdin.readline()
line = self.precmd(line)
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
self.postloop()
def columnize(self, list, displaywidth=80):
pass
def do_help(self, arg):
pass
def print_topics(self, header, cmds, cmdlen, maxcol):
pass
# Simplified interface
def run(statement, globals=None, locals=None):
Edb().run(statement, globals, locals)
def runeval(expression, globals=None, locals=None):
return Edb().runeval(expression, globals, locals)
def runctx(statement, globals, locals):
run(statement, globals, locals)
def runcall(*args, **kwds):
return Edb().runcall(*args, **kwds)
def set_trace():
Edb().set_trace(sys._getframe().f_back)
# Post-Mortem interface
def post_mortem(t):
p = Edb()
p.reset()
while t.tb_next is not None:
t = t.tb_next
p.interaction(t.tb_frame, t)
def pm():
post_mortem(sys.last_traceback)
def main():
if not sys.argv[1:]:
print "usage: edb.py scriptfile [arg] ..."
sys.exit(2)
mainpyfile = sys.argv[1]
if not os.path.exists(mainpyfile):
print 'Error:', mainpyfile, 'does not exist'
sys.exit(1)
del sys.argv[0]
# Replace pdb's dir with script's dir in front of module search path.
sys.path[0] = os.path.dirname(mainpyfile)
edb = Edb()
while 1:
try:
edb._runscript(mainpyfile)
if edb._user_requested_quit:
break
print "The program finished and will be restarted"
except SystemExit:
# In most cases SystemExit does not warrant a post-mortem session.
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"
print "Running 'cont' or 'step' will restart the program"
t = sys.exc_info()[2]
while t.tb_next is not None:
t = t.tb_next
edb.interaction(t.tb_frame,t)
print "Post mortem debugger finished. The "+mainpyfile+" will be restarted"
if __name__=='__main__':
main()