Skip to content

Instantly share code, notes, and snippets.

@elmotec
Last active September 27, 2025 21:07
Show Gist options
  • Save elmotec/ff0714597947593d3fa518e9595bbbc7 to your computer and use it in GitHub Desktop.
Save elmotec/ff0714597947593d3fa518e9595bbbc7 to your computer and use it in GitHub Desktop.
starter GDB cheat sheet

GDB Cheat Sheet

Starting & Running

Command Description
gdb <program> Start GDB with the specified program.
gdb -q Start quietly (no intro).
run [args] Run program with optional args.
start Run until main() and break.
attach <pid> Attach to a running process.
detach Detach from process.
quit Exit GDB.

Breakpoints

Command Description
break <function> Break at function.
break <file:line> Break at file:line.
break *<address> Break at memory address.
info breakpoints List breakpoints.
delete <n> Delete breakpoint n.
disable <n> Disable breakpoint n.
enable <n> Enable breakpoint n.
condition <n> <expr> Breakpoint n triggers only if expr is true.

Stepping & Continuing

Command Description
next / n Step over (don’t enter functions).
step / s Step into function.
finish Run until current function returns.
continue / c Resume execution.
until <line> Continue until line reached.

Examining State

Command Description
print <expr> Print expression.
display <expr> Auto-print expr each stop.
undisplay <n> Remove auto-print n.
backtrace / bt Show call stack.
frame <n> Switch to frame n.
info locals Show local variables.
info args Show function arguments.
x/<nfu> <addr> Examine memory (n=repeat count, f=format, u=unit size). Example: x/16xb $sp.

Changing State

Command Description
set var <expr>=<val> Change variable value.
return <expr> Force current function to return expr.
jump <line> Jump to line.

Program Control

Command Description
kill Stop program.
signal <sig> Send signal to program.
handle <sig> <action> Control how GDB handles signals.

Misc

Command Description
info registers Show CPU registers.
info threads List threads.
thread <n> Switch to thread n.
watch <expr> Break when expr changes.
help Show help.
apropos <keyword> Search help topics.

Tip: Use tab completion and help <command> inside GDB for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment