Sometimes gdb prints "incomplete type" for some type of variables. What does this mean and how can we see that value?
The ptype [ARG] command will print the type. Show activity on this post. This question may be related: vtable in polymorphic class of C++ using gdb: (gdb) help set print object Set printing of object's derived type based on vtable info.
0x0 refers the the address at 0 a.k.a NULL . This means there is no object at that location and trying to access anything at that address will likely result in a segmentation fault.
Print settings. GDB provides the following ways to control how arrays, structures, and symbols are printed. You can use `set print address off' to eliminate all machine dependent displays from the GDB interface.
It means that the type of that variable has been incompletely specified. For example:
struct hatstand; struct hatstand *foo;
GDB knows that foo
is a pointer to a hatstand
structure, but the members of that structure haven't been defined. Hence, "incomplete type".
To print the value, you can cast it to a compatible type.
For example, if you know that foo
is really a pointer to a lampshade
structure:
print (struct lampshade *)foo
Or, you could print it as a generic pointer, or treat it as if it were an integer:
print (void *)foo print (int)foo
See also these pages from the GDB manual:
What I've found is that if you disassemble a function that uses the incomplete struct type gdb 'discovers' the struct members and can subsequently display them. For example, say you have a string struct:
struct my_string { char * _string, int _size } ;
some functions to create and get the string via pointer:
my_string * create_string(const char *) {...} const char * get_string(my_string *){...}
and a test that creates a string:
int main(int argc, char *argv[]) { my_string *str = create_string("Hello World!") ; printf("String value: %s\n", get_string(str)) ; ... }
Run it in gdb and try to 'print *str' and you'll get an 'incomplete type' response. However, try 'disassemble get_string' and then 'print *str' and it'll display the struct and values properly. I have no idea why this works, but it does.
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