Go to the first, previous, next, last section, table of contents.
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 is called the working language.
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. The working language is
used to determine how expressions you type are interpreted, how values
are printed, etc.
In addition to the working language, every source file that
knows about has its own working language. For some object
file formats, the compiler might indicate which language a particular
source file is in. However, most of the time infers the
language from the name of the file. The language of a source file
controls whether C++ names are demangled--this way backtrace can
show each frame appropriately for its own language. There is no way to
set the language of a source file from within .
This is most commonly a problem when you use a program, such
as cfront or f2c, that generates C but is written in
another language. In that case, make the
program use #line directives in its C output; that way
will know the correct language of the source code of the original
program, and will display that source code, not the generated C code.
If a source file name ends in one of the following extensions, then infers that its language is the one indicated.
In addition, you may set the language associated with a filename extension. See section Displaying the language.
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'.
Setting the language manually prevents from updating the
working language automatically. For example, if you used the c
setting to debug a C++ program, names might not be demangled properly,
overload resolution would not work, user-defined operators might not be
interpreted correctly, and so on.
To have set the working language automatically, use `set language local' or `set language auto'. then infers the working language. That is, 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
In unusual circumstances, you may have source files with extensions not in the standard list. You can then set the extension associated with a language explicitly:
set extension-language .ext language
info extensions
supports C, C++, Fortran, Chill, and assembly.
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.
Since C and C++ are so closely related, many features of apply to both languages. Whenever this is the case, we discuss those languages together.
@raisesections
The C++ debugging facilities are jointly implemented by the C++
compiler and . Therefore, to debug your C++ code
effectively, you must compile your C++ programs with a supported
C++ compiler, such as GNU g++, or the HP ANSI C++
compiler (aCC).
For best results when using GNU C++, 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 can interpret most C++ expressions.
Warning: can only debug C++ code if you use the proper compiler. Typically, C++ debugging depends on the use of additional debugging information in the symbol table, and thus requires special support. 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++.
::---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
selects the working language.
If you allow to set the language automatically, it recognizes source files whose names end with `.c', `.C', or `.cc', etc, and when enters code compiled from one of these files, it sets the working language to C or C++. 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 throw
catch 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.
@lowersections
Go to the first, previous, next, last section, table of contents.