gdb
GDB debugger skill for C/C++ programs. Use when starting a GDB session, setting breakpoints, stepping through code, inspecting variables, debugging crashes, using reverse debugging (record/replay), remote debugging with gdbserver, or loading core dumps. Activates on queries about GDB commands, segfa
By mohitmishra786 · 680 installs
npx skills add mohitmishra786/low-level-dev-skills --skill gdb
Source repository · Upstream listing
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
Command Shortcut Effect
run [args] r Start the program
continue c Resume after break
next n Step over (source line)
step s Step into
nexti ni Step over (instruction)
stepi si Step into (instruction)
finish Run to end of current function
until N Run to line N
return [val] Force return from function
quit q Exit GDB
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
Symptom Cause Fix
No symbol table Binary not compiled with g Recompile with g
?? frames in backtrace Missing debug info or stack corruption Install debuginfo package; check for stack smash
Cannot access memory at address Null dereference / freed memory Check pointer before deref; use ASan
SIGABRT in backtrace abort() or assertion failure Go up frames to find the assertion
GDB hangs on run Binary waiting for input Redirect stdin: run < /dev/null
Breakpoint in wrong place Optimiser moved code Compile with Og ; or use nexti
10. GDB init file (~/.gdbinit)
For a command cheatsheet, see [references/cheatsheet.md](references/cheatsheet.md).
For pretty printers and Python scripting, see [references/scripting.md](references/scripting.md).
Related skills
Use skills/debuggers/core dumps for loading core files
Use skills/debuggers/lldb for LLDB based workflows
Use skills/runtimes/sanitizers to catch bugs before needing the debugger
Use skills/compilers/gcc for g flag details