c++gdb

Printing Sub-Class Members in GDB


Is there a setting in GDB that automatically prints all the members of a (C++) subclass from base-class pointer or do I always have to cast it to the sub-class pointer before dereferencing it.

That is I don't always want to do:

p *(SubClass*)baseClassInstance

Solution

  • set print object
    show print object
    
    Choose whether to print derived (actual) or declared types of objects. 
    

    I guess set print object is what you need but it works only for polymorphic types.

    https://sourceware.org/gdb/current/onlinedocs/gdb.html/Print-Settings.html