Next: , Up: Checks

15.3.1 An Overview of Type Checking

Some languages, such as C and C++, 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 ever causing any run-time problems. For example,

     int klass::my_method(char *b) { return  b ? 1 : 2; }
     (gdb) print obj.my_method (0)
     $1 = 2

(gdb) print obj.my_method (0x1234) Cannot resolve method klass::my_method to any overloaded instance

The second example fails because in C++ the integer constant ‘0x1234’ is not type-compatible with the pointer parameter type.

For the expressions you use in gdb commands, you can tell gdb to not enforce strict type checking or to treat any mismatches as errors and abandon the expression; When type checking is disabled, gdb successfully evaluates expressions like the second example above.

Even if type checking is 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 which make little sense to evaluate anyway.

gdb provides some additional commands for controlling type checking:

set check type on
set check type off
Set strict type checking on or off. If any type mismatches occur in evaluating an expression while type checking is on, gdb prints a message and aborts evaluation of the expression.
show check type
Show the current setting of type checking and whether gdb is enforcing strict type checking rules.