handle class exceptions; added runeval; made runctx obsolete
This commit is contained in:
parent
051ab123b4
commit
5e38b6fda1
39
Lib/bdb.py
39
Lib/bdb.py
|
@ -270,36 +270,59 @@ class Bdb: # Basic Debugger
|
|||
# The following two methods can be called by clients to use
|
||||
# a debugger to debug a statement, given as a string.
|
||||
|
||||
def run(self, cmd):
|
||||
import __main__
|
||||
dict = __main__.__dict__
|
||||
self.runctx(cmd, dict, dict)
|
||||
|
||||
def runctx(self, cmd, globals, locals):
|
||||
def run(self, cmd, globals=None, locals=None):
|
||||
if globals is None:
|
||||
import __main__
|
||||
globals = __main__.__dict__
|
||||
if locals is None:
|
||||
locals = globals
|
||||
self.reset()
|
||||
sys.settrace(self.trace_dispatch)
|
||||
try:
|
||||
try:
|
||||
exec(cmd + '\n', globals, locals)
|
||||
exec cmd + '\n' in globals, locals
|
||||
except BdbQuit:
|
||||
pass
|
||||
finally:
|
||||
self.quitting = 1
|
||||
sys.settrace(None)
|
||||
|
||||
def runeval(self, expr, globals=None, locals=None):
|
||||
if globals is None:
|
||||
import __main__
|
||||
globals = __main__.__dict__
|
||||
if locals is None:
|
||||
locals = globals
|
||||
self.reset()
|
||||
sys.settrace(self.trace_dispatch)
|
||||
try:
|
||||
try:
|
||||
return eval(expr + '\n', globals, locals)
|
||||
except BdbQuit:
|
||||
pass
|
||||
finally:
|
||||
self.quitting = 1
|
||||
sys.settrace(None)
|
||||
|
||||
def runctx(self, cmd, globals, locals):
|
||||
# B/W compatibility
|
||||
self.run(cmd, globals, locals)
|
||||
|
||||
# This method is more useful to debug a single function call.
|
||||
|
||||
def runcall(self, func, *args):
|
||||
self.reset()
|
||||
sys.settrace(self.trace_dispatch)
|
||||
res = None
|
||||
try:
|
||||
try:
|
||||
apply(func, args)
|
||||
res = apply(func, args)
|
||||
except BdbQuit:
|
||||
pass
|
||||
finally:
|
||||
self.quitting = 1
|
||||
sys.settrace(None)
|
||||
return res
|
||||
|
||||
|
||||
def set_trace():
|
||||
|
|
|
@ -75,7 +75,10 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
|
|||
# This function is called if an exception occurs,
|
||||
# but only if we are to stop at or just below this level
|
||||
frame.f_locals['__exception__'] = exc_type, exc_value
|
||||
self.settitle(exc_type + ': ' + repr.repr(exc_value))
|
||||
if type(exc_type) == type(''):
|
||||
exc_type_name = exc_type
|
||||
else: exc_type_name = exc_type.__name__
|
||||
self.settitle(exc_type_name + ': ' + repr.repr(exc_value))
|
||||
stdwin.fleep()
|
||||
self.interaction(frame, exc_traceback)
|
||||
if not self.closed:
|
||||
|
@ -271,19 +274,23 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
|
|||
|
||||
# Simplified interface
|
||||
|
||||
def run(statement):
|
||||
def run(statement, globals=None, locals=None):
|
||||
x = Wdb()
|
||||
try: x.run(statement)
|
||||
try: x.run(statement, globals, locals)
|
||||
finally: x.close()
|
||||
|
||||
def runeval(expression, globals=None, locals=None):
|
||||
x = Wdb()
|
||||
try: return x.runeval(expression, globals, locals)
|
||||
finally: x.close()
|
||||
|
||||
def runctx(statement, globals, locals):
|
||||
x = Wdb()
|
||||
try: x.runctx(statement, globals, locals)
|
||||
finally: x.close()
|
||||
# B/W compatibility
|
||||
run(statement, globals, locals)
|
||||
|
||||
def runcall(*args):
|
||||
x = Wdb()
|
||||
try: apply(x.runcall, args)
|
||||
try: return apply(x.runcall, args)
|
||||
finally: x.close()
|
||||
|
||||
def set_trace():
|
||||
|
|
|
@ -100,7 +100,10 @@ class FrameWindow(basewin.BaseWindow):
|
|||
value = eval(expr, globals, locals)
|
||||
output = repr.repr(value)
|
||||
except:
|
||||
output = sys.exc_type + ': ' + `sys.exc_value`
|
||||
if type(sys.exc_type) == type(''):
|
||||
exc_type_name = sys.exc_type
|
||||
else: exc_type_name = sys.exc_type.__name__
|
||||
output = exc_type_name + ': ' + `sys.exc_value`
|
||||
self.displaylist[1] = output
|
||||
lh = stdwin.lineheight()
|
||||
r = (-10, 0), (30000, 2*lh)
|
||||
|
|
32
Lib/pdb.py
32
Lib/pdb.py
|
@ -55,7 +55,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
# This function is called if an exception occurs,
|
||||
# but only if we are to stop at or just below this level
|
||||
frame.f_locals['__exception__'] = exc_type, exc_value
|
||||
print exc_type + ':', repr.repr(exc_value)
|
||||
if type(exc_type) == type(''):
|
||||
exc_type_name = exc_type
|
||||
else: exc_type_name = exc_type.__name__
|
||||
print exc_type_name + ':', repr.repr(exc_value)
|
||||
self.interaction(frame, exc_traceback)
|
||||
|
||||
# General interaction function
|
||||
|
@ -74,7 +77,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
try:
|
||||
exec(line + '\n', globals, locals)
|
||||
except:
|
||||
print '***', sys.exc_type + ':', sys.exc_value
|
||||
if type(sys.exc_type) == type(''):
|
||||
exc_type_name = sys.exc_type
|
||||
else: exc_type_name = sys.exc_type.__name__
|
||||
print '***', exc_type_name + ':', sys.exc_value
|
||||
|
||||
# Command definitions, called by cmdloop()
|
||||
# The argument is the remaining string on the command line
|
||||
|
@ -199,7 +205,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
value = eval(arg, self.curframe.f_globals, \
|
||||
self.curframe.f_locals)
|
||||
except:
|
||||
print '***', sys.exc_type + ':', `sys.exc_value`
|
||||
if type(sys.exc_type) == type(''):
|
||||
exc_type_name = sys.exc_type
|
||||
else: exc_type_name = sys.exc_type.__name__
|
||||
print '***', exc_type_name + ':', `sys.exc_value`
|
||||
return
|
||||
|
||||
print `value`
|
||||
|
@ -254,7 +263,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
value = eval(arg, self.curframe.f_globals, \
|
||||
self.curframe.f_locals)
|
||||
except:
|
||||
print '***', sys.exc_type + ':', `sys.exc_value`
|
||||
if type(sys.exc_type) == type(''):
|
||||
exc_type_name = sys.exc_type
|
||||
else: exc_type_name = sys.exc_type.__name__
|
||||
print '***', exc_type_name + ':', `sys.exc_value`
|
||||
return
|
||||
code = None
|
||||
# Is it a function?
|
||||
|
@ -429,14 +441,18 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
|
||||
# Simplified interface
|
||||
|
||||
def run(statement):
|
||||
Pdb().run(statement)
|
||||
def run(statement, globals=None, locals=None):
|
||||
Pdb().run(statement, globals, locals)
|
||||
|
||||
def runeval(expression, globals=None, locals=None):
|
||||
return Pdb().runeval(expression, globals, locals)
|
||||
|
||||
def runctx(statement, globals, locals):
|
||||
Pdb().runctx(statement, globals, locals)
|
||||
# B/W compatibility
|
||||
run(statement, globals, locals)
|
||||
|
||||
def runcall(*args):
|
||||
apply(Pdb().runcall, args)
|
||||
return apply(Pdb().runcall, args)
|
||||
|
||||
def set_trace():
|
||||
Pdb().set_trace()
|
||||
|
|
|
@ -75,7 +75,10 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
|
|||
# This function is called if an exception occurs,
|
||||
# but only if we are to stop at or just below this level
|
||||
frame.f_locals['__exception__'] = exc_type, exc_value
|
||||
self.settitle(exc_type + ': ' + repr.repr(exc_value))
|
||||
if type(exc_type) == type(''):
|
||||
exc_type_name = exc_type
|
||||
else: exc_type_name = exc_type.__name__
|
||||
self.settitle(exc_type_name + ': ' + repr.repr(exc_value))
|
||||
stdwin.fleep()
|
||||
self.interaction(frame, exc_traceback)
|
||||
if not self.closed:
|
||||
|
@ -271,19 +274,23 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
|
|||
|
||||
# Simplified interface
|
||||
|
||||
def run(statement):
|
||||
def run(statement, globals=None, locals=None):
|
||||
x = Wdb()
|
||||
try: x.run(statement)
|
||||
try: x.run(statement, globals, locals)
|
||||
finally: x.close()
|
||||
|
||||
def runeval(expression, globals=None, locals=None):
|
||||
x = Wdb()
|
||||
try: return x.runeval(expression, globals, locals)
|
||||
finally: x.close()
|
||||
|
||||
def runctx(statement, globals, locals):
|
||||
x = Wdb()
|
||||
try: x.runctx(statement, globals, locals)
|
||||
finally: x.close()
|
||||
# B/W compatibility
|
||||
run(statement, globals, locals)
|
||||
|
||||
def runcall(*args):
|
||||
x = Wdb()
|
||||
try: apply(x.runcall, args)
|
||||
try: return apply(x.runcall, args)
|
||||
finally: x.close()
|
||||
|
||||
def set_trace():
|
||||
|
|
|
@ -100,7 +100,10 @@ class FrameWindow(basewin.BaseWindow):
|
|||
value = eval(expr, globals, locals)
|
||||
output = repr.repr(value)
|
||||
except:
|
||||
output = sys.exc_type + ': ' + `sys.exc_value`
|
||||
if type(sys.exc_type) == type(''):
|
||||
exc_type_name = sys.exc_type
|
||||
else: exc_type_name = sys.exc_type.__name__
|
||||
output = exc_type_name + ': ' + `sys.exc_value`
|
||||
self.displaylist[1] = output
|
||||
lh = stdwin.lineheight()
|
||||
r = (-10, 0), (30000, 2*lh)
|
||||
|
|
Loading…
Reference in New Issue