Debugging with GDB Manual HP WDB v6.3 (5900-2180, August 2012)

GDB can check for conditions like the above if you wish. Although GDB does not check the
statements in your program, it can check expressions entered directly into GDB for evaluation via
the print command, for example. As with the working language, GDB can also decide whether
or not to check automatically based on your source language. See “Supported languages
(page 80), for the default settings of supported languages.
9.3.1 An overview of type checking
Some languages are strongly typed, meaning that the arguments to operators and functions have
to be of the correct type, otherwise an error occurs. These checks prevent type mismatch errors
from causing run-time problems. For example,
1 + 2 3
but
error 1 + 2.3
The second example fails because the CARDINAL 1 is not type-compatible with the REAL 2.3.
For the expressions you use in GDB commands, you can tell the GDB type checker to skip checking;
to treat any mismatches as errors and abandon the expression; or to only issue warnings when
type mismatches occur, and evaluate the expression anyway. When you choose the last of these,
GDB evaluates expressions like the second example above, but also issues a warning.
Even if you turn type checking off, there may be other reasons related to type that prevent GDB
from evaluating an expression. For instance, GDB does not know how to add an int and a
struct foo. These particular type errors have nothing to do with the language in use, and
usually arise from expressions, such as the one described above, which make little sense to evaluate
anyway.
Each language defines to what degree it is strict about type. For instance C requires the arguments
to arithmetical operators to be numbers. In C, enumerated types and pointers can be represented
as numbers, so that they are valid arguments to mathematical operators. See “Supported languages
(page 80), for further details on specific languages.
GDB provides some additional commands for controlling the type checker:
set check type auto Set type checking on or off based on the current working language.
See “Supported languages” (page 80), for the default settings for
each language.
set check type on, set
check type off
Set type checking on or off, overriding the default setting for the
current working language. Issue a warning if the setting does not
match the language default. If any type mismatches occur in
evaluating an expression while type checking is on, GDB prints a
message and aborts evaluation of the expression.
set check type warn Cause the type checker to issue warnings, but to always attempt to
evaluate the expression. Evaluating the expression may still be
impossible for other reasons. For example, GDB cannot add
numbers and structures.
show type Show the current setting of the type checker, and whether or not
GDB is setting it automatically.
9.3.2 An overview of range checking
In some languages it is an error to exceed the bounds of a type; this is enforced with run-time
checks. Such range checking is meant to ensure program correctness by making sure computations
do not overflow, or indices on an array element access do not exceed the bounds of the array.
For expressions you use in GDB commands, you can tell GDB to treat range errors in one of three
ways: ignore them, always treat them as errors and abandon the expression, or issue warnings
but evaluate the expression anyway.
9.3 Type and range checking 79