access further features, you have to do this yourself:
.. class:: Pdb(completekey='tab', stdin=None, stdout=None, skip=None, \
- nosigint=False, readrc=True)
+ nosigint=False, readrc=True, mode=None)
:class:`Pdb` is the debugger class.
The *readrc* argument defaults to true and controls whether Pdb will load
.pdbrc files from the filesystem.
+ The *mode* argument specifies how the debugger was invoked.
+ It impacts the workings of some debugger commands.
+ Valid values are ``'inline'`` (used by the breakpoint() builtin),
+ ``'cli'`` (used by the command line invocation)
+ or ``None`` (for backwards compatible behaviour, as before the *mode*
+ argument was added).
+
Example call to enable tracing with *skip*::
import pdb; pdb.Pdb(skip=['django.*']).set_trace()
.. versionchanged:: 3.6
The *readrc* argument.
+ .. versionadded:: 3.14
+ Added the *mode* argument.
+
.. method:: run(statement, globals=None, locals=None)
runeval(expression, globals=None, locals=None)
runcall(function, *args, **kwds)
History, breakpoints, actions and debugger options are preserved.
:pdbcmd:`restart` is an alias for :pdbcmd:`run`.
+ .. versionchanged:: 3.14
+ :pdbcmd:`run` and :pdbcmd:`restart` commands are disabled when the
+ debugger is invoked in ``'inline'`` mode.
+
.. pdbcommand:: q(uit)
Quit from the debugger. The program being executed is aborted.
:pdbcmd:`commands` are preserved across hard-coded breakpoints.
(Contributed by Tian Gao in :gh:`121450`.)
+* Added a new argument ``mode`` to :class:`pdb.Pdb`. Disabled ``restart``
+ command when :mod:`pdb` is in ``inline`` mode.
+ (Contributed by Tian Gao in :gh:`123757`.)
pickle
------
_last_pdb_instance = None
def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
- nosigint=False, readrc=True):
+ nosigint=False, readrc=True, mode=None):
bdb.Bdb.__init__(self, skip=skip)
cmd.Cmd.__init__(self, completekey, stdin, stdout)
sys.audit("pdb.Pdb")
self.mainpyfile = ''
self._wait_for_mainpyfile = False
self.tb_lineno = {}
+ self.mode = mode
# Try to load readline if it exists
try:
import readline
sys.argv. History, breakpoints, actions and debugger options
are preserved. "restart" is an alias for "run".
"""
+ if self.mode == 'inline':
+ self.error('run/restart command is disabled when pdb is running in inline mode.\n'
+ 'Use the command line interface to enable restarting your program\n'
+ 'e.g. "python -m pdb myscript.py"')
+ return
if arg:
import shlex
argv0 = sys.argv[0:1]
if Pdb._last_pdb_instance is not None:
pdb = Pdb._last_pdb_instance
else:
- pdb = Pdb()
+ pdb = Pdb(mode='inline')
if header is not None:
pdb.message(header)
pdb.set_trace(sys._getframe().f_back, commands=commands)
# 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(mode='cli')
pdb.rcLines.extend(opts.commands)
while True:
try:
(Pdb) continue
"""
+def test_pdb_restart_command():
+ """Test restart command
+
+ >>> def test_function():
+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False, mode='inline').set_trace()
+ ... x = 1
+
+ >>> with PdbTestInput([ # doctest: +ELLIPSIS
+ ... 'restart',
+ ... 'continue',
+ ... ]):
+ ... test_function()
+ > <doctest test.test_pdb.test_pdb_restart_command[0]>(2)test_function()
+ -> import pdb; pdb.Pdb(nosigint=True, readrc=False, mode='inline').set_trace()
+ (Pdb) restart
+ *** run/restart command is disabled when pdb is running in inline mode.
+ Use the command line interface to enable restarting your program
+ e.g. "python -m pdb myscript.py"
+ (Pdb) continue
+ """
+
def test_pdb_commands_with_set_trace():
"""Test that commands can be passed to Pdb.set_trace()
--- /dev/null
+Added a new argument ``mode`` to :class:`pdb.Pdb`. Only allow :mod:`pdb` from command line to use ``restart`` command.