From 37b3d294bc55443c946239a388d66f0badd3530b Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sun, 23 Feb 2025 20:35:39 -0500 Subject: [PATCH 1/6] Stop on calling frame unconditionally for inline breakpoints --- Lib/bdb.py | 9 ++++++--- Lib/test/test_pdb.py | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Lib/bdb.py b/Lib/bdb.py index a741628e32a981..5493961a9e5d54 100644 --- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -215,10 +215,13 @@ def dispatch_opcode(self, frame, arg): If the debugger stops on the current opcode, invoke self.user_opcode(). Raise BdbQuit if self.quitting is set. Return self.trace_dispatch to continue tracing in this scope. + + Opcode event will always trigger the user calback. For now the only + opcode event is from an inline set_trace() and we want to stop there + unconditionally. """ - if self.stop_here(frame) or self.break_here(frame): - self.user_opcode(frame) - if self.quitting: raise BdbQuit + self.user_opcode(frame) + if self.quitting: raise BdbQuit return self.trace_dispatch # Normally derived classes don't override the following diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 83753279599f76..ccfa5a729fa997 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4341,6 +4341,28 @@ def test_quit(self): # The quit prompt should be printed exactly twice self.assertEqual(stdout.count("Quit anyway"), 2) + def test_set_trace_with_skip(self): + """GH-82897 + Inline set_trace() should break unconditionally. This example is a + bit oversimplified, but as `pdb.set_trace()` uses the previous Pdb + instance, it's possible that we had a previous pdb instance with + skip values when we use `pdb.set_trace()` - it would be confusing + to users when such inline breakpoints won't break immediately. + """ + script = textwrap.dedent(""" + import pdb + def foo(): + x = 40 + 2 + pdb.Pdb(skip=['__main__']).set_trace() + foo() + """) + commands = """ + p x + c + """ + stdout, _ = self._run_script(script, commands) + self.assertIn("42", stdout) + @support.requires_subprocess() class PdbTestReadline(unittest.TestCase): From 6716ac02ad6f707e4b6ff791f3abdc655f5ae94e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 24 Feb 2025 01:49:14 +0000 Subject: [PATCH 2/6] =?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/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst diff --git a/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst b/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst new file mode 100644 index 00000000000000..bac343a8fba34b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst @@ -0,0 +1 @@ +:mod:`pdb` will always stop on calling frames when inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` are used, regardless of whether the module matches ``skip`` pattern. From c6947d15baac229e837bb64b1a4f8f3791cb2b45 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Mon, 24 Feb 2025 11:19:15 -0500 Subject: [PATCH 3/6] Update Lib/bdb.py Co-authored-by: Tomas R. --- Lib/bdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/bdb.py b/Lib/bdb.py index 5493961a9e5d54..2463cc217c6d75 100644 --- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -216,7 +216,7 @@ def dispatch_opcode(self, frame, arg): self.user_opcode(). Raise BdbQuit if self.quitting is set. Return self.trace_dispatch to continue tracing in this scope. - Opcode event will always trigger the user calback. For now the only + Opcode event will always trigger the user callback. For now the only opcode event is from an inline set_trace() and we want to stop there unconditionally. """ From e8c7d669747c10c5dd28d16921595845b4eb0f06 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Mon, 3 Mar 2025 17:37:31 -0500 Subject: [PATCH 4/6] Update Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- .../next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst b/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst index bac343a8fba34b..ee92843970d8ac 100644 --- a/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst +++ b/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst @@ -1 +1 @@ -:mod:`pdb` will always stop on calling frames when inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` are used, regardless of whether the module matches ``skip`` pattern. +:mod:`pdb` will always stop on calling frames when inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` are used, ignoring the ``skip`` pattern (if any). From 2cda74ce3ae831d824ba9aa3c9c583fb39340b81 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Mon, 3 Mar 2025 17:47:04 -0500 Subject: [PATCH 5/6] Add version change in pdb and add whatsnew entry --- Doc/library/pdb.rst | 3 +++ Doc/whatsnew/3.14.rst | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst index bdd89d127491a5..5411961594e0e1 100644 --- a/Doc/library/pdb.rst +++ b/Doc/library/pdb.rst @@ -245,6 +245,9 @@ access further features, you have to do this yourself: .. versionadded:: 3.14 Added the *mode* argument. + .. versionchanged:: 3.14 + *skip* will be ignored if inline breakpoints like :func:`breakpoint` or :func:`set_trace` are used. + .. method:: run(statement, globals=None, locals=None) runeval(expression, globals=None, locals=None) runcall(function, *args, **kwds) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 514c138c0ed061..84fd48fb741b9c 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -709,6 +709,11 @@ pdb the quit and call :func:`sys.exit`, instead of raising :exc:`bdb.BdbQuit`. (Contributed by Tian Gao in :gh:`124704`.) +* :mod:`pdb` will always stop on calling frames when inline breakpoints like + :func:`breakpoint` or :func:`pdb.set_trace` are used, ignoring the ``skip`` + pattern (if any). + (Contributed by Tian Gao in :gh:`130493`.) + pickle ------ From 418e7b1be6ca4b7db4b3c6ed56a9563f1a08a57d Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Mon, 3 Mar 2025 20:37:27 -0500 Subject: [PATCH 6/6] Update description --- Doc/library/pdb.rst | 3 ++- Doc/whatsnew/3.14.rst | 6 +++--- .../Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst index 5411961594e0e1..b31625e6b0082f 100644 --- a/Doc/library/pdb.rst +++ b/Doc/library/pdb.rst @@ -246,7 +246,8 @@ access further features, you have to do this yourself: Added the *mode* argument. .. versionchanged:: 3.14 - *skip* will be ignored if inline breakpoints like :func:`breakpoint` or :func:`set_trace` are used. + Inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` will + always stop the program at calling frame, ignoring the *skip* pattern (if any). .. method:: run(statement, globals=None, locals=None) runeval(expression, globals=None, locals=None) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 84fd48fb741b9c..5b02033ff0f724 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -709,9 +709,9 @@ pdb the quit and call :func:`sys.exit`, instead of raising :exc:`bdb.BdbQuit`. (Contributed by Tian Gao in :gh:`124704`.) -* :mod:`pdb` will always stop on calling frames when inline breakpoints like - :func:`breakpoint` or :func:`pdb.set_trace` are used, ignoring the ``skip`` - pattern (if any). +* Inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` will + always stop the program at calling frame, ignoring the ``skip`` pattern + (if any). (Contributed by Tian Gao in :gh:`130493`.) diff --git a/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst b/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst index ee92843970d8ac..0cfc7cf0cf7163 100644 --- a/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst +++ b/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst @@ -1 +1 @@ -:mod:`pdb` will always stop on calling frames when inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` are used, ignoring the ``skip`` pattern (if any). +Inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` will always stop the program at calling frame, ignoring the ``skip`` pattern (if any).