Skip to content

Commit e696ca7

Browse files
gaogaotiantianmiss-islington
authored andcommitted
gh-58956: Set f_trace on frames with breakpoints after setting a new breakpoint (GH-124454)
(cherry picked from commit 12eaadc) Co-authored-by: Tian Gao <[email protected]>
1 parent 90b1406 commit e696ca7

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
@@ -394,6 +394,14 @@ def set_break(self, filename, lineno, temporary=False, cond=None,
394394
return 'Line %s:%d does not exist' % (filename, lineno)
395395
self._add_to_breaks(filename, lineno)
396396
bp = Breakpoint(filename, lineno, temporary, cond, funcname)
397+
# After we set a new breakpoint, we need to search through all frames
398+
# and set f_trace to trace_dispatch if there could be a breakpoint in
399+
# that frame.
400+
frame = self.enterframe
401+
while frame:
402+
if self.break_anywhere(frame):
403+
frame.f_trace = self.trace_dispatch
404+
frame = frame.f_back
397405
return None
398406

399407
def _load_breaks(self):

Lib/test/test_pdb.py

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

2286+
def test_issue58956(self):
2287+
# Set a breakpoint in a function that already exists on the call stack
2288+
# should enable the trace function for the frame.
2289+
script = """
2290+
import bar
2291+
def foo():
2292+
ret = bar.bar()
2293+
pass
2294+
foo()
2295+
"""
2296+
commands = """
2297+
b bar.bar
2298+
c
2299+
b main.py:5
2300+
c
2301+
p ret
2302+
quit
2303+
"""
2304+
bar = """
2305+
def bar():
2306+
return 42
2307+
"""
2308+
with open('bar.py', 'w') as f:
2309+
f.write(textwrap.dedent(bar))
2310+
self.addCleanup(os_helper.unlink, 'bar.py')
2311+
stdout, stderr = self.run_pdb_script(script, commands)
2312+
lines = stdout.splitlines()
2313+
self.assertIn('-> pass', lines)
2314+
self.assertIn('(Pdb) 42', lines)
2315+
22862316
def test_step_into_botframe(self):
22872317
# gh-125422
22882318
# 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)