Debugging with GDB (September 2007)
Chapter 9: Using GDB with Different Languages 83
A range error can result from numerical overflow, from exceeding an array index bound,
or when you type a constant that is not a member of any type. Some languages, however,
do not treat overflows as an error. In many implementations of C, mathematical ove rflow
causes the result to “wrap around” to lower values—for example, if m is the largest integer
value, and s is the smallest, then
m + 1
⇒
s
This, too, is specific to individual languages, and in some cases specific to individual
compilers or machines. Refer to See Section 9.4 [Supported languages], page 83, for further
details on specific languages.
GDB provides the following additional commands for controlling the range checker:
set check range auto
Set range checking on or off based on the current working language. See Sec-
tion 9.4 [Supported languages], page 83, for the default settings for each lan-
guage.
set check range on
set check range off
Set range checking on or off, overriding the default s etting for the current work-
ing language. A warning is issued if the setting does not match the default
language. If a range error occurs and range checking is on, then a message is
printed and evaluation of the expression is aborted.
set check range warn
Output messages when the GDB range checker detects a range error, but at-
tempt to evaluate the expression anyway. Evaluating the expression may still
be impos sible for other reasons, such as accessing memory that the process does
not own (a typical example from many Unix systems).
show range
Show the current setting of the range checke r, and whether or not it is being
set automatically by GDB.
9.4 Supported languages
GDB supports C, C++, and Fortran. Refer to Section 9.4.2 [Fortran], page 90 for specific
information about Fortran.
Some GDB features may be used in expressions regardless of the language you use: the
GDB @ and :: operators, and the ‘{type}addr’ construct (see Section 8.1 [Expressions],
page 63) can be used with the constructs of any supported language.
The following section discusses GDB support for each source language. These sections
are not meant to be language tutorials or references, but serve only as a reference guide to
what the GDB expression parser acc epts, and what input and output formats should look
like for different languages.