Skip to content

Commit

Permalink
Add PUDB_RDB_REVERSE var to control reverse mode (#631)
Browse files Browse the repository at this point in the history
* Add PUDB_RDB_REVERSE var to control reverse mode

* Fix flake8 warnings
  • Loading branch information
max-arnold authored Jan 16, 2024
1 parent 5b7a07f commit 270c7c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions doc/starting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ Specify host and port in set_trace and set the *reverse* parameter to *True*::
from pudb.remote import set_trace
set_trace(reverse=True)

The "reverse" mode can also be enabled by setting the environment variable to a
non-empty value (the keyword argument has priority over the env var)::

export PUDB_RDB_REVERSE=1

Then watch the debugger connect to netcat::

pudb:9999: Now in session with 127.0.0.1:6899.
Expand Down
19 changes: 15 additions & 4 deletions pudb/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@

from pudb.debugger import Debugger

__all__ = ["PUDB_RDB_HOST", "PUDB_RDB_PORT", "default_port", "debugger", "set_trace",
__all__ = ["PUDB_RDB_HOST", "PUDB_RDB_PORT", "PUDB_RDB_REVERSE",
"default_port", "debugger", "set_trace",
"debug_remote_on_single_rank"]

default_port = 6899

PUDB_RDB_HOST = os.environ.get("PUDB_RDB_HOST") or "127.0.0.1"
PUDB_RDB_PORT = int(os.environ.get("PUDB_RDB_PORT") or default_port)
PUDB_RDB_REVERSE = bool(os.environ.get("PUDB_RDB_REVERSE"))

#: Holds the currently active debugger.
_current = [None]
Expand Down Expand Up @@ -124,7 +126,7 @@ def __init__(
port_search_limit=100,
out=sys.stdout,
term_size=None,
reverse=False,
reverse=PUDB_RDB_REVERSE,
):
"""
:arg term_size: A two-tuple ``(columns, rows)``, or *None*. If *None*,
Expand Down Expand Up @@ -245,7 +247,12 @@ def close_remote_session(self):
self.say(SESSION_ENDED.format(self=self))


def debugger(term_size=None, host=PUDB_RDB_HOST, port=PUDB_RDB_PORT, reverse=False):
def debugger(
term_size=None,
host=PUDB_RDB_HOST,
port=PUDB_RDB_PORT,
reverse=PUDB_RDB_REVERSE
):
"""Return the current debugger instance (if any),
or creates a new one."""
rdb = _current[0]
Expand All @@ -258,7 +265,11 @@ def debugger(term_size=None, host=PUDB_RDB_HOST, port=PUDB_RDB_PORT, reverse=Fal


def set_trace(
frame=None, term_size=None, host=PUDB_RDB_HOST, port=PUDB_RDB_PORT, reverse=False
frame=None,
term_size=None,
host=PUDB_RDB_HOST,
port=PUDB_RDB_PORT,
reverse=PUDB_RDB_REVERSE
):
"""Set breakpoint at current location, or a specified frame"""
if frame is None:
Expand Down

0 comments on commit 270c7c9

Please sign in to comment.