Debugging with GDB Manual HP WDB v6.3 (5900-2180, August 2012)
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 GDB 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 was written in C, and GDB 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.
9.1.3 Having GDB infer the source language
To have GDB set the working language automatically, use 'set language local' or 'set
language auto'. GDB then infers the working language. That is, when your program stops in
a frame (usually by encountering a breakpoint), GDB 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 GDB 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.
9.2 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 Display the source language for this frame. This language becomes the
working language if you use an identifier from this frame. See “Information
about a frame” (page 57), to identify the other information listed here.
info source Display the source language of this source file. Refer to See Chapter 10
(page 87), to identify the other information listed here.
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
Set source files with extension .ext to be assumed to be
in the source language language. However, this is not
valid on Unix systems.
info extensions List all the filename extensions and the associated languages.
Not valid on Unix systems.
9.3 Type and range checking
Some languages are designed to guard you against making seemingly common errors through a
series of compile and run-time checks. These include checking the type of arguments to functions
and operators, and making sure mathematical overflows are caught at run time. Checks such as
these help to ensure the correctness of the program once it has been compiled by eliminating type
mismatches, and providing active checks for range errors when your program is running.
78 Using GDB with Different Languages