GDB Cheat Sheet
Start up gdb with a program:
--OR-- run gdb from within emacs. This is preferable, as you can
then have multiple buffers open showing you context, etc.
Start emacs and type: M-x gdb
Very helpful to use the speedbar while debugging to aid in visiting
files and switching between buffers
(gdb) [RET] Repeat previous comamnd.
After you have entered a command once, hitting return
repeats that command. For example, (gdb) n steps one
command. Then just hit return to continue stepping.
(gdb) break main Set a breakpoint at the entry point to main
(gdb) run Run to first breakpoint
(gdb) start Runs to the beginning of main
(gdb) run CL_arg Run to first breakpoint, using a command-line arg
(gdb) n Next command (step over)
(gdb) bt Backtrace, shows where in the stack from you are
(gdb) s "s"tep into a function
(gdb) up # Go up # levels in the call stack. Eg, "up 1" shows cur. calling function.
Use "finish" to step out of current function.
(gdb) file execName Starts a new file to be debugged (can use tabbing and dired to find).
(gdb) info breakpoints Displays all break points. "info b" also works
(gdb) C-x [SPACE] Within gdb mode in emacs, sets a BP at the point in the
source file you are editing.
(gdb) break NS::ClasssName::FunctionName Set a breakpoint in a namespace,
(gdb) break NS1::NS2::ClasssName::FunctionName Set a breakpoint in nested
namespaces, class, function
Can type tab during entering of the namespace / class / function
for emacs-like auto-completion.
(gdb) break filename:line# Set a breakpoint in a file at the line #.
(gdb) l "l"ist source lines for context (lists several lines above
and below current line).
(gdb) info locals shows local variable values
(gdb) return (exp) steps out of a function. (exp) will optionally
override actual return val.
(gdb) continue re-start program execution.
(gdb) disable # Disable the breakpoint # (use "info breakoints"
to see breakpoint numbers).
(gdb) enable # Enables BP #
(gdb) delete # Deletes BP # (also "d #")
(gdb) delete Deletes all BPs (also "d")
(gdb) finish Continues until current function has ended
(gdb) until NS1::NS2::ClasssName::FunctionName Runs until reaches this point
or another line past this. Can use filename:line# syntax
(gdb) print var Prints the contents of a variable
(gdb) print vect.val() prints from a vector called vect, the
 positioned element, the value
returned by calling the function val().
(gdb) display var Display the value of var after each step
(gdb) kill Kill execution of program being debugged.
(gdb) quit Quit gdb altogether
(gdb) cd ... cd to a new working directory. This sets the cwd for the
session (in case you want to start the session in a different
working directory than the one where the exe is located.)
(gdb) print var.px->func() how to print the value a function from a
variable that is a boost::smart_ptr.
(gdb) break [place] if cond breaks at [place] (choose a place as with BPs above) if
the condiditon cond is met.
EX: (gdb) break TestGame.cpp:250 if (boolVar == false)
(gdb) where Displays where you are as well as the calling chain
(the sequence of func calls that lead us to this point.)
A lot of commands can be accessed by:
M-x gdb-xxxxxxxx where the xxxxxxx is a gbd command.
M-x gdb-display-locals-buffer - display local vars in a separate buffer