Debugging with GDB (September 2007)

Chapter 9: Using GDB with Different Languages 87
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 doe s perform integral conversions and promotions, floating-point promotions, arith-
metic 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 numbe r of function arguments.
Overload resolution is always performed, unless you have specified set overload-
resolution off. See Section 9.4.1.7 [GDB features for C++], page 88.
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. Refer to Section 3.2 [Com-
mand completion], page 17.
4. GDB understands variables declared as C++ references; you can use them in expressions
just as you do in C++ source—they are automatically dereferenced.
In the parameter list shown when GDB displays a frame, the values of reference vari-
ables 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 spec ified 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 (see Section 8.2 [Program variables], page 64).
In addition, when used with the HP aC++ compiler, GDB supports calling virtual func-
tions correctly, printing out virtual bases of objects, calling functions in a base subobject,
casting objects, and invoking user-defined operators.
Note: GDB cannot display debugging information for classes or functions de-
fined in a shared library that is not compiled for debugging (with the -g0
option). GDB displays the function with the message <no data fields>.
For example, after d3 is created by the following line:
RWCollectableDate d3(15,5,2001);
printing the variable or class returns:
(gdb) p d3
$3 = {<No data fields>}
(gdb) ptype RWCollectableDate
type = class RWCollectableDate {
<no data fields>