Below is a useful subset of gdb commands, listed roughly in the order they might be needed. The first column gives the command, with optional characters enclosed in [square brackets]. For example, the run command can be abbreviated r. The second column gives a short description of the command. Type help <command> in gdb to obtain more information on each command.
r[un] | Run to next breakpoint or to end |
s[tep] | Single-step, descending into functions |
n[ext] | Single-step without descending into functions |
fin[ish] | Finish current function, loop, etc. (useful!) |
c[ontinue] | Continue to next breakpoint or end |
up | Go up one context level on stack (to caller) |
do[wn] | Go down one level (only possible after up) |
p[rint] ![]() ![]() |
Print value of variable called ![]() ![]() |
p/x ![]() ![]() |
Print value of ![]() ![]() |
p ![]() ![]() ![]() ![]() |
print ![]() ![]() ![]() ![]() |
p ![]() ![]() ![]() ![]() |
List all variables starting with ![]() ![]() |
b[reak] ![]() ![]() |
Set a breakpoint at function ![]() ![]() |
b ![]() ![]() ![]() ![]() |
Set a breakpoint at ![]() ![]() ![]() ![]() |
b ![]() ![]() ![]() ![]() |
List all members in ![]() ![]() |
h[elp] b | Documentation for setting breakpoints |
i[nfo] b | List breakpoints |
i | List all info commands |
dis[able] 1 | Disable breakpoint 1 |
en[able] 1 | Enable breakpoint 1 |
d[elete] 1 | Delete breakpoint 1 |
d 1 2 | Delete breakpoints 1 and 2 |
d | Delete all breakpoints |
cond[ition] 1 ![]() ![]() |
Stop at breakpoint 1 only if ![]() ![]() |
cond 1 | Make breakpoint 1 unconditional |
comm[ands] 1 | Add a list of gdb commands to execute |
each time breakpoint 1 is hit | |
(usually just print <var>) |