Sun Studio 12 Update 1: Debugging a Program With dbx

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 dbx environment variable output_derived_type.

Using the -d flag or setting the dbx environment variable output_dynamic_type to on when there is no process running generates a “program is not active” error message because, as when you are debugging a core file, it is not possible to access dynamic information 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++.)