GDB
Purpose
Walk agents through GDB sessions from first launch to advanced workflows: crash diagnosis, reverse debugging, remote debugging, and multi-thread inspection.
Triggers
- "My program segfaults / crashes — how do I debug it?"
- "How do I set a breakpoint on condition X?"
- "How do I inspect memory / variables in GDB?"
- "How do I debug a remote embedded target?"
- "GDB shows
??frames / no source" - "How do I replay a bug deterministically?" (record/replay)
Workflow
1. Prerequisite: compile with debug info
Always compile with -g (GCC/Clang). Use -Og or -O0 for most debuggable code.
For release builds: use -g -O2 and keep the binary with symbols (strip separately with objcopy).
2. Start GDB
3. Essential commands
4. Breakpoints and watchpoints
5. Inspect state
6. Multi-thread debugging
7. Reverse debugging (record/replay)
Record requires target record-full or target record-btrace (Intel PT):
8. Remote debugging with gdbserver
On target:
On host:
For cross-compilation: use aarch64-linux-gnu-gdb on the host.
9. Common problems
10. GDB init file (~/.gdbinit)
For a command cheatsheet, see references/cheatsheet.md [blocked]. For pretty-printers and Python scripting, see references/scripting.md [blocked].
Related skills
- Use
skills/debuggers/core-dumpsfor loading core files - Use
skills/debuggers/lldbfor LLDB-based workflows - Use
skills/runtimes/sanitizersto catch bugs before needing the debugger - Use
skills/compilers/gccfor-gflag details


