Example #1
0
def set_trace():
    import sys
    dbg = _get_debugger()

    from pudb.settings import load_breakpoints
    for bpoint_descr in load_breakpoints(dbg):
        dbg.set_break(*bpoint_descr)

    dbg.set_trace(sys._getframe().f_back)
Example #2
0
def test_load_breakpoints(mocker):
    fake_data = ['b /home/user/test.py:41'], ['b /home/user/test.py:50']
    mock_open = mocker.mock_open()
    mock_open.return_value.readlines.side_effect = fake_data
    mocker.patch.object(builtins, 'open', mock_open)
    mocker.patch('pudb.settings.lookup_module',
            mocker.Mock(return_value='/home/user/test.py'))
    mocker.patch('pudb.settings.get_breakpoint_invalid_reason',
            mocker.Mock(return_value=None))
    result = load_breakpoints()
    expected = [('/home/user/test.py', 41, False, None, None),
                ('/home/user/test.py', 50, False, None, None)]
    assert result == expected
Example #3
0
def test_load_breakpoints(mocker):
    fake_data = ['b /home/user/test.py:41'], ['b /home/user/test.py:50']
    mock_open = mocker.mock_open()
    mock_open.return_value.readlines.side_effect = fake_data
    mocker.patch.object(builtins, 'open', mock_open)
    mocker.patch('pudb.settings.lookup_module',
                 mocker.Mock(return_value='/home/user/test.py'))
    mocker.patch('pudb.settings.get_breakpoint_invalid_reason',
                 mocker.Mock(return_value=None))
    result = load_breakpoints()
    expected = [('/home/user/test.py', 41, False, None, None),
                ('/home/user/test.py', 50, False, None, None)]
    assert result == expected
Example #4
0
def test_load_breakpoints(mocker):
    fake_data = ["b /home/user/test.py:41"], ["b /home/user/test.py:50"]
    mock_open = mocker.mock_open()
    mock_open.return_value.readlines.side_effect = fake_data
    mocker.patch.object(builtins, "open", mock_open)
    mocker.patch("pudb.settings.lookup_module",
                 mocker.Mock(return_value="/home/user/test.py"))
    mocker.patch("pudb.settings.get_breakpoint_invalid_reason",
                 mocker.Mock(return_value=None))
    result = load_breakpoints()
    expected = [("/home/user/test.py", 41, False, None, None),
                ("/home/user/test.py", 50, False, None, None)]
    assert result == expected
Example #5
0
def runscript(mainpyfile, args=None, pre_run="", steal_output=False):
    from pudb.debugger import Debugger
    dbg = 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)

    from pudb.settings import load_breakpoints
    for bpoint_descr in load_breakpoints(dbg):
        dbg.set_break(*bpoint_descr)

    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:
            status_msg = "The debuggee exited normally with status code %s.\n\n" % se.code
        except:
Example #6
0
    $ ./load_breakpoints.py foo.py
    12
    $ ./set_breakpoint.py foo.py 11
    $ ./load_breakpoints.py foo.py
    12
    11
"""

import sys

from pudb.settings import load_breakpoints, save_breakpoints
from pudb import NUM_VERSION

args = () if NUM_VERSION >= (2013, 1) else (None, )
bps = [bp[:2] for bp in load_breakpoints(*args)]

filename = sys.argv[1]
row = int(sys.argv[2])

bp = (filename, row)
if bp in bps:
    bps.pop(bps.index(bp))
else:
    bps.append(bp)


class BP(object):
    def __init__(self, fn, ln):
        self.file = fn
        self.line = ln
Example #7
0
def runscript(mainpyfile, args=None, pre_run="", steal_output=False):
    from pudb.debugger import Debugger
    dbg = 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)

    from pudb.settings import load_breakpoints
    for bpoint_descr in load_breakpoints(dbg):
        dbg.set_break(*bpoint_descr)

    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())

        def quit_debugger(w, size, key):
            dbg.ui.quit_event_loop = ["quit"]

        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"),
                ("Quit", "quit"),
                ],
            focus_buttons=True,
            bind_enter_esc=False,
            title="Finished",
            extra_bindings=[("q", quit_debugger)])

        if result == "quit":
            return

        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