Skip to content

Commit b9002bf

Browse files
committed
commands command with no bpnumber should use last available breakpoint
1 parent 14d3974 commit b9002bf

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

Lib/pdb.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,12 @@ def do_commands(self, arg):
13151315
reached.
13161316
"""
13171317
if not arg:
1318-
bnum = len(bdb.Breakpoint.bpbynumber) - 1
1318+
for bnum in range(len(bdb.Breakpoint.bpbynumber) - 1, -1, -1):
1319+
if bdb.Breakpoint.bpbynumber[bnum] is not None:
1320+
break
1321+
if bnum == 0:
1322+
self.error('no breakpoints setted')
1323+
return
13191324
else:
13201325
try:
13211326
bnum = int(arg)

Lib/test/test_pdb.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3478,6 +3478,43 @@ def test_pdb_issue_gh_65052():
34783478
(Pdb) continue
34793479
"""
34803480

3481+
def test_pdb_issue_142834():
3482+
"""See issue-142834
3483+
3484+
>>> def test_function():
3485+
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
3486+
... foo = 1
3487+
... bar = 2
3488+
3489+
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
3490+
... 'break 4',
3491+
... 'break 3',
3492+
... 'clear 2',
3493+
... 'commands',
3494+
... 'p "success"',
3495+
... 'end',
3496+
... 'continue',
3497+
... '',
3498+
... ]):
3499+
... test_function()
3500+
> <doctest test.test_pdb.test_pdb_issue_gh_xxx[0]>(2)test_function()
3501+
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
3502+
(Pdb) break 4
3503+
Breakpoint 1 at <doctest test.test_pdb.test_pdb_issue_gh_xxx[0]>:4
3504+
(Pdb) break 3
3505+
Breakpoint 2 at <doctest test.test_pdb.test_pdb_issue_gh_xxx[0]>:3
3506+
(Pdb) clear 2
3507+
Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_issue_gh_xxx[0]>:3
3508+
(Pdb) commands
3509+
(com) p "success"
3510+
(com) end
3511+
(Pdb) continue
3512+
'success'
3513+
> <doctest test.test_pdb.test_pdb_issue_gh_xxx[0]>(4)test_function()
3514+
-> bar = 2
3515+
(Pdb)
3516+
"""
3517+
34813518

34823519
@support.force_not_colorized_test_class
34833520
@support.requires_subprocess()

0 commit comments

Comments
 (0)