Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.13.0b1: suboptimal pdb._post_mortem behavior if .pdbrc exists #119824

Closed
d-maurer opened this issue May 31, 2024 · 6 comments
Closed

Python 3.13.0b1: suboptimal pdb._post_mortem behavior if .pdbrc exists #119824

d-maurer opened this issue May 31, 2024 · 6 comments
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@d-maurer
Copy link

d-maurer commented May 31, 2024

Bug report

Bug description:

pdb.post_mortem used to display the current stack entry before the command loop (which has been useful). With Python 3.13, this is no longer the case when there is a .pdbrc file.
The reason is the following code in pdb.Pdb.interaction:

            # if we have more commands to process, do not show the stack entry
            if not self.cmdqueue:
                self.print_stack_entry(self.stack[self.curindex])

If a .pdbrc exists, self.cmdqueue contains the commands from this file and the current stack entry is not displayed.

I suggest the introduction of a new interaction parameter show_stack_entry (with default False) and to display the current stack entry if it has a true value. Set it to True in the _post_mortem call of interaction.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

@d-maurer d-maurer added the type-bug An unexpected behavior, bug, or error label May 31, 2024
@gaogaotiantian gaogaotiantian self-assigned this May 31, 2024
@gaogaotiantian
Copy link
Member

This is more complicated than it appears to be:

  1. Where should the stack entry be printed? Before or after the .pdbrc file is processed? I think after is the right way to go but we can't achieve this easily with the current structure.
  2. Whether the stack entry should be printed is supposed to be determined by the content of .pdbrc - whether that gives the user chance to input commands, which can not be determined at the entry point of interaction.

This is a real issue and I need to think about how to address it without changes to cmd.Cmd.

@d-maurer
Copy link
Author

d-maurer commented May 31, 2024 via email

@gaogaotiantian
Copy link
Member

I realized these days that people are using .pdbrc differently. For example in #119579, the user uses .pdbrc as a debugging script so that they don't have to re-type the commands over and over again.

As you can tell, they use sophisticated comamnds like break, commands etc., maybe even ll or p to display some data. This is a completely valid usage (arguably a useful one), and the outcome is - it will print stuff on the screen! And that would make "before" or "after" a big difference.

The same thing could happen with post-mortem debugging as well - the user could potentially print something to help debugging, and if you print the stack entry before .pdbrc executes, it would be too far away.

And this is not specific to post-mortem debugging, actually this is an issue for all cases involving .pdbrc. That's why I wanted to fix it for good, not just have a force switch to print the entry.

I had a patch already, so hopefully this issue could be fixed soon.

@d-maurer
Copy link
Author

d-maurer commented May 31, 2024 via email

gaogaotiantian added a commit to gaogaotiantian/cpython that referenced this issue Jun 15, 2024
gaogaotiantian added a commit to gaogaotiantian/cpython that referenced this issue Jun 23, 2024
@gaogaotiantian
Copy link
Member

This is fixed in main, 3.13 and 3.12. Let me know if you still have the issue.

@d-maurer
Copy link
Author

d-maurer commented Jun 24, 2024 via email

mrahtz pushed a commit to mrahtz/cpython that referenced this issue Jun 30, 2024
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants