Skip to content

gh-125422: Don't set the caller's f_trace if it's botframe #125427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Lib/bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,10 @@ def _set_caller_tracefunc(self, current_frame):
# 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
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,19 @@ def main():
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):
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,20 @@ def test_issue26053(self):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the bug where :mod:`pdb` and :mod:`bdb` can step into the bottom caller frame.
Loading