debugger: Run honours the Target field; staged-row toggle/remove/edit hit the right row

Bug 5 (was still present): Run from Stopped re-ran the stored script
and ignored the Target/Args entries. _on_run() now compares the
entries with the loaded target and starts the new target when they
differ.

Bug 8, staged-row variant (found by reviewing the live screenshot):
staged breakpoints share id 0, so a checkbox toggle / Remove / Edit on
one staged row landed on the first staged breakpoint instead — the
store row flipped but the session flag went to the wrong bp, and the
next refresh showed the wrong row unchecked. Session lookups now
match by (id, location) via _find_bp(); the UI tracks the selected
row location and the refresh re-selects by (id, location).

Tests: test_run_from_stopped_uses_new_target,
test_staged_toggle_hits_the_right_row. Full suite 28/28 under Xvfb;
Stop on a Gtk.main() debuggee verified live (0.02s, reaped).
Docstrings in debugger.py/debugger_ui.py updated (they are the
debugger docs; architecture.md already points at them).
This commit is contained in:
cnmcdee committed 2026-12-02 10:03:04 +00:00
1 parent 11493b5f22
commit d0f430f88c
3 files changed
+140 -24

No files matched your search

+38 -11
View File
@@ -42,8 +42,10 @@ each of them (the UI half is in debugger_ui.py):
SIGTERM then SIGKILL to the whole process group, and the child
is always reaped.
5. Run from Stopped/Exited ignores Target — ``run()``/``restart()``
always restart with the *current* stored target and re-apply
every breakpoint; there is no stale-target path.
restart with the *stored* target by design; the UI
(debugger_ui.py) compares the Target/Args entries with the
stored ones and calls ``start()`` when they differ, so a changed
entry is honoured and there is no stale-target path.
6. break-on-main temp breakpoint persisted — there are no temp
breakpoints at all: ``stop_on_entry`` uses pdb's natural first
stop (no breakpoint is created), and ``break_on_main`` is a
@@ -51,7 +53,10 @@ each of them (the UI half is in debugger_ui.py):
7. Watch clicks open a search popup — the UI disables TreeView
search on the watch/locals trees and uses no SearchEntry.
8. Enabled-checkbox toggles ignored — the UI applies the toggle to
the session first, then updates the store row directly.
the session first, then updates the store row directly. Staged
rows share id 0, so the toggle/remove/edit look the row up by
(id, location), not id alone — otherwise the change lands on
the first staged breakpoint instead of the clicked row.
"""
import ast
@@ -745,11 +750,33 @@ class PdbSession:
return bp
return None
def remove_breakpoint(self, bp_id):
"""Remove breakpoint *bp_id* (live or staged). Returns False
def _find_bp(self, bp_id, location=None):
"""Breakpoint by pdb id. Staged breakpoints share id 0, so
when *location* is given an id-0 lookup also matches the
location — otherwise a toggle/remove/edit on one staged row
would hit the first staged breakpoint instead (bug 8's
staged-row variant: the store row flips, but the session
flag lands on the wrong breakpoint and a later refresh shows
the wrong row unchecked)."""
for bp in self._breakpoints:
if bp.id != bp_id:
continue
if bp_id == 0 and location is not None \
and bp.location != location:
continue
return bp
return None
def find_breakpoint_by_id(self, bp_id, location=None):
"""Public form of _find_bp (the UI looks rows up by the
(id, location) pair it shows)."""
return self._find_bp(bp_id, location)
def remove_breakpoint(self, bp_id, location=None):
"""Remove breakpoint *bp_id* (live or staged). *location*
disambiguates staged rows, which share id 0. Returns False
when the id is unknown."""
bp = next((b for b in self._breakpoints if b.id == bp_id),
None)
bp = self._find_bp(bp_id, location)
if bp is None:
# Staged breakpoints have id 0; match by object identity
# is handled by remove_staged_breakpoint().
@@ -798,12 +825,12 @@ class PdbSession:
lines.append(bp.line)
return sorted(lines)
def enable_breakpoint(self, bp_id, enable):
def enable_breakpoint(self, bp_id, enable, location=None):
"""Enable/disable breakpoint *bp_id*. Live: pdb
enable/disable; staged: the flag is stored and applied on
insert. Returns False when the id is unknown."""
bp = next((b for b in self._breakpoints if b.id == bp_id),
None)
insert. *location* disambiguates staged rows, which share
id 0 (see _find_bp). Returns False when the id is unknown."""
bp = self._find_bp(bp_id, location)
if bp is None:
if bp_id == 0:
return False
+45 -13
View File
@@ -27,8 +27,11 @@ debugger.py):
degrades to Continue at module level.
4. Stop times out on a GUI app — session.stop() kills the process
group; the Stop button just calls it.
5. Run from Stopped/Exited ignores Target — Run always restarts
with the current target entry / stored target.
5. Run from Stopped/Exited ignores Target — Run re-reads the Target
and Args entries on every press: if either changed since the
session started, it starts the new target (session.start);
otherwise it re-runs the stored one (session.run). There is no
stale-target path.
6. break-on-main temp breakpoint persisted — no temp breakpoints
exist (see debugger.py).
7. Watch clicks open a search popup — the watch and locals trees
@@ -37,7 +40,10 @@ debugger.py):
select it.
8. Enabled-checkbox toggles ignored — the toggle handler applies
the change to the session FIRST and then updates the store row
directly; the row is never rebuilt under it.
directly; the row is never rebuilt under it. Staged rows share
id 0, so the toggle/remove/edit look the row up by
(id, location), not id alone — otherwise the change lands on
the first staged breakpoint instead of the clicked row.
"""
import os
@@ -73,6 +79,7 @@ class DebuggerWindow:
# can scroll the Code window to the stopped line.
self.on_stop_location = on_stop_location
self._selected_bp_id = None
self._selected_bp_location = None
self._output_shown = 0
self._last_stop_seq = 0
self._poll_id = None
@@ -374,12 +381,23 @@ class DebuggerWindow:
self._status("Stopped at entry — %s"
% self._frame_text())
else:
# Bug 5: Run from Stopped/Exited restarts with the
# CURRENT target (session.run re-uses the stored one).
# Bug 5: Run from Stopped/Exited honours the CURRENT
# Target/Args entries, not just the stored target. If
# the user edited either field, start that target
# instead of re-running the loaded executable (the C
# bug: Run silently re-ran the old program).
target = self.get_target()
args = self.args_entry.get_text()
self._output_shown = 0
self.output_buffer.set_text("")
self.session.clear_output()
if not self.session.run():
if target and (os.path.abspath(target)
!= self.session.script_path
or args != self.session.args):
ok = self.session.start(target, args)
else:
ok = self.session.run()
if not ok:
self._status("Run failed: %s"
% self.session.last_error)
else:
@@ -503,8 +521,10 @@ class DebuggerWindow:
bp_id = self._selected_bp_id
if bp_id is None:
return
if self.session.remove_breakpoint(bp_id):
if self.session.remove_breakpoint(
bp_id, self._selected_bp_location):
self._selected_bp_id = None
self._selected_bp_location = None
else:
self._status("Cannot remove breakpoint: %s"
% self.session.last_error)
@@ -515,8 +535,8 @@ class DebuggerWindow:
bp_id = self._selected_bp_id
if bp_id is None:
return
bp = next((b for b in self.session.breakpoints()
if b.id == bp_id), None)
bp = self.session.find_breakpoint_by_id(
bp_id, self._selected_bp_location)
if bp is None:
return
dialog = Gtk.Dialog(title="Edit Breakpoint %d" % bp_id,
@@ -572,11 +592,15 @@ class DebuggerWindow:
def _on_bp_toggled(self, _renderer, path):
"""Bug 8: apply the toggle to the session FIRST, then update
the store row directly — never rebuild the model under the
click, so the toggle cannot be lost."""
click, so the toggle cannot be lost. The row's location is
passed too: staged rows share id 0, and without it the
toggle would land on the first staged breakpoint instead
of the clicked row."""
tree_iter = self.bp_store.get_iter(path)
bp_id = self.bp_store.get_value(tree_iter, 0)
location = self.bp_store.get_value(tree_iter, 2)
current = self.bp_store.get_value(tree_iter, 1)
if self.session.enable_breakpoint(bp_id, not current):
if self.session.enable_breakpoint(bp_id, not current, location):
self.bp_store.set_value(tree_iter, 1, not current)
else:
self._status("Cannot toggle breakpoint: %s"
@@ -586,8 +610,11 @@ class DebuggerWindow:
_model, tree_iter = selection.get_selected()
if tree_iter is None:
self._selected_bp_id = None
self._selected_bp_location = None
else:
self._selected_bp_id = self.bp_store.get_value(tree_iter, 0)
self._selected_bp_location = self.bp_store.get_value(
tree_iter, 2)
self._update_buttons()
def _refresh_breakpoints(self):
@@ -616,12 +643,17 @@ class DebuggerWindow:
self.bp_store.append(row)
for tree_iter in existing.values():
self.bp_store.remove(tree_iter)
# Restore the selection by id (bug 2).
# Restore the selection by (id, location) (bug 2) — by id
# alone a staged row would re-select the first staged row,
# since staged rows share id 0.
if self._selected_bp_id is not None:
tree_iter = self.bp_store.get_iter_first()
while tree_iter is not None:
if self.bp_store.get_value(tree_iter, 0) \
== self._selected_bp_id:
== self._selected_bp_id \
and (self._selected_bp_location is None
or self.bp_store.get_value(tree_iter, 2)
== self._selected_bp_location):
self.bp_tree.get_selection().select_iter(tree_iter)
break
tree_iter = self.bp_store.iter_next(tree_iter)
+57
View File
@@ -417,6 +417,63 @@ class DebuggerWindowTests(unittest.TestCase):
self.win.bp_store.get_value(selected, 2),
"%s:6" % self.script)
def test_run_from_stopped_uses_new_target(self):
# Bug 5: Run from Stopped must honour the Target entry, not
# silently re-run the stored script.
other = _write_script(self.tmp.name, "b.py", "print('B')\n")
self.win._on_run() # Idle -> start self.script
self.assertEqual(self.win.session.state, "stopped")
self.win.target_entry.set_text(other)
self.win._on_run()
self.assertEqual(self.win.session.script_path,
os.path.abspath(other))
# The new script actually runs: Continue past the entry stop
# prints B.
self.assertTrue(self.win.session.cont())
self.assertIn("B", self.win.session.target_output())
def test_staged_toggle_hits_the_right_row(self):
# Bug 8 (staged-row variant): staged breakpoints share id 0,
# so a toggle/remove must match by (id, location), not id
# alone — toggling the second row must not disable the first.
self.win.toggle_breakpoint(self.script, 6)
self.win.toggle_breakpoint(self.script, 7)
self.win._refresh_breakpoints()
path = None
tree_iter = self.win.bp_store.get_iter_first()
while tree_iter is not None:
if self.win.bp_store.get_value(tree_iter, 2) == \
"%s:7" % self.script:
path = self.win.bp_store.get_path(tree_iter)
break
tree_iter = self.win.bp_store.iter_next(tree_iter)
self.assertIsNotNone(path)
cell = self.win.bp_tree.get_columns()[0].get_cells()[0]
cell.emit("toggled", path.to_string())
by_loc = {b.location: b
for b in self.win.session.breakpoints()}
self.assertFalse(by_loc["%s:7" % self.script].enabled)
self.assertTrue(by_loc["%s:6" % self.script].enabled)
# The store rows agree with the session.
rows = {}
tree_iter = self.win.bp_store.get_iter_first()
while tree_iter is not None:
rows[self.win.bp_store.get_value(tree_iter, 2)] = \
self.win.bp_store.get_value(tree_iter, 1)
tree_iter = self.win.bp_store.iter_next(tree_iter)
self.assertFalse(rows["%s:7" % self.script])
self.assertTrue(rows["%s:6" % self.script])
# Remove must also hit the selected row, not the first
# staged one.
self.win.bp_tree.get_selection().select_iter(
self.win.bp_store.get_iter(path))
self.win._on_bp_remove()
self.assertEqual(len(self.win.bp_store), 1)
self.assertEqual(
self.win.bp_store.get_value(
self.win.bp_store.get_iter_first(), 2),
"%s:6" % self.script)
if __name__ == "__main__":
unittest.main()