Skip to content

Conversation

@cocolato
Copy link
Contributor

@cocolato cocolato commented Dec 16, 2025

What this PR does

When commands is invoked without an argument, pdb now finds and uses the last available (non-deleted) breakpoint instead of blindly using the last breakpoint number which might have been 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

after fix:

➜ ./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
(com) p "success"
(com) end
(Pdb) c
'success'
> /home/loyd/code_files/cpython/main.py(3)<module>()
-> bar = 2

Co-authored-by: AN Long <[email protected]>
Copy link
Contributor

@johnslavik johnslavik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good idea!

Thoughts:

  • Should it really be the last available breakpoint, or the last enabled breakpoint?
  • Let's update the documentation to reflect the new behavior.
  • In the no-arg mode, maybe print a message like *** Commands for breakpoint X, so it is always clear to the user which exactly is the breakpoint they're writing to?

cocolato and others added 2 commits December 17, 2025 00:31
Copy link
Member

@gaogaotiantian gaogaotiantian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is a good change. There are a few small items that are partially mentioned above:

  1. We need to update the documentation in pdb.rst. To something like With no bpnumber argument, commands refers to the most recently set breakpoint that still exists.
  2. The error message 'no breakpoints set' is a bit too concise. I think we should comply to the other error messages of commands and do something like cannot set commands: no existing breakpoint.
  3. Even though I think having a message to tell the user about which breakpoint they are setting commands to is a good idea, it's kind of a breaking change. I believe almost all of the usage would be to set commands immediately after setting breakpoints. I think we can skip that for now.

@cocolato
Copy link
Contributor Author

Documents and error messages have been updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants