From ba3b1443836f2d1a4d0ff08d8b09ec6572fa5748 Mon Sep 17 00:00:00 2001 From: cnmcdee Date: Tue, 1 Dec 2026 03:35:16 +0000 Subject: [PATCH] Phase 5 follow-up: step-over lands in the caller; Hits column syncs - debugger.py step_over: pdb stops once more at the --Return-- event inside the finishing function, so one extra `next` lands in the caller (GDB `next` behaviour). A --Return-- stop at a breakpoint line is no longer misreported as a breakpoint hit. - debugger_ui.py: sync hit counts from pdb on every stop so the breakpoint pane's Hits column shows the real count. - tests: step over the last line of a function lands in the caller (new test_step_over_last_line_lands_in_caller). Full suite: 240 tests pass. --- lightgui/debugger.py | 16 +++++++++++++--- lightgui/debugger_ui.py | 3 +++ tests/test_debugger.py | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lightgui/debugger.py b/lightgui/debugger.py index cd35c83..3087b23 100644 --- a/lightgui/debugger.py +++ b/lightgui/debugger.py @@ -535,7 +535,10 @@ class PdbSession: frame = parsed break bp_id = 0 - if frame is not None: + if frame is not None and "--Return--" not in response: + # A --Return-- stop is reported at the returning + # function's last line, which may itself be a + # breakpoint line — that is a step stop, not a hit. for bp in self._breakpoints: if bp.id and bp.file == frame.file \ and bp.line == frame.line and bp.enabled: @@ -608,8 +611,15 @@ class PdbSession: return self._exec("step", timeout_s) def step_over(self, timeout_s=None): - """Step over the current line (pdb ``next``).""" - return self._exec("next", timeout_s) + """Step over the current line (pdb ``next``). Stepping over + the last line of a function stops at pdb's ``--Return--`` + event inside that function; one more step lands in the + caller, like GDB's ``next``.""" + if not self._exec("next", timeout_s): + return False + if "--Return--" in self._last_exec_response: + return self._exec("next", timeout_s) + return True def step_out(self, timeout_s=None): """Step out of the current function (pdb ``return``). At diff --git a/lightgui/debugger_ui.py b/lightgui/debugger_ui.py index e108ec0..649597b 100644 --- a/lightgui/debugger_ui.py +++ b/lightgui/debugger_ui.py @@ -677,6 +677,9 @@ class DebuggerWindow: self.on_status(text) def _after_state_change(self): + # Sync hit counts from pdb so the Hits column is accurate. + if self.session.state == STATE_STOPPED: + self.session.refresh_breakpoints() self._refresh_all() self._update_buttons() self._drain_output() diff --git a/tests/test_debugger.py b/tests/test_debugger.py index a28c8a9..0cb71ad 100644 --- a/tests/test_debugger.py +++ b/tests/test_debugger.py @@ -142,6 +142,23 @@ class SessionTests(unittest.TestCase): self.assertEqual(self.session.state, STATE_EXITED) self.assertIn("total 13", self.session.target_output()) + def test_step_over_last_line_lands_in_caller(self): + # Stepping over the last line of a function (return b) must + # land in the caller, not sit on the --Return-- event inside + # the function at a line that happens to hold a breakpoint. + self.assertTrue(self.session.start(self.script)) + self.session.add_breakpoint("%s:4" % self.script) + self.assertTrue(self.session.cont()) + self.assertEqual(self.session.last_stop.frame.line, 4) + self.assertTrue(self.session.step_over()) + self.assertEqual(self.session.last_stop.frame.line, 5) + self.assertTrue(self.session.step_over()) + self.assertEqual(self.session.last_stop.frame.function, + "") + self.assertEqual(self.session.last_stop.frame.line, 7) + self.assertEqual(self.session.last_stop.reason, + "end-stepping-range") + def test_locals_evaluation(self): self.assertTrue(self.session.start(self.script)) self.session.add_breakpoint("%s:7" % self.script)