| Running a Program | ||
|---|---|---|
gdb [prog] * |
Open prog in the debugger. |
|
gdb [prog] [core] * |
Open prog in the debugger with corefile core. |
|
run |
r |
Run the program. |
run [arg1] ... |
Run the program with command line arguments. | |
run < [file] |
Run the program with standard input piped from file. |
|
quit |
q |
Exit the debugger. |
| Pausing and Continuing | ||
| Ctrl + C | Pause the program and open the debugger console. | |
step [n=1] |
s |
Run n lines of source code, then pause. |
next [n=1] |
n |
Like step, but don't count lines inside function calls. |
stepi [n=1] |
si |
Run n machine instructions, then pause. |
nexti [n=1] |
ni |
Like stepi, but don't count instructions inside calls. |
finish |
f |
Run until the current function is finished, then pause. |
continue |
c |
Start a paused program running normally again. |
| Walking the Stack | ||
backtrace |
bt |
Show the function call stack. |
up [n=1] |
Go up n stack frames. |
|
down [n=1] |
Go down n stack frames. |
|
frame [n] |
Go to stack frame n. |
|
| Looking Around | ||
info args |
i ar |
Show the values of any arguments to the current function. |
info locals |
i lo |
Show the values of any local variables. |
print [expr] |
p |
Evaluate expr and print the result. |
print ([type]) [expr] |
Cast the result of expr to type and print it. |
|
print $[reg] |
Print the value of register reg. |
|
x [expr] |
x |
Evaluate expr to a pointer and examine its target. |
x $[reg] |
Examine the memory pointed to by register reg. |
|
| Breakpoints | ||
break [name] |
b |
Create a breakpoint at the entry to function name. |
break [file]:[line] |
Create a breakpoint at the code from line in file. |
|
break *[addr] |
Create a breakpoint at memory address addr. |
|
break ... if [cond] |
Create a breakpoint that only triggers when cond is true. |
|
info breakpoints |
i b |
List all current breakpoints and catchpoints. |
disable [n] |
Disable breakpoint number n; also accepts a range. |
|
enable [n] |
Enable breakpoint number n; also accepts a range. |
|
delete [n] |
d |
Delete breakpoint number n; also accepts a range. |
clear ... |
Delete a breakpoint using the same syntax as break. |
|
| Catchpoints | ||
catch throw |
Break when a C++ exception is thrown. | |
catch syscall |
Break when a system call is made. | |
catch syscall [n] ... |
Break on system calls with name or number n. |
|
catch signal [sig] ... |
Break when signal sig (or all) is delivered. |
|
catch load |
Break when a shared library is loaded. | |
tcatch ... |
Create a catchpoint that will only catch one event. | |
info breakpoints |
i b |
List all current catchpoints and breakpoints. |
| Miscellaneous | ||
help |
h |
Show the top-level help menu. |
help [command] |
Show the help entry for command. |
|
info proc mappings |
i proc m |
Show the program's memory layout. |
info registers |
i r |
Show the contents of the CPU registers. |
info frame |
i f |
Show information about the current stack frame. |
list [addr=*$rip] |
l |
Print source code for the function containing addr. |
disassemble [addr=*$rip] |
disas |
Disassemble the function containing addr. |
| ↵ Enter | Repeat or continue the previous command. | |