Skip to content

pdb commands may try to access non-existing frames #138641

Closed

Description

@yihong0618

Bug report

Bug description:

➜  cpython git:(main) ./python.exe
Python 3.15.0a0 (heads/main:919c7e806e, Sep  8 2025, 17:24:03) [Clang 17.0.0 (clang-1700.0.13.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> breakpoint()
> <python-input-0>(1)<module>()
(Pdb) breakpoint()
(Pdb) ll
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    breakpoint()
    ~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/bdb.py", line 94, in wrapper
    ret = func(frame, *args)
  File "/Users/hyi/prs/cpython/Lib/bdb.py", line 154, in opcode_callback
    frame.f_trace(frame, 'opcode', None)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hyi/prs/cpython/Lib/bdb.py", line 289, in trace_dispatch
    return self.dispatch_opcode(frame, arg)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/Users/hyi/prs/cpython/Lib/bdb.py", line 406, in dispatch_opcode
    self.user_opcode(frame)
    ~~~~~~~~~~~~~~~~^^^^^^^
  File "/Users/hyi/prs/cpython/Lib/pdb.py", line 547, in user_line
    self.interaction(frame, None)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/hyi/prs/cpython/Lib/pdb.py", line 736, in interaction
    self._cmdloop()
    ~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/pdb.py", line 601, in _cmdloop
    self.cmdloop()
    ~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/cmd.py", line 149, in cmdloop
    stop = self.onecmd(line)
  File "/Users/hyi/prs/cpython/Lib/pdb.py", line 1038, in onecmd
    return cmd.Cmd.onecmd(self, line)
           ~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/Users/hyi/prs/cpython/Lib/cmd.py", line 227, in onecmd
    return func(arg)
  File "/Users/hyi/prs/cpython/Lib/pdb.py", line 2156, in do_longlist
    filename = self.curframe.f_code.co_filename
               ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'f_code'
>>> 

CPython versions tested on:

3.15, CPython main branch

Operating systems tested on:

Other

Linked PRs

Activity

  1. yihong0618 commented on Sep 8, 2025

    @yihong0618
    ContributorAuthor

    I am not sure it needs to fix, so will draft a patch

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Sep 8, 2025
  3. picnixz commented on Sep 8, 2025

    @picnixz
    Member

    It's not a crash but it's an annoying situation as the error message is really not needed. So yes a fix is needed.

  4. changed the title [-]breakpoint() in pdb will cause error[/-] [+]`pdb` commands may try to access non-existing frames[/+] on Sep 8, 2025
  5. gaogaotiantian commented on Sep 8, 2025

    @gaogaotiantian
    Member

    I think we are fixing the wrong thing. So this behavior should not happen, but checking self.curframe is not the way to fix it. self.curframe should always exist. The thing we should fix is how we treat breakpoint() in a breakpoint.

  6. yihong0618 commented on Sep 8, 2025

    @yihong0618
    ContributorAuthor

    I think we are fixing the wrong thing. So this behavior should not happen, but checking self.curframe is not the way to fix it. self.curframe should always exist. The thing we should fix is how we treat breakpoint() in a breakpoint.

    copy that, will try to learn that way, thank you

  7. ChenyangLi4288 commented on Oct 14, 2025

    @ChenyangLi4288

    Thank you! @gaogaotiantian I am thinking several ways to fix it. One is to make breakpoint() a no-op in pdb context - Detect when we're already in a debugger and just return immediately. Or simply don't trigger the opcode callback mechanism for the breakpoint() builtin when already debugging.

    The other way is to ensure that nested debugger calls properly maintain frame context.

    What do you think?

  8. added a commit that references this issue on Oct 20, 2026
  9. gaogaotiantian commented on Oct 20, 2026

    @gaogaotiantian
    Member

    Fixed in #159918

  10. added 2 commits that reference this issue on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions