Oracle® Solaris Studio 12.4: Debugging a Program With dbx

Exit Print View

Updated: January 2015
 
 

Printing C++ Pointers

In C++ an object pointer has two types: its static type (what is defined in the source code) and its dynamic type (what an object was before any casts were made to it). dbx can sometimes provide you with the information about the dynamic type of an object.

In general, when an object has a virtual function table (a vtable) in it, dbx can use the information in the vtable to correctly determine an object’s type.

You can use the print command, display command, or watch command with the -r (recursive) option. dbx displays all the data members directly defined by a class and those inherited from a base class.

These commands also take a -d or +d option that toggles the default behavior of the dbxenv variable output_dynamic_type.

Using the -d flag or setting the dbxenv variable output_dynamic_type to on when no process is running generates a program is not active error message. As when you are debugging a core file, accessing dynamic information is not possible when there is no process. An illegal cast on class pointers error message is generated if you try to find a dynamic type through a virtual inheritance. Casting from a virtual base class to a derived class is not legal in C++.