To remove all commands from a breakpoint, type ``commands`` and follow it
immediately with ``end``; that is, give no commands.
- With no *bpnumber* argument, ``commands`` refers to the last breakpoint set.
+ With no *bpnumber* argument, ``commands`` refers to the most recently set
+ breakpoint that still exists.
You can use breakpoint commands to start your program up again. Simply use
the :pdbcmd:`continue` command, or :pdbcmd:`step`,
reached.
"""
if not arg:
- bnum = len(bdb.Breakpoint.bpbynumber) - 1
+ for bp in reversed(bdb.Breakpoint.bpbynumber):
+ if bp is None:
+ continue
+ bnum = bp.number
+ break
+ else:
+ self.error('cannot set commands: no existing breakpoint')
+ return
else:
try:
bnum = int(arg)
(Pdb) continue
"""
+def test_pdb_commands_last_breakpoint():
+ """See GH-142834
+
+ >>> def test_function():
+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ ... foo = 1
+ ... bar = 2
+
+ >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
+ ... 'break 4',
+ ... 'break 3',
+ ... 'clear 2',
+ ... 'commands',
+ ... 'p "success"',
+ ... 'end',
+ ... 'continue',
+ ... 'clear 1',
+ ... 'commands',
+ ... 'continue',
+ ... ]):
+ ... test_function()
+ > <doctest test.test_pdb.test_pdb_commands_last_breakpoint[0]>(2)test_function()
+ -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ (Pdb) break 4
+ Breakpoint 1 at <doctest test.test_pdb.test_pdb_commands_last_breakpoint[0]>:4
+ (Pdb) break 3
+ Breakpoint 2 at <doctest test.test_pdb.test_pdb_commands_last_breakpoint[0]>:3
+ (Pdb) clear 2
+ Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_commands_last_breakpoint[0]>:3
+ (Pdb) commands
+ (com) p "success"
+ (com) end
+ (Pdb) continue
+ 'success'
+ > <doctest test.test_pdb.test_pdb_commands_last_breakpoint[0]>(4)test_function()
+ -> bar = 2
+ (Pdb) clear 1
+ Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_commands_last_breakpoint[0]>:4
+ (Pdb) commands
+ *** cannot set commands: no existing breakpoint
+ (Pdb) continue
+ """
+
@support.force_not_colorized_test_class
@support.requires_subprocess()