Debugging with GDB (September 2007)

88 Debugging with GDB
9.4.1.4 C and C++ defaults
If you allow GDB to set type and range checking automatically, they both default to off
whenever the working language changes to C or C++. 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 .c’, .C’, or .cc’, etc, and when GDB enters code compiled from one of
these files, it sets the working language to C or C++. Refer to See Section 9.1.3 [Having
GDB infer the source language], page 80, for further details.
9.4.1.5 C and C++ type and r ange checks
By default, when GDB parses C or C++ expressions, type checking is not used. However,
if you turn type checking on, GDB considers two variable types equivalent if:
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 been declared equivalent
through typedef.
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.
9.4.1.6 GDB and C
The set print union and show print union commands apply to the union type. When
set to on’, any union that is inside a struct or class is also printed. Otherwise, it appears
as {...}’.
The @ op e rator aids in the debugging of dynamic arrays, formed with pointers and a
memory allocation function. See Section 8.1 [Expressions], page 63.
9.4.1.7 GDB features for C++
Some GDB commands are particularly useful with C++, and some are designed spec ifi-
cally for use with C++. Here is a summary:
breakpoint menus
When you want a breakpoint in a function whose name is overloaded, GDB
breakpoint menus help you specify which function definition you want. See
Section 5.1.7 [Breakpoint menus], page 42.
rbreak regex
Setting breakpoints using regular expressions is helpful for setting breakpoints
on overloaded functions that are not members of any special classes. See Sec-
tion 5.1.1 [Setting breakpoints], page 33.