Skip to content

Commit 12eaadc

Browse files
gh-58956: Set f_trace on frames with breakpoints after setting a new breakpoint (#124454)
1 parent 9c2bb7d commit 12eaadc

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

Lib/bdb.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,14 @@ def set_break(self, filename, lineno, temporary=False, cond=None,
461461
return 'Line %s:%d does not exist' % (filename, lineno)
462462
self._add_to_breaks(filename, lineno)
463463
bp = Breakpoint(filename, lineno, temporary, cond, funcname)
464+
# After we set a new breakpoint, we need to search through all frames
465+
# and set f_trace to trace_dispatch if there could be a breakpoint in
466+
# that frame.
467+
frame = self.enterframe
468+
while frame:
469+
if self.break_anywhere(frame):
470+
frame.f_trace = self.trace_dispatch
471+
frame = frame.f_back
464472
return None
465473

466474
def _load_breaks(self):

Lib/test/test_pdb.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,6 +3396,36 @@ def test_issue26053(self):
33963396
self.assertRegex(res, "Restarting .* with arguments:\na b c")
33973397
self.assertRegex(res, "Restarting .* with arguments:\nd e f")
33983398

3399+
def test_issue58956(self):
3400+
# Set a breakpoint in a function that already exists on the call stack
3401+
# should enable the trace function for the frame.
3402+
script = """
3403+
import bar
3404+
def foo():
3405+
ret = bar.bar()
3406+
pass
3407+
foo()
3408+
"""
3409+
commands = """
3410+
b bar.bar
3411+
c
3412+
b main.py:5
3413+
c
3414+
p ret
3415+
quit
3416+
"""
3417+
bar = """
3418+
def bar():
3419+
return 42
3420+
"""
3421+
with open('bar.py', 'w') as f:
3422+
f.write(textwrap.dedent(bar))
3423+
self.addCleanup(os_helper.unlink, 'bar.py')
3424+
stdout, stderr = self.run_pdb_script(script, commands)
3425+
lines = stdout.splitlines()
3426+
self.assertIn('-> pass', lines)
3427+
self.assertIn('(Pdb) 42', lines)
3428+
33993429
def test_step_into_botframe(self):
34003430
# gh-125422
34013431
# pdb should not be able to step into the botframe (bdb.py)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

0 commit comments

Comments
 (0)