Troubleshooting entries rewritten as FIXED with the fixing commits: backende6678e1(Step Out in main, Stop/async, Run target switch, temp main bp) and UIa3df7cd(narrow pane incl. the wrapping hint root cause, sticky selection/checkbox, search popup). Run table row updated (Target/Args read every time), stale-breakpoints note updated (kept staged), First-run quirk callout removed, Known bugs section rewritten as all fixed.
27 KiB
Step debugger — a guided walkthrough
LightGUI has a built-in stepping debugger: a GDB/MI front end that runs your
program under gdb, stops at breakpoints, and lets you step through it line
by line while watching variables change. This guide walks through a real
debug session, click by click, with screenshots taken from the actual GUI
running under Xvfb. Every screenshot below shows the real debugger in the
state described — no mockups.
Related docs: docs/ide.md §5 (debugger reference),
DESIGN.md (debugger design notes). The debugger itself lives in
src/debugger.cpp, src/debugger_ui.cpp, and the paused-line / breakpoint
wiring in the code window is in src/codeview.cpp.
What you need before you start
- A program built with debug info: compile with
-g(and-O0while you are learning — optimisation reorders lines and hides variables). Without-g, gdb has no line numbers and breakpoints will not resolve. gdbinstalled (/usr/bin/gdbis the default; see Settings to change it).
The sample programs used here
Two targets are used in this guide, so you can follow along exactly.
1. tests/debugger/console.cpp — a console program with a loop
A small program in the repo, already written for this. Compile it with:
g++ -g -O0 -o /tmp/console tests/debugger/console.cpp
(The paths in the screenshots below say /tmp/dbg-guide/work/console
because that is where the guide author's copy lived; the program is the
same.)
| Line | Code | What happens |
|---|---|---|
| 8 | int r = v * 2 + 1; in helper() |
helper(0) → 1, helper(1) → 3, helper(2) → 5 |
| 13 | int s = a + b; in compute() |
compute(10, 20) → s = 30 |
| 18 | int main(int argc, char** argv) { |
program entry |
| 23 | int x = helper(i); |
loop body, runs for i = 0, 1, 2 |
| 24 | sum += x; |
sum goes 0 → 1 → 4 → 9 |
| 25 | std::printf("i=%d x=%d sum=%d\n", i, x, sum); |
prints each iteration |
| 28 | int total = compute(10, 20); |
total = 61 |
| 29 | std::printf("TOTAL total=%d sum=%d\n", total, sum); |
prints TOTAL total=61 sum=9 |
| 30 | std::printf("DONE sum=%d\n", sum); |
prints DONE sum=9 |
Expected run, with no breakpoints: i=0 x=1 sum=1, i=1 x=3 sum=4,
i=2 x=5 sum=9, TOTAL total=61 sum=9, DONE sum=9.
2. A generated project — three widgets, built and debugged
Later in this guide (§15) the same
debugger is used on a real generated LightGUI project: a window with
Button_001, Label_001 and Entry_001, generated to a folder, built with
make CXXFLAGS="-g -O0 -Wall -std=c++17" and debugged as app.
1. Open the debugger
- In the designer, click Debug in the menu bar.
- Click Open Debugger….
The debugger window opens. It starts idle:
The window has, top to bottom: a toolbar (Run, Continue, Step Over, Step Into, Step Out, Stop, Restart, Settings), a Target: row (executable path, Browse…, and an Args: field for command-line arguments), a status line, a Breakpoints pane on the left, and Locals, a watch row, Stack and Target output (stdout/stderr) on the right.
2. (Optional) Turn on "Break on main"
- In the debugger, click Settings (or Debug ▸ Debugger Settings…).
- Tick Break on main (stop at main()).
- Click Save (or press
Alt+S).
With this on, every Run stops at the first line of main() before any
of your code executes — a handy place to set further breakpoints. The other
options: Stop on entry (stop before main, at program entry),
Pretty-print values (nicer STL containers and structs), Refresh
locals on every stop. Settings are saved to
~/.config/lightgui/debugger.conf and apply to the next debug session
(pretty-print and the break-on-main / stop-on-entry options take effect on
Run).
3. Enter the target and press Run
- Click in the Target: field and type the path to your executable,
e.g.
/tmp/console. - Leave Args: empty (or type arguments here — they are passed to the program).
- Click Run.
Because "Break on main" is on, the program stops at the first line of
main():
The status line reads Stopped (breakpoint-hit) — main at …/console.cpp:18, the Locals pane shows argc = 1 and argv, and the
breakpoint list shows breakpoint #3 main with Hits = 1. (Ignore the
Running… status if you catch it in the first instant after pressing Run —
the status lags the stop event by one poll; see
Troubleshooting.)
4. Set a breakpoint by typing a location
- Click in the breakpoint entry (placeholder
file.cpp:123 or function). - Type
console.cpp:23— the loop lineint x = helper(i);. - Click Add BP.
The list now shows the breakpoint, resolved to its full path:
A relative location like console.cpp:23 is resolved against the
designer's working directory (here /opt/lightgui). You can also type a
function name, e.g. main or helper, instead of file:line. The
Enabled checkbox toggles a breakpoint without deleting it, and Hits
counts how many times it has fired.
5. Set a breakpoint by clicking in the gutter
You don't have to type locations — the code window has a gutter:
- Raise the LightGUI — Code window (the debugger loads the stopped file there automatically when the target stops).
- Click in the gutter, just right of the line number, on the line you
want — here line 24 (
sum += x;). A red dot appears in the gutter.
The shot below was taken paused at the line-23 breakpoint. Line 23 is highlighted solid red with a white ▶ in the gutter (the paused line), and line 24 carries the red dot you just clicked:
Below the code is the Variables in scope — automatic inspection pane:
the scope line reads main() — /opt/lightgui/tests/debugger/console.cpp:23 (breakpoint-hit) and the locals of the current frame are listed — x = 0,
i = 0, argc = 1, argv, sum = 0. It refreshes on every stop. While
the target is running it says Running — variables will appear when the target stops, and with no target it says No target running — start the debugger to inspect variables.
Gutter clicks also work while the debugger is running: a breakpoint added that way is inserted into the live gdb session immediately. (Clicking at the very left edge of the gutter, x < 18, toggles code folding instead — click a little further right, on the line number's right side.)
6. Step Into — follow a call into helper()
The target is stopped at line 23, int x = helper(i);.
- In the debugger, click Step Into (or press
F11).
The status is now Stopped (end-stepping-range) — helper at …/console.cpp:8. The Locals pane switched to helper()'s frame:
v = 0 (the argument) and r = 32767 — r is uninitialised garbage,
because line 8 hasn't executed yet. The Stack pane shows frame 0
helper over frame 1 main, so you can see how you got here.
Note the watch row at the bottom of this shot: the watch sum + 1 added
earlier now reads <error: No symbol "sum" in current context.> — watches
are evaluated in the current frame, and sum is a local of main(),
not of helper(). That error is expected here, not a bug.
7. Step Out — return to the caller
Still stopped inside helper() at line 8:
- Click Step Out.
Status: Stopped (function-finished) — main at …/console.cpp:23. You are
back in main(), still on line 23 — x is still 0 because the return
value hasn't been stored yet. The watch reads sum + 1 = 1 again, now
that sum is in scope.
8. Step Over — run a line without following its calls
From line 23, press Step Over (F10) twice:
- First
F10: executeshelper(i)as one step, stops at line 24 (sum += x;) withx = 1. - Second
F10: executessum += x;, stops at line 25.
The breakpoint list shows both breakpoints with Hits = 1, the locals
show x = 1, i = 0, and the watch sum + 1 now reads 2 — sum is 1
after the first loop iteration. Stepping over is the everyday key: F10
to walk a loop, F11 only when you want to look inside a call.
9. Continue — run until the next breakpoint
- Click Continue (or press
F5).
The target runs freely until it hits a breakpoint (or exits). Each time it
stops, the status line, Locals, Stack and the code window's paused line all
update together. Press F5 again to carry on. When the program finishes,
the output pane shows its exit, e.g. [Inferior 1 (process …) exited normally], and the status returns to idle-ish Exited.
10. Watches — evaluate an expression at every stop
- Click in the watch entry (placeholder
watch expression, e.g. sum + 1). - Type an expression, e.g.
sum + 1. - Click Add Watch.
The watch is re-evaluated at every stop and shown under the entry with its
current value. Any gdb expression works — vals.size(), x * 2, a
variable name on its own. As §6 showed, a watch that names a variable
outside the current frame shows an error instead of a value; that is gdb
telling you the name isn't visible there, not a broken watch. Click a
watch row and Remove to delete it.
Focus quirk: clicks in the watch row can land on the watch list instead of the entry, and typing then opens GTK's interactive-search popup instead of filling the expression. If your text doesn't appear in the entry, click directly inside the entry field (its centre is a little higher than the row looks) and try again. See Troubleshooting.
11. Conditional breakpoints — stop only when it matters
Loop breakpoints fire on every iteration; a condition stops only on the one you care about.
- Click Add… (next to Add BP).
- In the dialog, type the Location:
console.cpp:24. - Click the Type: combo and pick Conditional.
- In Condition: type
i == 2. - Leave Ignore first N hits: at 0.
- Click Save (or press
Alt+S).
The dialog's hint text spells out the rules: a conditional stops only
when the condition is true; a logpoint prints and never stops. Now press
Continue (F5): the program sails past i = 0 and i = 1 and stops
only at the third iteration:
The breakpoint list shows #4 console.cpp:24, type conditional,
condition i == 2, Hits = 1, and the locals confirm i = 2, x = 5.
Ignore first N hits is the same idea counted instead of tested: set
it to 2 and the breakpoint skips its first two hits, then stops normally.
12. Logpoints — print without stopping
A logpoint prints a message every time its line is reached and never
stops the program — printf debugging without editing your code.
- Click Add….
- Location:
console.cpp:28(thecompute(10, 20)call). - Type: Logpoint.
- Log message:
LOG calling compute, sum={sum}. - Click Save.
{expr} prints as an integer, {s:name} as a string, {f:x} as a
float, {x:v} as hex. Press Continue: the program runs to the end
without stopping at line 28, and the message appears in the Target
output pane as [gdb] text, interleaved with the program's own output:
i=2 x=5 sum=9
TOTAL total=61 sum=9
DONE sum=9
[gdb] LOG calling compute, sum=9
[Inferior 1 (process 696825) exited normally]
Your turn — the case of the unexpected 61
You have done every move in this guide now. Here is one to solve yourself, with no new buttons to learn.
Run the console program with no breakpoints and look at the last lines:
TOTAL total=61 sum=9
compute(10, 20) — ten plus twenty — should be 30. Where did 61
come from? Don't guess; make the debugger tell you:
- Set a breakpoint at
console.cpp:28(thecompute(10, 20)call) and press Continue (F5). - When it stops, press Step Into (
F11). You are insidecompute()at line 13:s= 30, as expected. - Press Step Over (
F10) once to reach line 14, then Step Into again. Now you are insidehelper()withv= 30. - Press Step Over: line 8 runs,
r= 61. There it is. - Step Out twice and you are back in
main()at line 29 withtotal= 61.
compute() doesn't just add — it passes the sum through helper(),
which doubles it and adds one: 30 × 2 + 1 = 61. The program is
correct as written; your assumption was the bug. If 30 is what you
actually wanted, the fix is one line — return s; in compute() —
but the debugger's job was to show you what the code does, not
what you assumed it does. That is the whole skill: stop arguing with
the program in your head and watch it run.
13. Stop and Restart
- Stop interrupts a running target (breaks into the debugger wherever it happens to be). Press it again to kill the target outright.
- Restart kills the target and runs it again from the start — with
"Break on main" on, it stops at
main()again. This is the reliable way to re-run after a change, and the way out when Stop can't interrupt a target stuck in a GUI event loop (see Troubleshooting).
14. Editing breakpoints
- Enabled checkbox in the list: untick to disable a breakpoint without deleting it; tick to re-enable. (The click needs a firm press — a quick click sometimes doesn't register; see Troubleshooting.)
- Edit…: opens the same dialog as Add…, with the breakpoint's type, condition, ignore-count and log message editable. The Location field is not editable when editing.
- Remove: deletes the selected breakpoint.
- Group: an optional label in the Add/Edit dialog, for grouping related breakpoints.
Known quirk: the breakpoint list is rebuilt every 150 ms by the debugger's poll, which clears the list selection — so a row click often doesn't "stick" and Edit… / Remove then do nothing. Add… (create) always works; for a conditional or logpoint, create it with Add… rather than editing an existing row. See Troubleshooting.
15. Debugging a generated project
The same debugger works on anything you generate — this is the real use case. Build a tiny project and debug it end to end:
-
In the designer, place a few widgets from the Widgets palette onto the canvas — here
Button_001,Label_001andEntry_001. The status bar confirms each one:Entry_001 placed — 3 widget(s) on canvas. -
File ▸ Generate C++/GTK…, pick a folder in the chooser (press
Ctrl+Lto type a path), and click Generate. -
LightGUI lists the generated files — 11 in this case (
MyWindow.h/.cpp, one.h/.cpppair per widget,main.cpp,Makefile,CMakeLists.txt). -
Build it with debug info. This is the step people miss: the generated
MakefileusesCXXFLAGS ?= -O2 -Wall -std=c++17— no-g— and the generatedCMakeLists.txtdoesn't add-geither, so a plainmakeproduces a binary gdb can't map to source lines. Build with:cd <your-folder> make CXXFLAGS="-g -O0 -Wall -std=c++17"which produces
appwith debug info. -
Back in the debugger, put the path to
appin Target: and click Run. With "Break on main" on it stops atmain.cpp:6(int main(int argc, char** argv) {). -
Click Continue (
F5). The generated window appears — a real GTK window, running under the debugger:The window is 800×600, titled
Main Window, with your three widgets at the top left. It is a live program: click its button, type in the entry, and if you have a breakpoint in a widget handler the debugger will stop there. -
Stop interrupts it; Restart kills it and re-runs to
main()again (§13).
Debugging in the Rust and Python designers
This guide covers the C designer — that is the one with a working debugger today. The other two are at different stages:
- Rust: the debugger (
crates/lightgui-debug, GDB/MI) is still in progress. The Debug menu entries exist but report that on the status bar instead of pretending to work. When it lands, the workflow will be the same as here — same GDB underneath. - Python: there is a working pdb-based step debugger in its own
window, with the same shape as this one: breakpoints (staged before
start, live after), Run / Continue / Step Over / Step Into / Step
Out, Stop, Restart, Settings (stop on entry, break on main), Locals,
Watches, call stack, a Hits column, and an output console. Two
differences to know: there is no logpoint UI (pdb has no
dprintfequivalent), and a breakpoint on adefline fires at definition time — pdb stops when thedefstatement executes, not when the function is later called — so use "Break on main" or a breakpoint on the first line inside the function to stop on entry.
Toolbar reference
| Button | Key | What it does |
|---|---|---|
| Run | — | Start the target under gdb. Reads the Target: entry (and Args:) every time: from Idle it starts it; from Stopped/Exited it re-runs the loaded executable when the entry is unchanged, or loads and runs the new target when the entry or args changed. |
| Continue | F5 |
Continue execution until the next breakpoint, or exit. |
| Step Over | F10 |
Step over the current line — run a function call as one step. |
| Step Into | F11 |
Step into the called function. |
| Step Out | — | Run until the current function returns. |
| Stop | — | Interrupt the running target; press again to kill it. |
| Restart | — | Kill and run the target again. |
| Settings | — | Debugger settings (gdb path, break on main, pretty-print…) — also under Debug ▸ Debugger. |
The Debug menu also has a Debugger submenu with toggles for Break on main, Stop on entry and Pretty-print values, and Debugger Settings… which opens the same dialog as the toolbar's Settings button.
Where settings and breakpoints are saved
Everything persists between LightGUI sessions, in
~/.config/lightgui/:
debugger.conf— settings: gdb path, default target args, break on main / stop on entry / pretty-print / refresh-locals flags, timeouts. Example after §2:gdb_path=/usr/bin/gdb, break_on_main=1, stop_on_entry=0, pretty_print=1, print_all_locals=1, default_args=, stop_timeout_ms=10000, cmd_timeout_ms=5000.debugger_bps.conf— one breakpoint per line:location|enabled|kind|condition|ignore|log_message|group. Example lines from this guide's session:console.cpp:24|1|conditional|i == 2|0||andconsole.cpp:28|1|logpoint||0|LOG calling compute, sum={sum}|. (kindisplain,conditionalorlogpoint;enabledis 1/0.)
Breakpoints are re-applied when the next session starts. Closing the debugger window does not destroy the session — the backend stays alive and keeps your breakpoints, which is why the same breakpoints are still there when you reopen it.
Troubleshooting
The breakpoint pane is too narrow.
FIXED Dec 2, 2026 (commit a3df7cd): the default divider moved from
380 px to 560 px, the breakpoint pane keeps a minimum width of 480 px
with a horizontal scrollbar, the Location column has a 140 px minimum
and expands, and all columns are resizable. The deeper cause was the
hint line under the list ("Breakpoints (toggle Enabled to
enable/disable; …)"): as one unwrapped line it was ~700 px wide, which
forced the whole pane's minimum width to ~734 px — wider than the
paned's 560 px slot — so GTK right-aligned the overflowing pane and the
# and Location columns ended up off-screen left. The hint now wraps
to two lines, the pane fits its 560 px slot exactly, and the list opens
with # and Location fully visible (the remaining columns scroll).
Before the fix the location entry was squeezed to ~50 px and the list
showed only the Ignore/Message columns:
The status says "Running…" but the program already stopped.
The status is polled every 150 ms, so it can show Running… for a beat
after the stop event. Wait a moment; the status line, locals and code
window catch up together.
The debugger stops responding to clicks.
Look for a modal error dialog centred on the debugger window — modal
dialogs block all input to the debugger until you dismiss them with
OK, and nothing else on screen hints they are there. If the debugger
seems dead, list the windows — an untitled dialog is the usual culprit.
(Step Out in main() used to produce such a dialog —
"finish" not meaningful in the outermost frame. — but that case is
FIXED Dec 2, 2026, commit e6678e1: pressing Step Out in
main() now writes Step Out: already in the outermost frame (main) — nothing to return to. Use Continue. in the status line instead.)
Stop doesn't interrupt a GUI app.
FIXED Dec 2, 2026 (commit e6678e1): the root cause was gdb
running in synchronous mode — while the target ran, gdb never read
-exec-interrupt from its stdin, so Stop timed out after 5 s with
"timed out waiting for gdb reply" and the app kept running. The
debugger now enables gdb's async mode at startup, and Stop falls
back to SIGINT and then SIGSTOP delivered straight to the target pid.
Stop now interrupts a GUI app sitting in gtk_main (or a busy loop) in
~0.1 s; press Stop again to kill it.
Run re-runs the old program after I changed the Target field.
FIXED Dec 2, 2026 (commit e6678e1): Run from Stopped or
Exited now compares the Target: and Args: entries with the
loaded target — unchanged means restart the loaded program, changed
means the old target is killed (through gdb, so it is reaped at once)
and the new one is loaded and run. Closing the debugger window doesn't
reset this — the session stays alive — but you no longer need to quit
LightGUI to switch targets.
Edit… / Remove do nothing, or the Enabled checkbox ignores a quick
click.
FIXED Dec 2, 2026 (commit a3df7cd): the lists are now rebuilt only
when their contents actually change (before, the 150 ms poll cleared
and rebuilt every list on every tick, wiping the row selection almost
as fast as you clicked it), and the selection is preserved across a
rebuild that does happen — so the row you clicked stays selected when
Edit… or Remove runs. The Enabled checkbox also flips in
the list immediately on click (optimistic update) instead of waiting
for the gdb round-trip.
Two identical "main" breakpoints.
FIXED Dec 2, 2026 (commit e6678e1): the break-on-main
breakpoint is now marked temporary — it lives only for the run and is
never written to debugger_bps.conf, and a second one is never added
when a main breakpoint already exists. Files that already contain two
main lines load deduplicated (the first is kept).
Breakpoints from an old target fail on the new one.
Breakpoints for locations the new target doesn't have are kept staged
(shown in the list with no gdb id) instead of being dropped, and are
re-applied automatically when you switch back to a target that has
them (gdb reports No source file named console.cpp. for locations
the current target doesn't have).
My watch text goes into a search popup, not the watch entry.
FIXED Dec 2, 2026 (commit a3df7cd): interactive search is disabled
on all debugger lists, so typing while a list has focus can no longer
open GTK's search popup instead of reaching the entry above the list.
Breakpoints don't resolve / locals are empty.
The target wasn't built with -g. Rebuild with -g -O0 (for a generated
project, make CXXFLAGS="-g -O0 -Wall -std=c++17" — the generated
Makefile/CMakeLists.txt don't add -g themselves) and run again.
Known bugs found while writing this guide — all fixed Dec 2, 2026
Found during the screenshot sessions. All eight were fixed Dec 2, 2026
and are covered by tests/debugger_tests.sh (backend) and the GUI
checks in that script:
- Breakpoint pane too narrow by default — fixed, commit
a3df7cd. - Breakpoint list selection doesn't stick — Edit… / Remove
usually do nothing (150 ms list rebuild clears the selection) —
fixed, commit
a3df7cd. - Step Out in
main()shows"finish" not meaningful in the outermost frame.as a modal error — fixed, commite6678e1: a status-line note instead, no modal. - Stop times out (
"timed out waiting for gdb reply") on a GUI app sitting ingtk_main— fixed, commite6678e1: gdb async mode + SIGINT/SIGSTOP fallbacks. - Run from Stopped/Exited ignores the Target: entry and re-runs
the loaded executable — fixed, commit
e6678e1: Run now loads the new target when the entry changed. - Break-on-main's temporary breakpoint is persisted, so a fresh session
can show two identical
mainbreakpoints — fixed, commite6678e1: the temp breakpoint is never saved. - Watch-entry clicks can land on the watch list and open GTK's
interactive-search popup instead of focusing the entry — fixed,
commit
a3df7cd: interactive search disabled on all lists. - Enabled-checkbox toggles sometimes ignore a quick click — fixed,
commit
a3df7cd: optimistic toggle + no rebuild while idle.













![Target output — program output plus the [gdb] logpoint line, then exit](/thinkmelt/lightgui/media/branch/monitor-apps-all/screenshots/debugger/18_logpoint_output.png)





