Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
def set_trace():
    import sys

    dbg = _get_debugger()

    set_interrupt_handler()
    dbg.set_trace(sys._getframe().f_back)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
        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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
    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()
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
0
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
Ejemplo n.º 17
0
def _interrupt_handler(signum, frame):
    from pudb import _get_debugger
    _get_debugger().set_trace(frame)
Ejemplo n.º 18
0
def runcall(*args, **kwds):
    return _get_debugger().runcall(*args, **kwds)
Ejemplo n.º 19
0
def runeval(expression, globals=None, locals=None):
    return _get_debugger().runeval(expression, globals, locals)
Ejemplo n.º 20
0
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)
Ejemplo n.º 21
0
    def db(self):
        import sys
        dbg = _get_debugger()

        set_interrupt_handler()
        dbg.set_trace(sys._getframe().f_back)
Ejemplo n.º 22
0
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)
Ejemplo n.º 23
0
def _interrupt_handler(signum, frame):
    from pudb import _get_debugger
    _get_debugger().set_trace(frame)
Ejemplo n.º 24
0
def set_trace():
    dbg = _get_debugger()
    set_interrupt_handler()
    dbg.set_trace(sys._getframe().f_back.f_back)
Ejemplo n.º 25
0
def runstatement(statement, globals=None, locals=None):
    _get_debugger().run(statement, globals, locals)
Ejemplo n.º 26
0
def runstatement(statement, globals=None, locals=None):
    _get_debugger().run(statement, globals, locals)
Ejemplo n.º 27
0
def runcall(*args, **kwds):
    return _get_debugger().runcall(*args, **kwds)
Ejemplo n.º 28
0
def runeval(expression, globals=None, locals=None):
    return _get_debugger().runeval(expression, globals, locals)
Ejemplo n.º 29
0
def _interrupt_handler(signum, frame):
    from pudb import _get_debugger
    _get_debugger().set_trace(frame, as_breakpoint=False)
Ejemplo n.º 30
0
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()
Ejemplo n.º 31
0
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
Ejemplo n.º 32
0
def _interrupt_handler(signum, frame):
    from pudb import _get_debugger
    _get_debugger().set_trace(frame, as_breakpoint=False)