Skip to content

Commit 5e21f89

Browse files
Show troubleshooting URL for remote debugging permission errors in pdb
Add help text and display a URL in permission-related errors when using the -p option in pdb to assist users in resolving common issues during remote debugging.
1 parent 48db553 commit 5e21f89

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Lib/pdb.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3504,6 +3504,20 @@ def help():
35043504
"-c 'until X'"."""
35053505

35063506

3507+
def exit_with_permission_help_text():
3508+
"""
3509+
Prints a message pointing to platform-specific permission help text and exits the program.
3510+
This function is called when a PermissionError is encountered while trying
3511+
to attach to a process.
3512+
"""
3513+
print(
3514+
"Error: The specified process cannot be attached to due to insufficient permissions.\n"
3515+
"See the Python documentation for details on required privileges and troubleshooting:\n"
3516+
"https://docs.python.org/3.14/howto/remote_debugging.html#permission-requirements\n"
3517+
)
3518+
sys.exit(1)
3519+
3520+
35073521
def main():
35083522
import argparse
35093523

@@ -3537,7 +3551,10 @@ def main():
35373551
opts = parser.parse_args()
35383552
if opts.module:
35393553
parser.error("argument -m: not allowed with argument --pid")
3540-
attach(opts.pid, opts.commands)
3554+
try:
3555+
attach(opts.pid, opts.commands)
3556+
except PermissionError as e:
3557+
exit_with_permission_help_text()
35413558
return
35423559
elif opts.module:
35433560
# If a module is being debugged, we consider the arguments after "-m module" to

Lib/test/test_remote_pdb.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,9 @@ def do_integration_test(self, client_stdin):
15261526
redirect_stdout(client_stdout),
15271527
redirect_stderr(client_stderr),
15281528
unittest.mock.patch("sys.argv", ["pdb", "-p", str(process.pid)]),
1529+
unittest.mock.patch(
1530+
"pdb.exit_with_permission_help_text", side_effect=PermissionError
1531+
),
15291532
):
15301533
try:
15311534
pdb.main()

0 commit comments

Comments
 (0)