This adds some new commands and convenience functions to gdb. I've found these useful while hacking on firefox.
Also, for Emacs users, this arranges to set
when gdb is running inside Emacs, so that the
edit command will contact
Emacs and not wait for the edit to be complete. (In this case it also
sets another environment variable so the new
ecomm command will do
the right thing.)
The simplest way is to:
This will edit your
.gdbinit to load the helpers.
ecomm N. Edit the commands for breakpoint N. This writes the commands out to a file and pops up your editor. When you're done the commands are re-applied.
hier CLASS. Print the class hierarchy of a class, one line per base class.
preattach FILE. This is like
attach, but it attaches to the next instance of the program. This relies on SystemTap to do its magic.
set backtrace function,
set backtrace filename, and
set backtrace argumentto colorize backtraces. Also see
STRas a Python expression. This is an occasionally handy shortcut to use in place of a new
$_typeof(EXP). Evaluates EXP and then returns a string representation of its dynamic type. This is handy in conjunction with
$_regex(distributed with gdb) in breakpoint conditions -- you can easily break only when a specific sub-class is seen.
$_upvar(NAME, LIMIT). Search up for at most LIMIT frames, looking for a variable named NAME (which must be a string). If such a variable is found, return its value. Otherwise, an error results.
$_up([N = 1]). Move up N frames and return 1. This is sometimes useful in conjunction with
$_var(NAME). Return the value of a variable named NAME in the current frame.
If you put
extended-prompt, then when running gdb in the shell, changes to the current location will be sent to a running Emacs using
emacsclient. For best results you will also want to
(setq server-raise-frame nil)in Emacs.
This is useful if you have to run gdb from the shell for some reason, and want see the sources, and don't want to use the TUI, and gdb-gui fails due to an obscure bug on your machine. Cough cough.