summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2024-10-15 14:51:37 (GMT)
committerGitHub <noreply@github.com>2024-10-15 14:51:37 (GMT)
commit703227dd021491ceb9343f69fa48f4b6a05adbb3 (patch)
tree2e68e677552b09c6a997e0377d24bb30ec948efb
parentd3c82b9ccedd77fc302f5ab8ab0220b3372f574c (diff)
downloadcpython-703227dd021491ceb9343f69fa48f4b6a05adbb3.zip
cpython-703227dd021491ceb9343f69fa48f4b6a05adbb3.tar.gz
cpython-703227dd021491ceb9343f69fa48f4b6a05adbb3.tar.bz2
gh-125422: Don't set the caller's f_trace if it's botframe (#125427)
-rw-r--r--Lib/bdb.py5
-rw-r--r--Lib/test/test_bdb.py13
-rw-r--r--Lib/test/test_pdb.py14
-rw-r--r--Misc/NEWS.d/next/Library/2024-10-14-04-44-12.gh-issue-125422.MlVuC6.rst1
4 files changed, 31 insertions, 2 deletions
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 666f971..9755d61 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -350,9 +350,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
diff --git a/Lib/test/test_bdb.py b/Lib/test/test_bdb.py
index 10c58c0..f15dae1 100644
--- a/Lib/test/test_bdb.py
+++ b/Lib/test/test_bdb.py
@@ -1217,6 +1217,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):
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 46eb002..3dc65fd 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -3393,6 +3393,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
index 0000000..c890ece
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-10-14-04-44-12.gh-issue-125422.MlVuC6.rst
@@ -0,0 +1 @@
+Fixed the bug where :mod:`pdb` and :mod:`bdb` can step into the bottom caller frame.