compile program with debugging symbols
gcc -g program.c -o programname
run program with gdb
gdb programname
(gdb) run arg1 "arg2" ...
exit gdb
(gdb) quit
help in gdb
(gdb) help
stop execution -- press CTRL-C (sends SIGINT signal)
continue execution
(gdb) continue
watch code where program has stopped
(gdb) list
step-through the code -- next, step
(gdb) next -- go over the function call to the next line of code
(gdb) step -- go into the function call
examine variables
(gdb) print x
modify variables
(gdb) set x = 3
call functions -- your own/system's
(gdb) call abort () -- this will dump the core!
return from a function to its caller
(gdb) finish
get trace of function calls -- outputs each call with a frame number
(gdb) backtrace
change stack frames
(gdb) frame 2 -- to change frame 2
examine stack frames -- current frame
(gdb) info frame
(gdb) info locals
(gdb) info args
set a breakpoint on a line
(gdb) break 19
(gdb) break program.c:19
set a breakpoint on a C function
(gdb) break function
set a temporary breakpoint
(gdb) tbreak
list of breakpoints
(gdb) info breakpoints
disable a breakpoint
(gdb) disable 2
(gdb) info breakpoints
skip breakpoints
(gdb) ignore 2 5 -- will ignore next 5 crossings of breakpoint 2
set write watchpoint for a variable
(gdb) watch x -- x is the variable
(gdb) continue
set read watchpoint for a variable
(gdb) rwatch y
(gdb) continue
set read/write watchpoint for a variable
(gdb) awatch x
disable watchpoint
(gdb) info breakpoints
(gdb) disable 4