]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-125422: Don't set the caller's f_trace if it's botframe (GH-125427) (#125531)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 15 Oct 2024 15:26:41 +0000 (17:26 +0200)
committerGitHub <noreply@github.com>
Tue, 15 Oct 2024 15:26:41 +0000 (15:26 +0000)
gh-125422: Don't set the caller's f_trace if it's botframe (GH-125427)
(cherry picked from commit 703227dd021491ceb9343f69fa48f4b6a05adbb3)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Lib/bdb.py
Lib/test/test_bdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2024-10-14-04-44-12.gh-issue-125422.MlVuC6.rst [new file with mode: 0644]

index 564d6c5e5324ed93ca2522ba5873e00ffe4dd1b1..196e6b178cb9fd3d88f489d1df7259df21ff8df8 100644 (file)
@@ -295,9 +295,10 @@ class Bdb:
         # Issue #13183: pdb skips frames after hitting a breakpoint and running
         # step commands.
         # Restore the trace function in the caller (that may not have been set
-        # for performance reasons) when returning from the current frame.
+        # for performance reasons) when returning from the current frame, unless
+        # the caller is the botframe.
         caller_frame = current_frame.f_back
-        if caller_frame and not caller_frame.f_trace:
+        if caller_frame and not caller_frame.f_trace and caller_frame is not self.botframe:
             caller_frame.f_trace = self.trace_dispatch
 
     # Derived classes and clients can call the following methods
index 568c88e326c0873b59447532fd25bb97a2a1bf69..33e28592f59e1b1d85957986c9ce5dd0f42b267d 100644 (file)
@@ -1203,6 +1203,19 @@ class IssuesTestCase(BaseTestCase):
             with TracerRun(self) as tracer:
                 tracer.runcall(tfunc_import)
 
+    def test_next_to_botframe(self):
+        # gh-125422
+        # Check that next command won't go to the bottom frame.
+        code = """
+            lno = 2
+        """
+        self.expect_set = [
+            ('line', 2, '<module>'),   ('step', ),
+            ('return', 2, '<module>'), ('next', ),
+        ]
+        with TracerRun(self) as tracer:
+            tracer.run(compile(textwrap.dedent(code), '<string>', 'exec'))
+
 
 class TestRegressions(unittest.TestCase):
     def test_format_stack_entry_no_lineno(self):
index 8a7e41b281165e14507eef6023f40add7e775743..6da82fe04c0eaadd8a8cb0c8e1f3c886a33587f3 100644 (file)
@@ -2283,6 +2283,20 @@ def bœr():
         self.assertRegex(res, "Restarting .* with arguments:\na b c")
         self.assertRegex(res, "Restarting .* with arguments:\nd e f")
 
+    def test_step_into_botframe(self):
+        # gh-125422
+        # pdb should not be able to step into the botframe (bdb.py)
+        script = "x = 1"
+        commands = """
+            step
+            step
+            step
+            quit
+        """
+        stdout, _ = self.run_pdb_script(script, commands)
+        self.assertIn("The program finished", stdout)
+        self.assertNotIn("bdb.py", stdout)
+
     def test_pdbrc_basic(self):
         script = textwrap.dedent("""
             a = 1
diff --git a/Misc/NEWS.d/next/Library/2024-10-14-04-44-12.gh-issue-125422.MlVuC6.rst b/Misc/NEWS.d/next/Library/2024-10-14-04-44-12.gh-issue-125422.MlVuC6.rst
new file mode 100644 (file)
index 0000000..c890ece
--- /dev/null
@@ -0,0 +1 @@
+Fixed the bug where :mod:`pdb` and :mod:`bdb` can step into the bottom caller frame.