Inheritance (STABS)

Next: Virtual Base Classes, Previous: Virtual Methods, Up: Cplusplus [Contents][Index]

### 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 {
    public:
            int Adat;
            virtual int A_virt (int arg) { return arg; };
    };

    class B {
    public:
            int B_dat;
            virtual int B_virt (int arg) {return arg; };
    };

    class C {
    public:
            int Cdat;
            virtual int C_virt (int arg) {return arg; };
    };

    class D : A, virtual B, public C {
    public:
            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;
            A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;",128,0,0,0

    .stabs "B:Tt25=s8Bdat:1,0,32;$vf25:21,32;B_virt::26=##1;
            :i;2A*-2147483647;25;;;~%25;",128,0,0,0

    .stabs "C:Tt28=s8Cdat:1,0,32;$vf28:21,32;C_virt::29=##1;
            :i;2A*-2147483647;28;;;~%28;",128,0,0,0

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)=
            type_descriptor(struct)struct_bytes(32)!num_bases(3),
            base_virtual(no)inheritance_public(no)base_offset(0),
            base_class_type_ref(A);
            base_virtual(yes)inheritance_public(no)base_offset(NIL),
            base_class_type_ref(B);
            base_virtual(no)inheritance_public(yes)base_offset(64),
            base_class_type_ref(C); …

    .stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:
            1,160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt:
            :32:i;2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;
            28;;D_virt::32:i;2A*-2147483646;31;;;~%20;",128,0,0,0

Next: Virtual Base Classes, Previous: Virtual Methods, Up: Cplusplus [Contents][Index]