@@ -523,6 +523,33 @@ def do_jump(self, arg):
523523 print '*** Jump failed:' , e
524524 do_j = do_jump
525525
526+ def do_debug (self , arg ):
527+ sys .settrace (None )
528+ globals = self .curframe .f_globals
529+ locals = self .curframe .f_locals
530+ p = Pdb ()
531+ p .prompt = "(%s) " % self .prompt .strip ()
532+ print "ENTERING RECURSIVE DEBUGGER"
533+ sys .call_tracing (p .run , (arg , globals , locals ))
534+ print "LEAVING RECURSIVE DEBUGGER"
535+ sys .settrace (self .trace_dispatch )
536+ self .lastcmd = p .lastcmd
537+
538+ def dont_debug (self , arg ):
539+ locals = self .curframe .f_locals
540+ globals = self .curframe .f_globals
541+ try :
542+ r = sys .call_tracing (eval , (arg , globals , locals ))
543+ print "--- DEBUG RETURNED ---"
544+ if r is not None :
545+ print repr (r )
546+ except :
547+ t , v = sys .exc_info ()[:2 ]
548+ if type (t ) == type ('' ):
549+ exc_type_name = t
550+ else : exc_type_name = t .__name__
551+ print '***' , exc_type_name + ':' , v
552+
526553 def do_quit (self , arg ):
527554 self .set_quit ()
528555 return 1
@@ -834,6 +861,12 @@ def help_j(self):
834861 print """j(ump) lineno
835862Set the next line that will be executed."""
836863
864+ def help_debug (self ):
865+ print """debug code
866+ Enter a recursive debugger that steps through the code argument
867+ (which is an arbitrary expression or statement to be executed
868+ in the current environment)."""
869+
837870 def help_list (self ):
838871 self .help_l ()
839872
0 commit comments