def post_mortem(self, traceback=None): # See https://github.com/python/cpython/blob/ # 022bc7572f061e1d1132a4db9d085b29707701e7/Lib/pdb.py#L1617 try: t = sys.exc_info()[2] self.reset() Pdb.interaction(self, None, t) except IOError as exc: if exc.errno != errno.ECONNRESET: raise
def interaction(self, frame, traceback): self.shell.set_completer_frame(frame) while True: try: OldPdb.interaction(self, frame, traceback) break except KeyboardInterrupt: self.shell.write('\n' + self.shell.get_exception_only()) break finally: # Pdb sets readline delimiters, so set them back to our own if self.shell.readline is not None: self.shell.readline.set_completer_delims(self.shell.readline_delims)
def pdb_main(): """This pdb_main is modified from pdb.main(). """ from pdb import Pdb, Restart, traceback mainpyfile = sys.argv[0] # Get script filename if not os.path.exists(mainpyfile): print 'Error:', mainpyfile, 'does not exist' sys.exit(1) # Replace pdb's dir with script's dir in front of module search path. sys.path[0] = os.path.dirname(mainpyfile) # Note on saving/restoring sys.argv: it's a good idea when sys.argv was # modified by the script being debugged. It's a bad idea when it was # changed by the user from the command line. There is a "restart" command # which allows explicit specification of command line arguments. pdb = Pdb(stdin=sys.__stdin__, stdout=sys.__stdout__) while True: try: pdb._runscript(mainpyfile) if pdb._user_requested_quit: break print "The program finished and will be restarted" except Restart: print "Restarting", mainpyfile, "with arguments:" print "\t" + " ".join(sys.argv[1:]) 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] pdb.interaction(None, t) print "Post mortem debugger finished. The " + mainpyfile + \ " will be restarted"
def interaction(self, frame, traceback): try: OldPdb.interaction(self, frame, traceback) except KeyboardInterrupt: sys.stdout.write('\n' + self.shell.get_exception_only())
def interaction(self, *args, **kwargs): print >>self.stdout, self._prompt_msg Pdb.interaction(self, *args, **kwargs)
def interaction(self, *args, **kwargs): print(self._prompt_msg, stream=self.stdout) Pdb.interaction(self, *args, **kwargs)
def interaction(self, *args, **kwargs): if sys.version_info.major == 3: print(self._prompt_msg, stream=self.stdout) else: print >> self.stdout, self._prompt_msg Pdb.interaction(self, *args, **kwargs)