Next: , Previous: Virtual Methods, Up: Cplusplus

8.12 Inheritance

Stabs describing C++ derived classes include additional sections that describe the inheritance hierarchy of the class. A derived class stab also encodes the number of base classes. For each base class it tells if the base class is virtual or not, and if the inheritance is private or public. It also gives the offset into the object of the portion of the object corresponding to each base class.

This additional information is embedded in the class stab following the number of bytes in the struct. First the number of base classes appears bracketed by an exclamation point and a comma.

Then for each base type there repeats a series: a virtual character, a visibility character, a number, a comma, another number, and a semi-colon.

The virtual character is ‘1’ if the base class is virtual and ‘0’ if not. The visibility character is ‘2’ if the derivation is public, ‘1’ if it is protected, and ‘0’ if it is private. Debuggers should ignore virtual or visibility characters they do not recognize, and assume a reasonable default (such as public and non-virtual) (GDB 4.11 does not, but this should be fixed in the next GDB release).

The number following the virtual and visibility characters is the offset from the start of the object to the part of the object pertaining to the base class.

After the comma, the second number is a type_descriptor for the base type. Finally a semi-colon ends the series, which repeats for each base class.

The source below defines three base classes A, B, and C and the derived class D.

     class A {
             int Adat;
             virtual int A_virt (int arg) { return arg; };
     class B {
             int B_dat;
             virtual int B_virt (int arg) {return arg; };
     class C {
             int Cdat;
             virtual int C_virt (int arg) {return arg; };
     class D : A, virtual B, public C {
             int Ddat;
             virtual int A_virt (int arg ) { return arg+1; };
             virtual int B_virt (int arg)  { return arg+2; };
             virtual int C_virt (int arg)  { return arg+3; };
             virtual int D_virt (int arg)  { return arg; };

Class stabs similar to the ones described earlier are generated for each base class.

     .stabs "A:T20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;
     .stabs "B:Tt25=s8Bdat:1,0,32;$vf25:21,32;B_virt::26=##1;
     .stabs "C:Tt28=s8Cdat:1,0,32;$vf28:21,32;C_virt::29=##1;

In the stab describing derived class D below, the information about the derivation of this class is encoded as follows.

     .stabs "derived_class_name:symbol_descriptors(struct tag&type)=
             base_class_type_ref(C); ...
     .stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat: