112
Chapter 14. Using gdb with Different Languages
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 mis-
matches occur, but 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, both Modula-2 and C require
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. Refer to Section
14.4
Supported languages
, 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. Refer to Section 14.4
Sup-
ported languages
, 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. Eval-
uating 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.
14.3.2. An overview of range checking
In some languages (such as Modula-2), 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.
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
Summary of Contents for ENTERPRISE LINUX 4 - DEVELOPER TOOLS GUIDE
Page 1: ...Red Hat Enterprise Linux 4 Debugging with gdb ...
Page 12: ...2 Chapter 1 Debugging with gdb ...
Page 28: ...18 Chapter 4 Getting In and Out of gdb ...
Page 34: ...24 Chapter 5 gdb Commands ...
Page 44: ...34 Chapter 6 Running Programs Under gdb ...
Page 68: ...58 Chapter 8 Examining the Stack ...
Page 98: ...88 Chapter 10 Examining Data ...
Page 112: ...102 Chapter 12 Tracepoints ...
Page 118: ...108 Chapter 13 Debugging Programs That Use Overlays ...
Page 138: ...128 Chapter 14 Using gdb with Different Languages ...
Page 144: ...134 Chapter 15 Examining the Symbol Table ...
Page 170: ...160 Chapter 19 Debugging remote programs ...
Page 198: ...188 Chapter 21 Controlling gdb ...
Page 204: ...194 Chapter 22 Canned Sequences of Commands ...
Page 206: ...196 Chapter 23 Command Interpreters ...
Page 216: ...206 Chapter 25 Using gdb under gnu Emacs ...
Page 296: ...286 Chapter 27 gdb Annotations ...
Page 300: ...290 Chapter 28 Reporting Bugs in gdb ...
Page 322: ...312 Chapter 30 Using History Interactively ...
Page 362: ...352 Appendix D gdb Remote Serial Protocol ...
Page 380: ...370 Appendix F GNU GENERAL PUBLIC LICENSE ...
Page 386: ...376 Appendix G GNU Free Documentation License ...
Page 410: ......