5.3.15 · D3Build Systems & Toolchain

Worked examples — GDB debugging — breakpoints, watchpoints, step, next, backtrace

3,594 words16 min readBack to topic

See the parent: GDB debugging (topic note).


The scenario matrix

Before solving anything, let us list every kind of question this topic can throw. Think of it as a grid: each row is a class of situation, and every worked example below fills in one row.

# Case class The knob that changes Degenerate / limiting edge
C1 Software watchpoint cost , , all finite (hardware) ⇒
C2 Hardware watchpoint limit number of watched bytes 5th watchpoint ⇒ forced software
C3 step vs next trace call present vs absent line has no call ⇒ they behave identically
C4 Breakpoint mechanics byte substitution at address instruction pointer must back up by 1
C5 Crash triage with bt which frame holds the bug bug is in the caller, not the crash line
C6 Optimization erases a variable -O0 vs -O2/-O3 <optimized out> at high -O
C7 Real-world word problem pick hardware vs software live choose the cheaper tool under a time budget
C8 Exam twist breakpoint "didn't fire" pending symbol / inlining / zero hits

Every cell below is covered. Signs and limits live inside the cost-model rows (C1, C2, C7); the degenerate control-flow case is C3's edge; the zero-hit degenerate case is C8.


C1 — Software watchpoint cost (the core formula)


C2 — Hardware watchpoint limit → forced software fallback


C3 — step vs next: trace them, including the degenerate edge

Figure — GDB debugging — breakpoints, watchpoints, step, next, backtrace

C4 — Breakpoint mechanics: the byte and the pointer


C5 — Crash triage: the bug lives one frame up

Figure — GDB debugging — breakpoints, watchpoints, step, next, backtrace

C6 — Optimization erases a variable


C7 — Real-world word problem: choose the tool under a time budget


C8 — Exam twist: the breakpoint that "never fired" (two distinct symptoms)


Recall Self-test: match each answer to its matrix cell

Software watchpoint with — slowdown? ::: (C1) 5th watchpoint on x86 with DR0–DR3 full — what happens? ::: Falls back to software, again (C2) next presses vs step presses to cross a 2-line call — difference? ::: 2 extra step presses; on a call-free line, difference is 0 (C3) Net offset GDB applies to the instruction pointer after an INT3 trap? ::: (C4) On a NULL-deref crash, how many frames up is the usual bug? ::: 1 (the caller) (C5) Return value of factorial(5) regardless of -O level? ::: (C6) Software vs hardware slowdown for ? ::: (100.5 s, over budget) vs (0.5 s) (C7) A breakpoint shows <PENDING> and 0 hits — what class of cause? ::: Unresolved symbol: missing -g / unloaded shared lib / inlining (C8a) A breakpoint shows a real hex address but 0 hits — what class of cause? ::: Reachability: forgot run, or the branch was never taken (C8b)

Related method: The scientific method in debugging · Deeper tooling: Memory debugging — Valgrind & AddressSanitizer.