Debugging with GDB (September 2007)
86 Debugging with GDB
9.4.1.2 C and C++ constants
GDB allows you to express the constants of C and C++ in the following ways:
• Integer constants are a sequence of digits. Octal constants are specified by a leading
‘0’ (i.e. zero), and hexadecimal constants by a leading ‘0x’ or ‘0X’. Constants can also
end with a letter ‘l’, specifying that the constant should be treated as a long value.
• 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: ‘e[[+]|-]nnn ’, where nnn is a sequence of digits. The ‘+’ is optional for positive
exponents. A floating-point constant may also end with a letter ‘f’ or ‘F’, specifying
that the constant should be treated as being of the float (as opposed to the default
double) type; or with a letter ‘l’ or ‘L’, which specifies a long double constant.
• Enumerated constants consist of enumerated identifiers, or their integral equivalents.
• Character constants are a single character surrounded by single quotes (’), or a number
or the ordinal value of the corresponding character (usually its ascii value). Within
quotes, the single character may be represented by a letter or by escape sequences,
which are of the form ‘\nnn ’, where nnn is the octal representation of the character’s
ordinal value; or of the form ‘\x ’, where ‘x ’ is a predefined special character—for
example, ‘\n’ for newline.
• String constants are a sequence of character constants surrounded by double quotes (").
Any valid character constant (as described above) may appear. Double quotes within
the string must be preceded by a backslash, so for instance ‘"a\"b’c"’ is a string of
five characters.
• Pointer constants are an integral value. You can also write pointers to constants using
the C operator ‘&’.
• Array constants are comm a-se parated lists surrounded by braces ‘{’ and ‘}’; for e x-
ample, ‘{1,2,3}’ is a three-element array of integers, ‘{{1,2}, {3,4}, {5,6}}’ is a
three-by-two array, and ‘{&"hi", &"there", &"fred"}’ is a three-element array of
pointers.
9.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. Typ-
ically, C++ debugging depends on the use of additional debugging information
in the symb ol table, and thus requires special support. In particular, if your
compiler generates a.out, MIPS ecoff, RS/6000 xcoff, or elf with stabs ex-
tensions to the symbol table, these facilities are all available. (With gnu CC,
you can use the ‘-gstabs’ option to request stabs debugging extensions explic-
itly.) Where the object code format is standard coff or dwarf in elf, on the
other hand, most of the C++ support in GDB do e s not work.
1. Member function calls are allowed; you can use expressions like
count = aml->GetOriginal(x, y)