How does gdb know the pointer points to a int or struct or any other data types?
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;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With