Some gdb commands are particularly useful with C++, and some are designed specifically for use with C++. Here is a summary:
rbreak
regexcatch throw
catch rethrow
catch catch
ptype
typenameinfo vtbl
expression.
info vtbl
command can be used to display the virtual
method tables of the object computed by expression. This shows
one entry per virtual table; there may be multiple virtual tables when
multiple inheritance is in use.
demangle
namedemangle
command.
set print demangle
show print demangle
set print asm-demangle
show print asm-demangle
set print object
show print object
set print vtbl
show print vtbl
vtbl
commands do not work on programs compiled with the HP
ANSI C++ compiler (aCC
).)
set overload-resolution on
set overload-resolution off
show overload-resolution
(
types)
rather than just symbol. You can
also use the gdb command-line word completion facilities to list the
available choices, or to finish the type list for you.
See Command Completion, for details on how to do this.
The ABI tags are visible in C++ demangled names. For example, a function that returns a std::string:
std::string function(int);
when compiled for the C++11 ABI is marked with the cxx11
ABI
tag, and gdb displays the symbol like this:
function[abi:cxx11](int)
You can set a breakpoint on such functions simply as if they had no tag. For example:
(gdb) b function(int) Breakpoint 2 at 0x40060d: file main.cc, line 10. (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x0040060d in function[abi:cxx11](int) at main.cc:10
On the rare occasion you need to disambiguate between different ABI tags, you can do so by simply including the ABI tag in the function name, like:
(gdb) b ambiguous[abi:other_tag](int)