gdb.info: C plus plus expressions
Go forward to C Defaults
Go backward to C Constants
Go up to C
Go to the top op gdb
GDB expression handling can interpret most C++ expressions.
_Warning:_ GDB can only debug C++ code if you use the proper
compiler and the proper debug format. Currently, GDB works best
when debugging C++ code that is compiled with GCC 2.95.3 or with
GCC 3.1 or newer, using the options `-gdwarf-2' or `-gstabs+'.
DWARF 2 is preferred over stabs+. Most configurations of GCC emit
either DWARF 2 or stabs+ as their default debug format, so you
usually don't need to specify a debug format explicitly. Other
compilers and/or debug formats are likely to work badly or not at
all when using GDB to debug C++ code.
1. Member function calls are allowed; you can use expressions like
count = aml->GetOriginal(x, y)
2. While a member function is active (in the selected stack frame),
your expressions have the same namespace available as the member
function; that is, GDB allows implicit references to the class
instance pointer `this' following the same rules as C++.
3. You can call overloaded functions; GDB resolves the function call
to the right definition, with some restrictions. GDB does not
perform overload resolution involving user-defined type
conversions, calls to constructors, or instantiations of templates
that do not exist in the program. It also cannot handle ellipsis
argument lists or default arguments.
It does perform integral conversions and promotions, floating-point
promotions, arithmetic conversions, pointer conversions,
conversions of class objects to base classes, and standard
conversions such as those of functions or arrays to pointers; it
requires an exact match on the number of function arguments.
Overload resolution is always performed, unless you have specified
`set overload-resolution off'. *Note GDB features for C++:
Debugging C plus plus.
You must specify `set overload-resolution off' in order to use an
explicit function signature to call an overloaded function, as in
p 'foo(char,int)'('x', 13)
The GDB command-completion facility can simplify this; see *Note
Command completion: Completion.
4. GDB understands variables declared as C++ references; you can use
them in expressions just as you do in C++ source--they are
In the parameter list shown when GDB displays a frame, the values
of reference variables are not displayed (unlike other variables);
this avoids clutter, since references are often used for large
structures. The _address_ of a reference variable is always
shown, unless you have specified `set print address off'.
5. GDB supports the C++ name resolution operator `::'--your
expressions can use it just as expressions in your program do.
Since one scope may be defined in another, you can use `::'
repeatedly if necessary, for example in an expression like
`SCOPE1::SCOPE2::NAME'. GDB also allows resolving name scope by
reference to source files, in both C and C++ debugging (*note
Program variables: Variables.).
In addition, when used with HP's C++ compiler, GDB supports calling
virtual functions correctly, printing out virtual bases of objects,
calling functions in a base subobject, casting objects, and invoking
Created Mon Nov 8 17:42:38 2004 on tillpc with info_to_html version 0.9.6.