GDB Commands Summary
by Sultan Almuhammadi - Fall 2003
1. First, compile and link with -g option. Eg:  g++ -g -o myprog ...
2. To start debugging "myprog", type: gdb myprog
3. Then you may use the following gdb commands. Type quit to exit gdb.
GDB Command/Usage Description/Example
break main set a breakpoint at main
break <function name> set a breakpoint at the first line in <function name>
break <line#> set a breakpoint at <line#>
info break to list all active breakpoints (with index #s)
delete <#> delete a breakpoint (by index #). Eg: delete 3  (remove the 3rd breakpoint)
run start running myprog and it will stop at first breakpoint
next to execute the current line (statement) of the program (skips details inside functions)
step to step into a function call
next <n> repeat next <n> times. Eg: next 5   (repeat next 5 times)
step <n> repeat step <n> times
watch <var> set a breakpoint/watchpoint at <var> (useful to monitor the value of a variable)
cont to resume execution of the program, it will stop at next breakpoint/watchpoint.
print <exp> display the current value of variable (or expression). Eg: print (x+y)/2
display <exp> auto-print value of expression <exp> each time the program stops. No need to call print each time :)
info display to list all auto-display expressions (with index #s)
undisplay <#> cancel some expressions (by index #) that are displayed when program stops
whatis <var> print the data type of <var> or <exp>
where tell where you are now in the current function (from where called, current line numbers)
list display 10 lines of code at current position
list <n> display code around line <n>
list <m,n> display lines <m> through <n>
list <function name> display the code of the function
help display help menu
help <command> for help on gdb command
quit to quit debugger and return to Unix
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees