Go to the previous, next section.

Using with Different Languages

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.

Switching between source languages

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.

Setting the working 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'.

Having infer the source 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:

`*.c'
C source file

`*.C'
`*.cc'
C++ source file

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.

Displaying the language

The following commands help you find out which language is the working language, and also what language source files were written in.

show language
Display the current working language. This is the language you can use with commands such as print to build and compute expressions that may involve variables in your program.

info frame
Among the other information listed here (see section Information about a frame) is the source language for this frame. This language becomes the working language if you use an identifier from this frame.

info source
Among the other information listed here (see section Examining the Symbol Table) is the source language of this source file.

Supported languages

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.

@raisesections

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.

C and C++ operators

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:

The following operators are supported. They are listed here in order of increasing precedence:

,
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.

op=
Used in an expression of the form a op= b, and translated to a = a op b. 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 "artificial array" operator (see section 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 ++.

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.

-
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, 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[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 scope operator (see section Expressions). Same precedence as ::, above.

C and C++ constants

allows you to express the constants of C and C++ in the following ways:

C++ expressions

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.

  1. Member function calls are allowed; you can use expressions like

    count = aml->GetOriginal(x, y)
    

  2. While a member function is active (in the selected stack frame), your expressions have the same namespace available as the member function; that is, allows implicit references to the class instance pointer this following the same rules as C++.

  3. You can call overloaded functions; 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. does not perform conversions requiring constructors or user-defined type operators.

  4. 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 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'.

  5. supports the C++ name resolution operator ::---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).

C and C++ defaults

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.

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 @ operator aids in the debugging of dynamic arrays, formed with pointers and a memory allocation function. See section Expressions.

features for C++

Some commands are particularly useful with C++, and some are designed specifically for use with C++. Here is a summary:

breakpoint menus
When you want a breakpoint in a function whose name is overloaded, breakpoint menus help you specify which function definition you want. See section Breakpoint menus.

rbreak regex
Setting breakpoints using regular expressions is helpful for setting breakpoints on overloaded functions that are not members of any special classes. See section Setting breakpoints.

catch exceptions
info catch
Debug C++ exception handling using these commands. See section Breakpoints and exceptions.

ptype typename
Print inheritance relationships as well as other information for type typename. See section Examining the Symbol Table.

set print demangle
show print demangle
set print asm-demangle
show print asm-demangle
Control whether C++ symbols display in their source form, both when displaying code as C++ source and when displaying disassemblies. See section Print settings.

set print object
show print object
Choose whether to print derived (actual) or declared types of objects. See section Print settings.

set print vtbl
show print vtbl
Control the format for printing virtual function tables. See section Print settings.

Overloaded symbol names
You can specify a particular definition of an overloaded symbol, using the same notation that is used to declare such symbols in C++: type 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 previous, next section.