8000 gh-133490: Add color support to remote PDB by godlygeek · Pull Request #133491 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-133490: Add color support to remote PDB #133491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2677,6 +2677,7 @@ def __init__(
sockfile,
signal_server=None,
owns_sockfile=True,
colorize=False,
**kwargs,
):
self._owns_sockfile = owns_sockfile
Expand All @@ -2687,7 +2688,10 @@ def __init__(
if signal_server:
# Only started by the top level _PdbServer, not recursive ones.
self._start_signal_listener(signal_server)
# Override the `colorize` attribute set by the parent constructor,
# because it checks the server's stdout, rather than the client's.
super().__init__(colorize=False, **kwargs)
self.colorize = colorize

@staticmethod
def protocol_version():
Expand Down Expand Up @@ -2975,7 +2979,11 @@ def do_interact(self, arg):

@typing.override
def _create_recursive_debugger(self):
return _PdbServer(self._sockfile, owns_sockfile=False)
return _PdbServer(
self._sockfile,
owns_sockfile=False,
colorize=self.colorize,
)

@typing.override
def _prompt_for_confirmation(self, prompt, default):
Expand Down Expand Up @@ -3336,7 +3344,16 @@ def complete(self, text, state):
return None


def _connect(*, host, port, frame, commands, version, signal_raising_thread):
def _connect(
*,
host,
port,
frame,
commands,
version,
signal_raising_thread,
colorize,
):
with closing(socket.create_connection((host, port))) as conn:
sockfile = conn.makefile("rwb")

Expand All @@ -3347,7 +3364,11 @@ def _connect(*, host, port, frame, commands, version, signal_raising_thread):
else:
signal_server = None

remote_pdb = _PdbServer(sockfile, signal_server=signal_server)
remote_pdb = _PdbServer(
sockfile,
signal_server=signal_server,
colorize=colorize,
)
weakref.finalize(remote_pdb, sockfile.close)

if Pdb._last_pdb_instance is not None:
Expand Down Expand Up @@ -3379,6 +3400,7 @@ def attach(pid, commands=()):
)

use_signal_thread = sys.platform == "win32"
colorize = _colorize.can_colorize()

connect_script.write(
textwrap.dedent(
Expand All @@ -3391,6 +3413,7 @@ def attach(pid, commands=()):
commands={json.dumps("\n".join(commands))},
version={_PdbServer.protocol_version()},
signal_raising_thread={use_signal_thread!r},
colorize={colorize!r},
)
"""
)
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_remote_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ def dummy_function():
commands="",
version=pdb._PdbServer.protocol_version(),
signal_raising_thread=False,
colorize=False,
)
return x # This line won't be reached in debugging

Expand Down Expand Up @@ -1210,6 +1211,7 @@ def bar():
commands="",
version=pdb._PdbServer.protocol_version(),
signal_raising_thread=True,
colorize=False,
)
print("Connected to debugger")
iterations = 50
Expand Down Expand Up @@ -1301,6 +1303,7 @@ def run_test():
commands="",
version=fake_version,
signal_raising_thread=False,
colorize=False,
)

# This should print if the debugger detaches correctly
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add color support to PDB in remote mode.
Loading
0