STOP GUESSING WHAT YOUR PROGRAM DOES?! Step Through Your Generated C++ Line by Line With LightGUI's Built-In GDB Debugger!
A hands-on walkthrough of LightGUI's built-in GDB debugger: set breakpoints, step into functions, watch variables change, and find out why compute(10, 20) returns 61 — plus the 8 known bugs found while writing it, all fixed Dec 2, 2026.
You generated a C++ app from the designer, it runs, and the numbers coming out are wrong. Now what? This guide walks you through LightGUI's built-in GDB debugger click by click — breakpoints, stepping, watches, conditional breakpoints, logpoints — on a real program, with a screenshot of every step taken from the actual debugger. Work through it once and you'll never go back to sprinkling printf through your code.
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.
Fixed Dec 2, 2026 (commita3df7cd): the breakpoint pane used to open squeezed narrow — the location entry only ~50 px wide, the list showing just theIgnore/Messagecolumns. The hint line now wraps and the pane opens at 560 px, so the full entry and all eight columns are visible from the start. The old squeezed layout is kept as a screenshot in Troubleshooting.
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.
Fixed Dec 2, 2026 (commit a3df7cd): clicks in the watch row used to land on the watch list instead of the entry, and typing then opened GTK's interactive-search popup instead of filling the expression. Interactive search is now disabled on all lists, so clicks in the watch row focus the entry. 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:
![Target output — program output plus the [gdb] logpoint line, then exit](https://www.lightgui.com/content/images/2026/12/18_logpoint_output.png)
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. (Stop used to time out on a target stuck in a GUI event loop; fixed Dec 2, 2026 — Stop now interrupts in ~2 s. See Troubleshooting.)

14. Editing breakpoints
- Enabled checkbox in the list: untick to disable a breakpoint without deleting it; tick to re-enable. (Fixed Dec 2, 2026: a quick click used to be ignored sometimes; the checkbox now flips optimistically. 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.
Fixed Dec 2, 2026 (commitse6678e1+a3df7cd): the breakpoint list used to be rebuilt every 150 ms by the debugger's poll, which cleared the list selection — so a row click often didn't "stick" and Edit… / Remove then did nothing. Rebuilds are now fingerprint-gated and the selection is preserved, so Edit… / Remove work on the selected 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:
sh cd <your-folder> make CXXFLAGS="-g -O0 -Wall -std=c++17"
which produces app with 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. 7. 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. Four backend fixes landed Dec 2, 2026 in commita1645d3— Step Out degrades to Continue, Stop via async MI plus a 3-stage interrupt, Run honours Target, and the break-on-main temporary breakpoint no longer duplicates — but there is still no debugger UI to use them from, so the other four bugs from this guide don't apply there yet. - 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 more fixes landed Dec 2, 2026 in commit
d0f430f: Run now honours the Target field, and a staged-row checkbox bug — toggling one row flipped another breakpoint's flag — is fixed (28/28 tests pass). Two differences to know: there is no logpoint UI (pdb has nodprintfequivalent), 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. From Idle it reads the Target: entry; from Stopped/Exited it kills the loaded target and starts the one in the Target: entry (fixed Dec 2, 2026, commit e6678e1 — it used to re-run the loaded executable and ignore the entry). |
| 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
Update, Dec 2, 2026: all eight bugs found while writing this guide are fixed in the C designer — verified live under Xvfb (console tests 42/42, GTK tests 8/8, GUI smoke pass), commits e6678e1 (backend) and a3df7cd (UI) in cnmcdee/lightgui, repo guide updated in 3792410. The Rust designer fixed four of them in a1645d3 (the other four don't apply — there is no debugger UI in Rust yet); the Python designer fixed two in d0f430f (the other six were already handled there). The entries below are kept as a record of what each bug was and what the fix changed. Nothing is outstanding in C — if you hit one of these on a current build, you are on an older one.
The breakpoint pane is too narrow. — FIXED. At the default divider position the location entry used to be squeezed to ~50 px and the list showed only the Ignore/Message columns, with no visible horizontal scrollbar:

Fixed in a3df7cd: the hint line that forced the 734 px minimum width now wraps, and the pane opens at 560 px — the full entry and all eight columns (#, Location, Enabled, Hits, Type, Condition, Ignore, Message) are visible from the start, no divider-dragging needed. The screenshot above shows the old layout.
The status says "Running…" but the program already stopped. Not a bug — 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. — FIXED. Pressing Step Out while stopped in main() used to fire gdb's finish in the outermost frame, which answered "finish" not meaningful in the outermost frame. as a modal error dialog — and modal dialogs block all input to the debugger until dismissed with OK, with nothing else on screen hinting one is there. Fixed in e6678e1: a can_step_out() guard checks first, and instead of a modal you get a sticky note in the status line. If the debugger ever seems dead on a current build, a modal dialog from somewhere else is still the first thing to check — list the windows for an untitled dialog.
Stop doesn't interrupt a GUI app. — FIXED. Pressing Stop while a generated app sat in gtk_main used to fail with "timed out waiting for gdb reply" (5 s timeout) and the app kept running; the only way out was Restart, which SIGKILLs the target and re-runs it. Fixed in e6678e1: MI async mode is on and Stop falls back through SIGINT/SIGSTOP, so it now interrupts in ~2 s. Restart still works the same way if you want a clean re-run.
Run re-runs the old program after I changed the Target field. — FIXED. Run from Stopped or Exited used to re-run the executable already loaded; only a fresh (Idle) session read the Target: entry, and closing the debugger window didn't reset this — the session stays alive — so the only way to debug a different target was to quit LightGUI and start again. Fixed in e6678e1: restart_or_start() kills the old target with gdb kill and starts the one in the Target: entry. Also fixed in Rust (a1645d3) and Python (d0f430f).
Edit… / Remove do nothing. — FIXED. The list used to be rebuilt every 150 ms by the debugger's poll, which wiped the row selection almost as fast as you clicked it, so usually no row was selected when Edit… or Remove ran and they silently returned. Fixed in e6678e1 + a3df7cd: rebuilds are now fingerprint-gated (the list is only rebuilt when its contents actually changed) and the selection is preserved across rebuilds, so Edit… / Remove act on the row you clicked.
Two identical "main" breakpoints. — FIXED. The break-on-main temporary breakpoint used to be written into debugger_bps.conf and re-applied on the next start, so a fresh session could show two main rows (one with hits, one without). Fixed in e6678e1: the temporary breakpoint carries a temporary flag, is skipped on save, and is deduped on load — one main row, always. Also fixed in Rust (a1645d3).
Breakpoints from an old target fail on the new one. Unchanged behaviour, not one of the eight bugs: stale breakpoints are dropped best-effort when a session starts (gdb reports No source file named console.cpp. for locations the new target doesn't have). They are not kept pending — re-add the ones you need.
My watch text goes into a search popup, not the watch entry. — FIXED. Clicks in the watch row used to focus the watch list instead of the entry; typing then opened GTK's interactive-search popup. Fixed in a3df7cd: interactive search is disabled on all lists, so the entry gets the keystrokes.
Enabled-checkbox toggles sometimes ignore a quick click. — FIXED. Same root cause as the selection bug above — the 150 ms rebuild could swallow the toggle — plus the checkbox now flips optimistically, so a quick click registers immediately. Fixed in e6678e1 + a3df7cd. (Python had its own variant, fixed in d0f430f: toggling one staged row flipped another breakpoint's flag.)
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 for this guide. All eight were fixed Dec 2, 2026 and verified live under Xvfb. C designer: all 8 fixed, commits e6678e1 (backend) + a3df7cd (UI), repo guide updated in 3792410 — console tests 42/42, GTK tests 8/8, GUI smoke pass. Rust designer: 4 fixed in a1645d3 — Step Out degrades to Continue, Stop via async MI plus a 3-stage interrupt, Run honours Target, and the break-on-main temporary breakpoint no longer duplicates; the other 4 don't apply (no debugger UI in Rust yet). Python designer: 2 fixed in d0f430f — Run honours Target, and the staged-row checkbox variant where toggling one row flipped another breakpoint's flag; the other 6 were already handled in Python (28/28 tests pass). Nothing is outstanding in C.
- Breakpoint pane too narrow by default — fixed (
a3df7cd): hint line wraps, pane opens at 560 px. - Breakpoint list selection doesn't stick — Edit… / Remove usually did nothing — fixed (
e6678e1+a3df7cd): fingerprint-gated rebuild, selection preserved. - Step Out in
main()showed"finish" not meaningful in the outermost frame.as a modal error — fixed (e6678e1):can_step_out()guard, sticky status note instead. Rust: degrades to Continue (a1645d3). - Stop timed out (
"timed out waiting for gdb reply") on a GUI app sitting ingtk_main— fixed (e6678e1): MI async + SIGINT/SIGSTOP fallback, stops in ~2 s. Rust: async MI + 3-stage interrupt (a1645d3). - Run from Stopped/Exited ignored the Target: entry and re-ran the loaded executable — fixed (
e6678e1):restart_or_start()kills the old target and starts the new one. Also fixed in Rust (a1645d3) and Python (d0f430f). - Break-on-main's temporary breakpoint was persisted, so a fresh session could show two identical
mainbreakpoints — fixed (e6678e1): temporary flag, skipped on save, deduped on load. Also fixed in Rust (a1645d3). - Watch-entry clicks could land on the watch list and open GTK's interactive-search popup instead of focusing the entry — fixed (
a3df7cd): interactive search disabled on all lists. - Enabled-checkbox toggles sometimes ignored a quick click — fixed (
e6678e1+a3df7cd): same rebuild root cause as (2), plus optimistic flip. Python's staged-row variant fixed ind0f430f.