Skip to content

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

Closed

Description

@d-maurer

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

Activity

  1. gaogaotiantian commented on May 31, 2024

    @gaogaotiantian
    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.

  2. d-maurer commented on May 31, 2024

    @d-maurer
    Author
  3. gaogaotiantian commented on May 31, 2024

    @gaogaotiantian
    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.

  4. d-maurer commented on May 31, 2024

    @d-maurer
    Author
  5. added 7 commits that reference this issue on Jun 14, 2024
  6. gaogaotiantian commented on Jun 24, 2024

    @gaogaotiantian
    Member

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

  7. d-maurer commented on Jun 24, 2024

    @d-maurer
    Author
  8. added a commit that references this issue on Jun 30, 2024
  9. added a commit that references this issue on Jul 11, 2024
  10. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

type-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions