Reputation: 997
How does gdb know the pointer points to a int
or struct
or any other data types?
Upvotes: 2
Views: 4276
Reputation: 2427
from: Examining the Symbol Table
whatis expr
Print the data type of expression expr. expr is not actually evaluated, and any side-effecting operations (such as assignments or function calls) inside it do not take place. See section Expressions.
ptype expr
ptype
Print a description of the type of expression expr. ptype differs from whatis by printing a detailed description, instead of just the name of the type. For example, for this variable declaration:
struct complex {double real; double imag;} v;
the two commands give this output:
(gdb) whatis v
type = struct complex
(gdb) ptype v
type = struct complex {
double real;
double imag;
}
Upvotes: 7
Reputation: 116
gdb
knows the type of a pointer variable in your code by reading the debugging information (a.k.a. symbol table) that's embedded in your executable when you compile with the debug option (-g
).
Upvotes: 1
Reputation: 19975
gdb can't know, unless the pointer came from a variable or expression for which the type can be determined.
If gdb is given 0x4567789, it has no idea what that might point to. But if an int *p has that value, gdb can deference that and give you what that address contains.
Upvotes: 4