Go to the previous, next section.

Using _GDBN__ with Different Languages

Although programming languages generally have common aspects, they are rarely expressed in the same manner. For instance, in ANSI C, dereferencing a pointer p is accomplished by *p, but in Modula-2, it is accomplished by p^. Values can also be represented (and displayed) differently. Hex numbers in C are written like `0x1ae', while in Modula-2 they appear as `1AEH'.

Language-specific information is built into _GDBN__ for some languages, allowing you to express operations like the above in your program's native language, and allowing _GDBN__ 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 _GDBN__ can set it automatically.

Switching between source languages

There are two ways to control the working language--either have _GDBN__ set it automatically, or select it manually yourself. You can use the set language command for either purpose. On startup, _GDBN__ defaults to setting the language automatically.

Setting the working language

To set the language, issue the command `set language lang', where lang is the name of a language: c or modula-2. For a list of the supported languages, type `set language'.

Setting the language manually prevents _GDBN__ from updating the working language automatically. This can lead to confusion if you try to debug a program when the working language is not the same as the source language, when an expression is acceptable to both languages--but means different things. For instance, if the current source file were written in C, and _GDBN__ was parsing Modula-2, a command such as:

print a = b + c

might not have the effect you intended. In C, this means to add b and c and place the result in a. The result printed would be the value of a. In Modula-2, this means to compare a to the result of b+c, yielding a BOOLEAN value.

If you allow _GDBN__ to set the language automatically, then you can count on expressions evaluating the same way in your debugging session and in your program.

Having _GDBN__ infer the source language

To have _GDBN__ set the working language automatically, use `set language local' or `set language auto'. _GDBN__ then infers the language that a program was written in by looking at the name of its source files, and examining their extensions:

`*.mod'
Modula-2 source file

`*.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), _GDBN__ 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 _GDBN__ 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 will 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 is the