GNU Debugger

Start the gnu debugger from the command line with:

$ gdb foo

Commands

Press <RET> to simply repeat the previous command.

Running

run (or 'start' which initially breaks at main())
step (step into)
finish (step out of current function)
next (stop over)
continue

Step steps into the current line of code, whilst next steps over it.

Breakpoints

info breakpoints
break main.cc:140
help disable breakpoints
save breakpoints mypoints
source mypoints

Variables

display foo
undisplay foo

Core Dumps

Enable core dumps (if necessary) with:

$ ulimit -c unlimited

To see what is set:

$ ulimit -a

To disable core dumps:

$ ulimit -c 0

View Stack Trace

To see the stack trace for a core dump:

$ gdb ./src/executable /tmp/core
(gdb) where
(gdb) thread apply all bt

See http://publib.boulder.ibm.com/httpserv/ihsdiag/get_backtrace.html

References


-- Frank Dean - 10 Apr 2010

Related Topics: DebianTips, LinuxHintsAndTips