From a7e07e5aea7965e8eb04ad7e242f85ae1787b629 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Tue, 24 Sep 2024 11:07:14 -0700 Subject: [PATCH 1/4] Set f_trace on frames with breakpoints after setting a new breakpoint --- Lib/bdb.py | 8 ++++++++ Lib/test/test_pdb.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/Lib/bdb.py b/Lib/bdb.py index d7543017940d4f..42f9fd2a98eeff 100644 --- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -439,6 +439,14 @@ def set_break(self, filename, lineno, temporary=False, cond=None, 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): diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index db7d1b1e9cd935..99a1e18a9e09d5 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3276,6 +3276,36 @@ def test_issue26053(self): 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_pdbrc_basic(self): script = textwrap.dedent(""" a = 1 From bd72ec978629d3221c30074e5b5f1e74ec20c32c Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 18:17:04 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst diff --git a/Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst b/Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst new file mode 100644 index 00000000000000..7d28f9eab09279 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst @@ -0,0 +1 @@ +Setting a :mod:`pdb` breakpoint on a function that's already in the call stack will enable the trace function on that frame so the breakpoint would trigger. From 5a32d943d3348bd75799d6b5facecaacf7a534fa Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Tue, 15 Oct 2024 10:58:33 -0400 Subject: [PATCH 3/4] Update 2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst --- .../next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst b/Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst index 7d28f9eab09279..190122831d2051 100644 --- a/Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst +++ b/Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst @@ -1 +1 @@ -Setting a :mod:`pdb` breakpoint on a function that's already in the call stack will enable the trace function on that frame so the breakpoint would trigger. +Fixed a bug in :mod:`pdb` where sometimes the breakpoint won't trigger if it was set on a function in the call stack already. From 0cb7fe7b7b787ff19cb23991cadcc5f05381a123 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Tue, 15 Oct 2024 11:04:30 -0400 Subject: [PATCH 4/4] Update Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- .../next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst b/Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst index 190122831d2051..a882a632fddf1b 100644 --- a/Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst +++ b/Misc/NEWS.d/next/Library/2024-09-24-18-16-59.gh-issue-58956.0wFrBR.rst @@ -1 +1 @@ -Fixed a bug in :mod:`pdb` where sometimes the breakpoint won't trigger if it was set on a function in the call stack already. +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.