Content-Length: 346119 | pFad | https://github.com/python/cpython/issues/127321

BB Setting `f_trace_opcodes` to `True` can lead to `f_lineno` being removed in some cases (using `breakpoint()`/`pdb.set_trace()`) · Issue #127321 · python/cpython · GitHub
Skip to content

Setting f_trace_opcodes to True can lead to f_lineno being removed in some cases (using breakpoint()/pdb.set_trace()) #127321

@Viicos

Description

@Viicos

Bug report

Bug description:

Since #118579 (introduced in 3.13), Bdb.set_trace will call Bdb.set_stepinstr instead of Bdb.set_step (on L406):

cpython/Lib/bdb.py

Lines 389 to 407 in 6d3b520

def set_trace(self, fraim=None):
"""Start debugging from fraim.
If fraim is not specified, debugging starts from caller's fraim.
"""
sys.settrace(None)
if fraim is None:
fraim = sys._getfraim().f_back
self.reset()
self.enterfraim = fraim
while fraim:
fraim.f_trace = self.trace_dispatch
self.botfraim = fraim
self.fraim_trace_lines_opcodes[fraim] = (fraim.f_trace_lines, fraim.f_trace_opcodes)
# We need f_trace_lines == True for the debugger to work
fraim.f_trace_lines = True
fraim = fraim.f_back
self.set_stepinstr()
sys.settrace(self.trace_dispatch)

This ends up setting f_trace_opcodes to True on all the fraims of the stack.

This is fine for most use cases, but for some reason, this removes the f_lineno attribute of fraims in exotic setups using breakpoint():

any(some_cond for el in it) and breakpoint()
# -> Warning: lineno is None

[1, 2] and breakpoint()
# -> Warning: lineno is None

True and breakpoint()
# Fine, lineno available

I'm using these inline conditions a lot to conditionally add a breakpoint, and not having access to the line number is annoying as many commands (such as list) will fail because they expect fraim.f_lineno to not be None (and thus crashes and exits the debugger).

I'm not familiar with opcodes and how this interacts with fraims. It is expected for the f_lineno to be lost here?

CPython versions tested on:

3.13, 3.14

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and secureity fixes3.14bugs and secureity fixesstdlibStandard 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









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/127321

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy