8000 gh-123756: Only allow restart in command line mode by gaogaotiantian · Pull Request #123757 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-123756: Only allow restart in command line mode #123757

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 19 commits into from
Sep 25, 2024
Merged
Changes from 1 commit
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
Next Next commit
Only allow restart in command line mode
  • Loading branch information
gaogaotiantian committed Sep 6, 2024
commit 8c6fb0514346ba85aac4187ca0e682a559774b72
9 changes: 7 additions & 2 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
_last_pdb_instance = None

def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
nosigint=False, readrc=True):
nosigint=False, readrc=True, allow_restart=False):
bdb.Bdb.__init__(self, skip=skip)
cmd.Cmd.__init__(self, completekey, stdin, stdout)
sys.audit("pdb.Pdb")
Expand All @@ -321,6 +321,7 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
self.mainpyfile = ''
self._wait_for_mainpyfile = False
self.tb_lineno = {}
self.allow_restart = allow_restart
# Try to load readline if it exists
try:
import readline
Expand Down Expand Up @@ -1607,6 +1608,10 @@ def do_run(self, arg):
sys.argv. History, breakpoints, actions and debugger options
are preserved. "restart" is an alias for "run".
"""
if not self.allow_restart:
self.error('run/restart command is only allowed in command line usage:\n'
'e.g. "python -m pdb myscript.py"')
return
if arg:
import shlex
argv0 = sys.argv[0:1]
Expand Down Expand Up @@ -2476,7 +2481,7 @@ def main():
# modified by the script being debugged. It's a bad idea when it was
# changed by the user from the command line. There is a "restart" command
# which allows explicit specification of command line arguments.
pdb = Pdb()
pdb = Pdb(allow_restart=True)
pdb.rcLines.extend(opts.commands)
while True:
try:
Expand Down
Loading
0