Displaying Virtual and Inherited Class Information

When you use the print command to display information on an instance of a derived class, the debugger displays both the new class members as well as the members inherited from a base class. Pointers to members of a class are not supported.

When you use the print command to display the contents of an instance of a C++ class, the class name (or structure/union name) is displayed at the top of the output. Data members of a class that are inherited from another class are commented using a double slash (//). Only those data members that are inherited within the current class being printed are commented.

The following example shows how the debugger uses C++ style comments to identify inherited class members. In the example, class Moon inherits from class Planet, which inherits from both class Orbit and class HeavenlyBody. When printing a class Moon object, the data member _distance is commented with "// class Planet::Orbit", signifying that it is inherited from class Planet which inherits it from class Orbit. The member _innerNeighbor is commented with "// class Planet::HeavenlyBody", showing that it is inherited from class Planet, which inherits it from class HeavenlyBody. This commenting is also provided for C++ structs.

(idb) print $usedynamictypes

1

(idb) whatis *this

class Moon : Planet {

  const Kilometers _radius;

  Moon(char*, Megameters, Kilometers, class Planet*);

  Kilometers radius(void) const;

  virtual void printBody(unsigned int) const;

  virtual ~Moon(void);

}

(idb) print *this

class Moon {

  _radius = 1738;

  _name = 0x805abe4="Moon";       // class Planet::HeavenlyBody

  _innerNeighbor = 0x0;           // class Planet::HeavenlyBody

  _outerNeighbor = 0x0;           // class Planet::HeavenlyBody

  _firstSatellite = 0x0;          // class Planet::HeavenlyBody

  _lastSatellite = 0x0;           // class Planet::HeavenlyBody

  _primary = 0x806b4e0;           // class Planet::Orbit

  _distance = 384;                // class Planet::Orbit

  _name = 0x806b5c0="Earth 1";    // class Planet::Orbit

}

If two members in an object have the same name but different base class types (multiple inheritance), you can refer to the members using the following syntax:

object.class::member

or

object->class::member

This syntax is more effective than using the object.member and object->member syntaxes, which can be ambiguous. In all cases, the debugger uses the C++ language rules as defined in The Annotated C++ Reference Manual to determine which member you are specifying.

The following example shows a case in which the expanded syntax can be used:

(idb) print *jupiter

class Planet {

  _name = 0x805a50c="Jupiter";    // class HeavenlyBody

  _innerNeighbor = 0x8067788;     // class HeavenlyBody

  _outerNeighbor = 0x8067aa0;     // class HeavenlyBody

  _firstSatellite = 0x80678e8;    // class HeavenlyBody

  _lastSatellite = 0x8067a48;     // class HeavenlyBody

  _primary = 0x8067550;           // class Orbit

  _distance = 778330;             // class Orbit

  _name = 0x80678c0="Sol 5";      // class Orbit

}

(idb) print jupiter->_name

Overloaded Values

0x80678c0="Sol 5"

0x805a50c="Jupiter"

(idb) print jupiter->HeavenlyBody::_name

0x805a50c="Jupiter"

(idb) print jupiter->Orbit::_name

0x80678c0="Sol 5"