Table of Contents
GDB Commands
GDB commands control execution and inspection. Most commands have short abbreviations. Typing a blank line repeats the last command.
run (r) start program continue (c) resume from breakpoint next (n) next line (skip calls) step (s) next line (step into calls) finish run until return until line run until line reached break (b) location set breakpoint watch variable set watchpoint print (p) expr show expression value backtrace (bt) show call stack frame N select frame N up / down move between frames list (l) show source around current line quit (q) exit GDB help command show help info breakpoints list breakpoints delete N delete breakpoint N disable N disable (keep) breakpoint enable N enable breakpoint display expr auto-print expression undisplay N remove display
Abbreviations: most commands work with just the first letter. b for break, c for continue, n for next, s for step, p for print. Exceptions: u is ambiguous (could be until or up), so use the full name.
Blank line repeats the last command—useful for stepping (n, n, n by just pressing Enter). Stepping becomes very fast this way.
Command separators: separate multiple commands on one line with semicolons. break main; run; step sets a breakpoint at main, starts the program, and steps into main.
Sourcing commands: if you type the same sequence repeatedly, save commands to a file and run source filename in GDB. Each line is a command.
Shell escape: prefix a line with shell or ! to run a shell command. shell ls lists the current directory without leaving GDB.
Abbreviations are context-sensitive—if you type f 2, GDB interprets it as frame 2, not finish 2. Full names are safer in scripts.
