cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Pdb "commands" command with no bpnumber should use last available breakpoint

Open cocolato opened this issue 1 week ago • 2 comments

Bug report

Bug description:

According to the documentation:

With no bpnumber argument, commands refers to the last breakpoint set.

I think the intended meaning should be the last available breakpoint. However, when using the commands command without specifying a breakpoint number, if the most recently created breakpoint has been deleted, the current behavior throws an error stating "Breakpoint N already deleted".

main.py:

foo = 1
bar = 2
➜ ./python -m pdb main.py
> /cpython/main.py(2)<module>()
-> foo = 1
(Pdb) b 3    
Breakpoint 1 at /cpython/main.py:3
(Pdb) b 2
Breakpoint 2 at /cpython/main.py:2
(Pdb) clear 2
Deleted breakpoint 2 at /cpython/main.py:2
(Pdb) commands # should set command on breakpoint 1
*** cannot set commands: Breakpoint 2 already deleted

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-142835

cocolato avatar Dec 16 '25 15:12 cocolato

@ZeroIntensity stdlib

johnslavik avatar Dec 16 '25 15:12 johnslavik

Good idea! Should it really be the last available breakpoint, or the last enabled breakpoint?

johnslavik avatar Dec 16 '25 16:12 johnslavik

Should it really be the last available breakpoint, or the last enabled breakpoint?

cc @gaogaotiantian

johnslavik avatar Dec 17 '25 03:12 johnslavik

Should it really be the last available breakpoint, or the last enabled breakpoint?

I think it should be the last available breakpoint because it's totally valid to set commands on a disabled breakpoint. However, this is a very rare case already. I believe commands is used mostly either immediately after breakpoint, or explicitly on a numbered breakpoint. This specific difference won't be noticable to the majority of the users.

gaogaotiantian avatar Dec 17 '25 03:12 gaogaotiantian