diff --git a/Lib/bdb.py b/Lib/bdb.py --- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -230,8 +230,8 @@ if frame is None: frame = sys._getframe().f_back self.reset() + frame.f_trace = self.trace_dispatch while frame: - frame.f_trace = self.trace_dispatch self.botframe = frame frame = frame.f_back self.set_step() @@ -273,6 +273,17 @@ list.append(lineno) bp = Breakpoint(filename, lineno, temporary, cond, funcname) + # set the trace function when the breakpoint is set in one of the + # frames of the frame stack + frame = self._curframe + while frame is not None: + if filename == frame.f_code.co_filename: + if not frame.f_trace: + frame.f_trace = self.trace_dispatch + if frame is self.botframe: + break + frame = frame.f_back + def _prune_breaks(self, filename, lineno): if (filename, lineno) not in Breakpoint.bplist: self.breaks[filename].remove(lineno) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -854,6 +854,35 @@ any('-> val = increment(100)' in l for l in stdout.splitlines()), 'Fail to stop into the selected frame after return') + def test_issueXXX(self): + script = """ + import bar + + def foo(): + bar.bar() + x = 1 + + foo() + """ + commands = """ + break bar.bar + continue + break main.py:6 + continue + quit + """ + bar = """ + def bar(): + pass + """ + with open('bar.py', 'w') as f: + f.write(textwrap.dedent(bar)) + self.safe_unlink('bar.py') + stdout, stderr = self.run_pdb(script, commands) + self.assertTrue( + any('-> x = 1' in l for l in stdout.splitlines()), + 'Fail to stop at a breakpoint set in the frame stack') + def tearDown(self): support.unlink(support.TESTFN)