def set_trace(addr='127.0.0.1', port=4444, no_signals=False): # Backup stdin and stdout before replacing them by the socket handle old_stdout = sys.stdout old_stdin = sys.stdin # Run telnet server and get the new fds (pid, stdout, stdin) = run_telnet_server(addr, port) sys.stdout = stdout sys.stdin = stdin # Kill children on exit. def cleanup(): print('Killing server...') os.kill(pid, signal.SIGKILL) atexit.register(cleanup) def signal_handler(signal, frame): sys.exit(0) signal.signal(signal.SIGINT, signal_handler) # Finally, run pudb if no_signals: # this allows this to work inside uwsgi pudb._get_debugger().set_trace(sys._getframe().f_back) else: pudb.set_trace()
def go(self): dbg = _get_debugger() import threading if isinstance(threading.current_thread(), threading._MainThread): set_interrupt_handler() dbg.set_trace(sys._getframe().f_back, paused=False)
def set_trace(): import sys dbg = _get_debugger() set_interrupt_handler() dbg.set_trace(sys._getframe().f_back)
def set_trace(): import sys dbg = _get_debugger() import threading if isinstance(threading.current_thread(), threading._MainThread): set_interrupt_handler() dbg.set_trace(sys._getframe().f_back)
def go(self): import sys dbg = _get_debugger() import threading if isinstance(threading.current_thread(), threading._MainThread): set_interrupt_handler() dbg.set_trace(sys._getframe().f_back, paused=False)
def db(self): capman = config.pluginmanager.getplugin("capturemanager") out, err = capman.suspendcapture() import sys import pudb dbg = pudb._get_debugger() dbg.set_trace(sys._getframe().f_back)
def post_mortem(tb=None, e_type=None, e_value=None): if tb is None: import sys exc_info = sys.exc_info() else: exc_info = (e_type, e_value, tb) dbg = _get_debugger() dbg.reset() dbg.interaction(None, exc_info)
def post_mortem(exc_info=None): if exc_info is None: import sys exc_info = sys.exc_info() tb = exc_info[2] while tb.tb_next is not None: tb = tb.tb_next dbg = _get_debugger() dbg.reset() dbg.interaction(tb.tb_frame, exc_info)
def post_mortem(tb=None, e_type=None, e_value=None): if tb is None: import sys exc_info = sys.exc_info() else: exc_info = (e_type, e_value, tb) tb = exc_info[2] while tb.tb_next is not None: tb = tb.tb_next dbg = _get_debugger() dbg.reset() dbg.interaction(tb.tb_frame, exc_info)
def set_trace(paused=True): """ Start the debugger If paused=False (the default is True), the debugger will not stop here (same as immediately pressing 'c' to continue). """ import sys dbg = _get_debugger() import threading if isinstance(threading.current_thread(), threading._MainThread): set_interrupt_handler() dbg.set_trace(sys._getframe().f_back, paused=paused)
def emit(self, record): from pudb import _have_debugger, _get_debugger logfile = getlogfile() self.acquire() try: if logfile is not None: message = self.format(record) with open(logfile, "a") as openfile: openfile.write("\n%s\n" % message) elif _have_debugger(): dbg = _get_debugger() message = self.format(record) dbg.ui.add_cmdline_content(message, "command line error") else: super().emit(record) finally: self.release()
def set_trace(paused=True, tty=None): """ Start the debugger If paused=False (the default is True), the debugger will not stop here (same as immediately pressing 'c' to continue). tty- Allow the user to control the debugger from seperate terminal given in tty """ import sys dbg = _get_debugger(tty=tty) import threading if isinstance(threading.current_thread(), threading._MainThread): set_interrupt_handler() dbg.set_trace(sys._getframe().f_back, paused=paused)
def debug(self): # disable console logging when entering interactive debugger j.core.myenv.log_console = False import sys if j.core.myenv.debugger == "pudb": import pudb import threading dbg = pudb._get_debugger() if isinstance(threading.current_thread(), threading._MainThread): pudb.set_interrupt_handler() dbg.set_trace(sys._getframe().f_back, paused=True) elif j.core.myenv.debugger == "ipdb": try: import ipdb as debugger except ImportError: import pdb debugger = pdb.Pdb() debugger.set_trace(sys._getframe().f_back)
def runscript(mainpyfile, args=None, pre_run="", steal_output=False): dbg = _get_debugger(steal_output=steal_output) # 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. The best approach would be to # have a "restart" command which would allow explicit specification of # command line arguments. import sys if args is not None: prev_sys_argv = sys.argv[:] sys.argv = [mainpyfile] + args # replace pudb's dir with script's dir in front of module search path. from os.path import dirname prev_sys_path = sys.path[:] sys.path[0] = dirname(mainpyfile) while True: if pre_run: from subprocess import call retcode = call(pre_run, close_fds=True, shell=True) if retcode: print("*** WARNING: pre-run process exited with code %d." % retcode) raw_input("[Hit Enter]") status_msg = "" try: dbg._runscript(mainpyfile) except SystemExit: se = sys.exc_info()[1] status_msg = "The debuggee exited normally with " \ "status code %s.\n\n" % se.code except: dbg.post_mortem = True dbg.interaction(None, sys.exc_info()) while True: import urwid pre_run_edit = urwid.Edit("", pre_run) result = dbg.ui.call_with_ui(dbg.ui.dialog, urwid.ListBox([urwid.Text( "Your PuDB session has ended.\n\n%s" "Would you like to quit PuDB or restart your program?\n" "You may hit 'q' to quit." % status_msg), urwid.Text("\n\nIf you decide to restart, this command " "will be run prior to actually restarting:"), urwid.AttrMap(pre_run_edit, "value") ]), [ ("Restart", "restart"), ("Examine", "examine"), ("Quit", "quit"), ], focus_buttons=True, bind_enter_esc=False, title="Finished", extra_bindings=[ ("q", "quit"), ("esc", "examine"), ]) if result == "quit": return if result == "examine": dbg.post_mortem = True dbg.interaction(None, sys.exc_info(), show_exc_dialog=False) if result == "restart": break pre_run = pre_run_edit.get_edit_text() dbg.restart() if args is not None: sys.argv = prev_sys_argv sys.path = prev_sys_path
def _interrupt_handler(signum, frame): from pudb import _get_debugger _get_debugger().set_trace(frame)
def runcall(*args, **kwds): return _get_debugger().runcall(*args, **kwds)
def runeval(expression, globals=None, locals=None): return _get_debugger().runeval(expression, globals, locals)
def post_mortem(tb, excinfo): dbg = pudb._get_debugger() stack, i = dbg.get_stack(None, tb) dbg.reset() i = _find_last_non_hidden_frame(stack) dbg.interaction(stack[i][0], excinfo._excinfo)
def db(self): import sys dbg = _get_debugger() set_interrupt_handler() dbg.set_trace(sys._getframe().f_back)
def set_trace(): dbg = _get_debugger() set_interrupt_handler() dbg.set_trace(sys._getframe().f_back.f_back)
def runstatement(statement, globals=None, locals=None): _get_debugger().run(statement, globals, locals)
def _interrupt_handler(signum, frame): from pudb import _get_debugger _get_debugger().set_trace(frame, as_breakpoint=False)
def _runscript(module, filename, pre_run, steal_output): import sys dbg = _get_debugger(steal_output=steal_output) while True: if pre_run: from subprocess import call retcode = call(pre_run, close_fds=True, shell=True) if retcode: print("*** WARNING: pre-run process exited with code %d." % retcode) raw_input("[Hit Enter]") status_msg = "" try: dbg._runscript(module, filename) except SystemExit: se = sys.exc_info()[1] status_msg = "The debuggee exited normally with " \ "status code %s.\n\n" % se.code except Exception: dbg.post_mortem = True dbg.interaction(None, sys.exc_info()) while True: import urwid pre_run_edit = urwid.Edit("", pre_run) if not CONFIG["prompt_on_quit"]: return result = dbg.ui.call_with_ui(dbg.ui.dialog, urwid.ListBox(urwid.SimpleListWalker([urwid.Text( "Your PuDB session has ended.\n\n%s" "Would you like to quit PuDB or restart your program?\n" "You may hit 'q' to quit." % status_msg), urwid.Text("\n\nIf you decide to restart, this command " "will be run prior to actually restarting:"), urwid.AttrMap(pre_run_edit, "value") ])), [ ("Restart", "restart"), ("Examine", "examine"), ("Quit", "quit"), ], focus_buttons=True, bind_enter_esc=False, title="Finished", extra_bindings=[ ("q", "quit"), ("esc", "examine"), ]) if result == "quit": return if result == "examine": dbg.post_mortem = True dbg.interaction(None, sys.exc_info(), show_exc_dialog=False) if result == "restart": break pre_run = pre_run_edit.get_edit_text() dbg.restart()
def runscript(mainpyfile, args=None, pre_run="", steal_output=False): dbg = _get_debugger(steal_output=steal_output) # 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. The best approach would be to # have a "restart" command which would allow explicit specification of # command line arguments. import sys if args is not None: prev_sys_argv = sys.argv[:] sys.argv = [mainpyfile] + args # replace pudb's dir with script's dir in front of module search path. from os.path import dirname prev_sys_path = sys.path[:] sys.path[0] = dirname(mainpyfile) while True: if pre_run: from subprocess import call retcode = call(pre_run, close_fds=True, shell=True) if retcode: print("*** WARNING: pre-run process exited with code %d." % retcode) raw_input("[Hit Enter]") status_msg = "" try: dbg._runscript(mainpyfile) except SystemExit: se = sys.exc_info()[1] status_msg = "The debuggee exited normally with " \ "status code %s.\n\n" % se.code except Exception: dbg.post_mortem = True dbg.interaction(None, sys.exc_info()) while True: import urwid pre_run_edit = urwid.Edit("", pre_run) if not CONFIG["prompt_on_quit"]: return result = dbg.ui.call_with_ui(dbg.ui.dialog, urwid.ListBox(urwid.SimpleListWalker([urwid.Text( "Your PuDB session has ended.\n\n%s" "Would you like to quit PuDB or restart your program?\n" "You may hit 'q' to quit." % status_msg), urwid.Text("\n\nIf you decide to restart, this command " "will be run prior to actually restarting:"), urwid.AttrMap(pre_run_edit, "value") ])), [ ("Restart", "restart"), ("Examine", "examine"), ("Quit", "quit"), ], focus_buttons=True, bind_enter_esc=False, title="Finished", extra_bindings=[ ("q", "quit"), ("esc", "examine"), ]) if result == "quit": return if result == "examine": dbg.post_mortem = True dbg.interaction(None, sys.exc_info(), show_exc_dialog=False) if result == "restart": break pre_run = pre_run_edit.get_edit_text() dbg.restart() if args is not None: sys.argv = prev_sys_argv sys.path = prev_sys_path