Go to the previous, next section.
Language-specific information is built into for some languages, allowing you to express operations like the above in your program's native language, and allowing to output values in a manner consistent with the syntax of your program's native language. The language you use to build expressions, called the working language, can be selected manually, or can set it automatically.
There are two ways to control the working language--either have
set it automatically, or select it manually yourself. You can use the
set language
command for either purpose. On startup,
defaults to setting the language automatically.
If you allow to set the language automatically, expressions are interpreted the same way in your debugging session and your program.
If you wish, you may set the language manually. To do this, issue the
command `set language lang', where lang is the name of
a language, such as
c
.
For a list of the supported languages, type `set language'.
To have set the working language automatically, use `set language local' or `set language auto'. then infers the language that a program was written in by looking at the name of its source files, and examining their extensions:
This information is recorded for each function or procedure in a source file. When your program stops in a frame (usually by encountering a breakpoint), sets the working language to the language recorded for the function in that frame. If the language for a frame is unknown (that is, if the function or block corresponding to the frame was defined in a source file that does not have a recognized extension), the current working language is not changed, and issues a warning.
This may not seem necessary for most programs, which are written entirely in one source language. However, program modules and libraries written in one source language can be used by a main program written in a different source language. Using `set language auto' in this case frees you from having to set the working language manually.
The following commands help you find out which language is the working language, and also what language source files were written in.
show language
print
to
build and compute expressions that may involve variables in your program.
info frame
info source
4 supports C, and C++.
Some features may be used in expressions regardless of the
language you use: the @
and ::
operators,
and the `{type}addr' construct (see section Expressions) can be used with the constructs of any supported
language.
The following sections detail to what degree each source language is supported by . These sections are not meant to be language tutorials or references, but serve only as a reference guide to what the expression parser accepts, and what input and output formats should look like for different languages. There are many good books written on each of these languages; please look to these for a language reference or tutorial.
The C++ debugging facilities are jointly implemented by the GNU C++
compiler and . Therefore, to debug your C++ code
effectively, you must compile your C++ programs with the GNU C++
compiler, g++
.
For best results when debugging C++ programs, use the stabs debugging
format. You can select that format explicitly with the g++
command-line options `-gstabs' or `-gstabs+'. See
section 'Options for Debugging Your Program or GNU CC' in Using GNU CC, for more information.
Operators must be defined on values of specific types. For instance,
+
is defined on numbers, but not on structures. Operators are
often defined on groups of types.
For the purposes of C and C++, the following definitions hold:
int
with any of its storage-class
specifiers; char
; and enum
.
float
and double
.
(type
*)
.
The following operators are supported. They are listed here in order of increasing precedence:
,
=
op=
a op= b
,
and translated to a = a op b
.
op=
and =
have the same precendence.
op is any one of the operators |
, ^
, &
,
<<
, >>
, +
, -
, *
, /
, %
.
?:
a ? b : c
can be thought
of as: if a then b else c. a should be of an
integral type.
||
&&
|
^
&
==, !=
<, >, <=, >=
<<, >>
@
+, -
*, /, %
++, --
*
++
.
&
++
.
For debugging C++, implements a use of `&' beyond what is allowed in the C++ language itself: you can use `&(&ref)' (or, if you prefer, simply `&&ref') to examine the address where a C++ reference variable (declared with `&ref') is stored.
-
++
.
!
++
.
~
++
.
., ->
struct
and union
data.
[]
a[i]
is defined as
*(a+i)
. Same precedence as ->
.
()
->
.
::
struct
, union
, and class
types.
::
::
, above.
allows you to express the constants of C and C++ in the following ways:
long
value.
'
), or a number--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.
"
).
expression handling has a number of extensions to interpret a significant subset of C++ expressions.
Warning: 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. has this support only with the stabs debug format. In particular, if your compiler generates a.out, MIPS ECOFF, RS/6000 XCOFF, or ELF with stabs extensions to the symbol table, these facilities are all available. (With GNU CC, you can use the `-gstabs' option to request stabs debugging extensions explicitly.) Where the object code format is standard COFF or DWARF in ELF, on the other hand, most of the C++ support in does not work.
count = aml->GetOriginal(x, y)
this
following the same rules as C++.
In the parameter list shown when 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'.
::
---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'. also allows
resolving name scope by reference to source files, in both C and C++
debugging (see section Program variables).
If you allow 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 ,
selected the working language.
If you allow to set the language automatically, it sets the working language to C or C++ on entering code compiled from a source file whose name ends with `.c', `.C', or `.cc'. See section Having infer the source language, for further details.
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 @
operator aids in the debugging of dynamic arrays, formed
with pointers and a memory allocation function. See section Expressions.
Some commands are particularly useful with C++, and some are designed specifically for use with C++. Here is a summary:
breakpoint menus
rbreak regex
catch exceptions
info catch
ptype typename
set print demangle
show print demangle
set print asm-demangle
show print asm-demangle
set print object
show print object
set print vtbl
show print vtbl
Overloaded symbol names
symbol(types)
rather than just symbol. You can
also use the command-line word completion facilities to list the
available choices, or to finish the type list for you.
See section Command completion, for details on how to do this.
Go to the previous, next section.