0
0
mirror of https://github.com/python/cpython.git synced 2024-11-21 12:59:38 +01:00

gh-58956: Set f_trace on frames with breakpoints after setting a new breakpoint (#124454)

This commit is contained in:
Tian Gao 2024-10-15 12:56:33 -07:00 committed by GitHub
parent 9c2bb7d551
commit 12eaadc0ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 0 deletions

View File

@ -461,6 +461,14 @@ class Bdb:
return 'Line %s:%d does not exist' % (filename, lineno)
self._add_to_breaks(filename, lineno)
bp = Breakpoint(filename, lineno, temporary, cond, funcname)
# After we set a new breakpoint, we need to search through all frames
# and set f_trace to trace_dispatch if there could be a breakpoint in
# that frame.
frame = self.enterframe
while frame:
if self.break_anywhere(frame):
frame.f_trace = self.trace_dispatch
frame = frame.f_back
return None
def _load_breaks(self):

View File

@ -3396,6 +3396,36 @@ def bœr():
self.assertRegex(res, "Restarting .* with arguments:\na b c")
self.assertRegex(res, "Restarting .* with arguments:\nd e f")
def test_issue58956(self):
# Set a breakpoint in a function that already exists on the call stack
# should enable the trace function for the frame.
script = """
import bar
def foo():
ret = bar.bar()
pass
foo()
"""
commands = """
b bar.bar
c
b main.py:5
c
p ret
quit
"""
bar = """
def bar():
return 42
"""
with open('bar.py', 'w') as f:
f.write(textwrap.dedent(bar))
self.addCleanup(os_helper.unlink, 'bar.py')
stdout, stderr = self.run_pdb_script(script, commands)
lines = stdout.splitlines()
self.assertIn('-> pass', lines)
self.assertIn('(Pdb) 42', lines)
def test_step_into_botframe(self):
# gh-125422
# pdb should not be able to step into the botframe (bdb.py)

View File

@ -0,0 +1 @@
Fixed a bug in :mod:`pdb` where sometimes the breakpoint won't trigger if it was set on a function which is already in the call stack.