Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd2db5b9

Browse files
Mention remote debugging in pdb.rst
1 parent4657a7b commitd2db5b9

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

‎Doc/library/pdb.rst

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ The module :mod:`pdb` defines an interactive source code debugger for Python
1616
programs. It supports setting (conditional) breakpoints and single stepping at
1717
the source line level, inspection of stack frames, source code listing, and
1818
evaluation of arbitrary Python code in the context of any stack frame. It also
19-
supports post-mortem debugging and can be called under program control.
19+
supports post-mortem debugging and can be called under program control. The
20+
:mod:`pdb` module also supports remote attaching to a running Python process
21+
using a ``-p PID`` command-line option.
2022

2123
..index::
2224
single: Pdb (class in pdb)
@@ -80,7 +82,10 @@ The debugger's prompt is ``(Pdb)``, which is the indicator that you are in debug
8082
You can also invoke:mod:`pdb` from the command line to debug other scripts. For
8183
example::
8284

83-
python -m pdb [-c command] (-m module | pyfile) [args ...]
85+
python -m pdb [-c command] (-m module | -p pid | pyfile) [args ...]
86+
87+
Remote debugging is supported by attaching to a running Python process using
88+
the ``-p`` option and a PID.
8489

8590
When invoked as a module, pdb will automatically enter post-mortem debugging if
8691
the program being debugged exits abnormally. After post-mortem debugging (or
@@ -104,6 +109,27 @@ useful than quitting the debugger upon program's exit.
104109
..versionchanged::3.7
105110
Added the ``-m`` option.
106111

112+
..option::-p,--pid <pid>
113+
114+
Attach to the process with the specified PID.
115+
116+
..versionchanged::3.14
117+
Added the ``-p`` and ``--pid`` options. This feature leverages:pep:`768`
118+
and the:func:`sys.remote_exec` function to attach to the remote process
119+
and send the PDB commands to it.
120+
121+
122+
To attach to a running Python process for remote debugging, use the ``-p`` or
123+
``--pid`` option with the target process's PID::
124+
125+
python -m pdb -p 1234
126+
127+
This will connect to the Python process with the given PID and allow you to
128+
debug it interactively. Notice that due to how the Python interpreter works,
129+
attaching to a remote process that is blocked in a system call or waiting for
130+
I/O will only work once the next bytecode instruction is executed or when the
131+
process receives a signal.
132+
107133
Typical usage to execute a statement under control of the debugger is::
108134

109135
>>> import pdb

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp