Search code examples
gdb

How to print <incomplete type> variable in gdb


Sometimes gdb prints "incomplete type" for some type of variables. What does this mean and how can we see that value?


Solution

  • 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: