Skip to content

Commit 797b29b

Browse files
godlygeekpablogsal
andauthored
gh-131591: Allow pdb to attach to a running process (#132451)
Co-authored-by: Pablo Galindo <[email protected]>
1 parent 3a39e33 commit 797b29b

File tree

5 files changed

+1330
-11
lines changed

5 files changed

+1330
-11
lines changed

Doc/whatsnew/3.14.rst

+29-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ PEP 768: Safe external debugger interface for CPython
9999

100100
:pep:`768` introduces a zero-overhead debugging interface that allows debuggers and profilers
101101
to safely attach to running Python processes. This is a significant enhancement to Python's
102-
debugging capabilities allowing debuggers to forego unsafe alternatives.
102+
debugging capabilities allowing debuggers to forego unsafe alternatives. See
103+
:ref:`below <whatsnew314-remote-pdb>` for how this feature is leveraged to
104+
implement the new :mod:`pdb` module's remote attaching capabilities.
103105

104106
The new interface provides safe execution points for attaching debugger code without modifying
105107
the interpreter's normal execution path or adding runtime overhead. This enables tools to
@@ -149,6 +151,32 @@ See :pep:`768` for more details.
149151

150152
(Contributed by Pablo Galindo Salgado, Matt Wozniski, and Ivona Stojanovic in :gh:`131591`.)
151153

154+
155+
.. _whatsnew314-remote-pdb:
156+
157+
Remote attaching to a running Python process with PDB
158+
-----------------------------------------------------
159+
160+
The :mod:`pdb` module now supports remote attaching to a running Python process
161+
using a new ``-p PID`` command-line option:
162+
163+
.. code-block:: sh
164+
165+
python -m pdb -p 1234
166+
167+
This will connect to the Python process with the given PID and allow you to
168+
debug it interactively. Notice that due to how the Python interpreter works
169+
attaching to a remote process that is blocked in a system call or waiting for
170+
I/O will only work once the next bytecode instruction is executed or when the
171+
process receives a signal.
172+
173+
This feature leverages :pep:`768` and the :func:`sys.remote_exec` function
174+
to attach to the remote process and send the PDB commands to it.
175+
176+
177+
(Contributed by Matt Wozniski and Pablo Galindo in :gh:`131591`.)
178+
179+
152180
.. _whatsnew314-pep758:
153181

154182
PEP 758 – Allow except and except* expressions without parentheses

0 commit comments

Comments
 (0)