Skip to content

Commit 2ded598

Browse files
[3.13] gh-58956: Set f_trace on frames with breakpoints after setting a new breakpoint (GH-124454) (#125548)
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 <gaogaotiantian@hotmail.com>
1 parent c5bad75 commit 2ded598

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

Lib/bdb.py

+8
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ def set_break(self, filename, lineno, temporary=False, cond=None,
439439
return 'Line %s:%d does not exist' % (filename, lineno)
440440
self._add_to_breaks(filename, lineno)
441441
bp = Breakpoint(filename, lineno, temporary, cond, funcname)
442+
# After we set a new breakpoint, we need to search through all frames
443+
# and set f_trace to trace_dispatch if there could be a breakpoint in
444+
# that frame.
445+
frame = self.enterframe
446+
while frame:
447+
if self.break_anywhere(frame):
448+
frame.f_trace = self.trace_dispatch
449+
frame = frame.f_back
442450
return None
443451

444452
def _load_breaks(self):

Lib/test/test_pdb.py

+30
Original file line numberDiff line numberDiff line change
@@ -3184,6 +3184,36 @@ def test_issue26053(self):
31843184
self.assertRegex(res, "Restarting .* with arguments:\na b c")
31853185
self.assertRegex(res, "Restarting .* with arguments:\nd e f")
31863186

3187+
def test_issue58956(self):
3188+
# Set a breakpoint in a function that already exists on the call stack
3189+
# should enable the trace function for the frame.
3190+
script = """
3191+
import bar
3192+
def foo():
3193+
ret = bar.bar()
3194+
pass
3195+
foo()
3196+
"""
3197+
commands = """
3198+
b bar.bar
3199+
c
3200+
b main.py:5
3201+
c
3202+
p ret
3203+
quit
3204+
"""
3205+
bar = """
3206+
def bar():
3207+
return 42
3208+
"""
3209+
with open('bar.py', 'w') as f:
3210+
f.write(textwrap.dedent(bar))
3211+
self.addCleanup(os_helper.unlink, 'bar.py')
3212+
stdout, stderr = self.run_pdb_script(script, commands)
3213+
lines = stdout.splitlines()
3214+
self.assertIn('-> pass', lines)
3215+
self.assertIn('(Pdb) 42', lines)
3216+
31873217
def test_step_into_botframe(self):
31883218
# gh-125422
31893219
# pdb should not be able to step into the botframe (bdb.py)
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)