Chapter 14. Using gdb with Different Languages
117
14.4.1.3. C
++
expressions
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
-
. 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-
5
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 conver-
sions, 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 con-
versions, pointer conversions, conversions of class objects to base classes, and standard conver-
sions 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
. Refer to Section 14.4.1.7
gdb features for C++
.
You must specify
set overload-resolution off
in order to use an explicit function sig-
nature to call an overloaded function, as in
p ’foo(char,int)’(’x’, 13)
The gdb command-completion facility can simplify this; (refer to Section 5.2
Command com-
pletion
.
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 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 expres-
sions 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 resolv-
ing name scope by reference to source files, in both C and C
++
debugging (refer to Section
10.2
Program 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
user-defined operators.
Summary of Contents for ENTERPRISE LINUX 3 - SECURITY GUIDE
Page 1: ...Red Hat Enterprise Linux 3 Debugging with gdb ...
Page 12: ...2 Chapter 1 Debugging with gdb ...
Page 28: ...18 Chapter 4 Getting In and Out of gdb ...
Page 34: ...24 Chapter 5 gdb Commands ...
Page 44: ...34 Chapter 6 Running Programs Under gdb ...
Page 68: ...58 Chapter 8 Examining the Stack ...
Page 98: ...88 Chapter 10 Examining Data ...
Page 112: ...102 Chapter 12 Tracepoints ...
Page 118: ...108 Chapter 13 Debugging Programs That Use Overlays ...
Page 138: ...128 Chapter 14 Using gdb with Different Languages ...
Page 144: ...134 Chapter 15 Examining the Symbol Table ...
Page 170: ...160 Chapter 19 Debugging remote programs ...
Page 198: ...188 Chapter 21 Controlling gdb ...
Page 204: ...194 Chapter 22 Canned Sequences of Commands ...
Page 206: ...196 Chapter 23 Command Interpreters ...
Page 216: ...206 Chapter 25 Using gdb under gnu Emacs ...
Page 296: ...286 Chapter 27 gdb Annotations ...
Page 300: ...290 Chapter 28 Reporting Bugs in gdb ...
Page 322: ...312 Chapter 30 Using History Interactively ...
Page 362: ...352 Appendix D gdb Remote Serial Protocol ...
Page 380: ...370 Appendix F GNU GENERAL PUBLIC LICENSE ...
Page 386: ...376 Appendix G GNU Free Documentation License ...
Page 410: ......