Launching GDB (in the terminal)
|
gdb [prog] |
Loads the program [prog] into GDB. |
gdb --args [prog] [arg1 arg2 ...] |
Loads the program [prog] into GDB with the parameters [arg1 arg2 ...]
|
gdb [prog] [core-file] |
Loads the core dump of the program [prog] into GDB. |
q or quit
|
Quits GDB. |
Showing the code (in gdb)
|
layout src |
Splits the view and shows the code. |
Starting Program Execution (in gdb)
|
r or run
|
Starts the execution of the program loaded in GDB. |
r [arg1 arg2 ...] |
Starts the execution of the program loaded in GDB with the parameters [arg1 arg2 ...]. |
set [args arg1 arg2 ...] |
Sets the list of arguments ([arg1 arg2 ...]) for the next program to start. |
Examining the State of a Process (in gdb)
|
p [var] or print [var]
|
Displays the value of the variable [var]. |
p/x [var] |
Displays the hexadecimal value of the variable [var]. |
display [var] |
Displays the value of the variable [var] at every stop of the program. |
bt or backtrace
|
Displays the call stack. |
frame |
Displays the current call frame. |
frame [x] |
Selects the call frame [x]. |
l or list
|
Displays the code around the selected call frame. |
Monitoring Process Execution (in gdb)
|
b [pos] or break [pos]
|
Sets a breakpoint at [pos]. [pos] can be a function name, a line number (from the current file), a file name+line number (break my_file:57), etc. |
clear [pos] |
Removes the breakpoint at [pos]. |
d [num] or delete [num]
|
Removes the breakpoint number [num]. |
w [var] or watch [var]
|
Watches the state of the variable [var]. |
Controlling Process Execution (in gdb)
|
n or next
|
Steps forward one line. |
s or step
|
Steps forward one line. If the instruction to execute is a function call, it does not descend into the function. |
c or continue
|
Continues execution until the next breakpoint. |