f78
C and C++
The C++ debugging facilities are jointly implemented by the GNU C++ compiler and GDB. Therefore, to debug your C++ code effectively, you must
compile your C++ programs with the GNU C++ compiler,
For best results when debugging C++ programs, use the
Integral types include
Floating-point types include
Pointer types include all types defined as
Scalar types include all of the previous types.
The following operators are supported. They are listed in order of increasing
precedence:
For debugging C++, GDB implements a use of ‘
Integer constants are a sequence of digits. Octal constants are specified by a
leading ‘
Floating point constants are a sequence of digits, followed by a decimal
point, followed by a sequence of digits, and optionally followed by an exponent. An
exponent is of the form: ‘
Enumerated constants consist of enumerated identifiers, or their integral
equivalents.
Character constants are a single character surrounded by single quotes (
String constants are a sequence of character constants surrounded by double
quotes (
Pointer constants are an integral value. You can also write pointers to
constants using the C operator, ‘
Array constants are comma-separated lists surrounded by braces ‘
Warning: GDB can only debug C++ code if you compile with the
GNU C++ compiler. Moreover, C++ debugging depends on the use of additional
debugging information in the symbol table, and thus requires special support. GDB has
this support only with the stabs debug format. In particular, if your compiler
generates
Member function calls are allowed; you can use expressions like
You can call overloaded functions; GDB resolves the function call to the right
definition, with one restriction—you must use arguments of the type required
by the function that you want to call. GDB does not perform conversions
requiring constructors or user-defined type operators.
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 ‘
GDB supports the C++ name resolution operator
This happens regardless of whether you or GDB selects the working language.
If you allow GDB to set the language automatically, it recognizes source files
whose names end with ‘
The two variables are structured and have the same structure, union, or
enumerated tag.
The two variables have the same type name, or types that have
ffb
been declared
equivalent through
Range checking, if turned on, is done on mathematical operations. Array
indices are not checked, since they are often used to index a pointer that is not
itself an array.
The
breakpoint menus
show print demangle
set print asm-demangle
show print asm-demangle
show print object
show print vtbl
Overloaded symbol names
The comma or sequencing operator. Expressions in a comma-separated list are
evaluated from left to right, with the result of the entire expression being the
last expression evaluated.
Assignment. The value of an assignment expression is the value assigned.
Defined on scalar types.
Used in an expression of the form a op=b, and translated to a= a opb. op= and = have the same precendence. op is any one of the operators |, ˆ, &, <<, >>, +, -, *, /, %.
The ternary operator. a ? b: c can be thought of as: if a, then b, else, c. a should be of an integral type.
Logical OR. Defined on integral types.
Logical AND. Defined on integral types.
Bitwise OR. Defined on integral types.
Bitwise exclusive-OR. Defined on integral types.
Bitwise AND . Defined on integral types.
Equality and inequality. Defined on scalar types. The value of these
expressions is 0 for false and non-zero for true.
Less than, greater than, less than or equal, greater than or equal. Defined on
scalar types. The value of these expressions is 0 for false and non-zero for
true.
Left shift, and right shift. Defined on integral types.
The GDB “artificial array” operator (see Expressions).
Addition and subtraction. Defined on integral types, floating-point types and
pointer types.
Multiplication, division, and modulus. Multiplication and division are defined
on integral and floating-point types. Modulus is defined on integral types.
Increment and decrement. When appearing before a variable, the operation is
performed before the variable is used in an expression; when appearing after it,
the variable’s value is used before the operation takes place.
Pointer dereferencing. Defined on pointer types. Same precedence as ++.
Address operator. Defined on variables. Same precedence as ++.
Negative. Defined on integral and floating-point types. Same precedence as ++.
Logical negation. Defined on integral types. Same precedence as ++.
Bitwise complement operator. Defined on integral types. Same precedence as ++.
Structure member, and pointer-to-structure member. For convenience, GDB
regards the two as equivalent, choosing whether to dereference a pointer based on the
stored type information. Defined on struct and union data.
Array indexing. a[
ffb
B>i] is defined as *(a+i). Same precedence as ->.
Function parameter list. Same precedence as ->.
C++ scope resolution operator. Defined on struct, union, and class types.
Doubled colons also represent the GDB scope operator (see Expressions). Same precedence as ::.
C and C++ constants
When you want a breakpoint in a function whose name is overloaded, GDB
breakpoint menus help you specify which function definition you want. See
Setting breakpoints using regular expressions is helpful for setting
breakpoints on overloaded functions that are not members of any special classes. See Setting breakpoints.
Debug C++ exception handling using these commands. See Breakpoints and exceptions.
Print inheritance relationships as well as other information for type
typename. See Examining the Symbol Table.
Cont
713
rol whether C++ symbols display in their source form, both when displaying
code as C++ source and when displaying disassemblies. See Print settings.
Choose whether to print derived (actual) or declared types of objects. See Print settings.
Control the format for printing virtual function tables. See Print settings.
You can specify a particular definition of an overloaded symbol, using the
same notation that is used to declare such symbols in C++: type