8.4 Simple Class Definition

The stabs describing C++ language features are an extension of the stabs describing C. Stabs representing C++ class types elaborate extensively on the stab format used to describe structure types in C. Stabs representing class type variables look just like stabs representing C language variables.

Consider the following very simple class definition.

     class baseA {
     public:
             int Adat;
             int Ameth(int in, char other);
     };

The class baseA is represented by two stabs. The first stab describes the class as a structure type. The second stab describes a structure tag of the class type. Both stabs are of stab type N_LSYM. Since the stab is not located between an N_FUN and an N_LBRAC stab this indicates that the class is defined at file scope. If it were, then the N_LSYM would signify a local variable.

A stab describing a C++ class type is similar in format to a stab describing a C struct, with each class member shown as a field in the structure. The part of the struct format describing fields is expanded to include extra information relevant to C++ class members. In addition, if the class has multiple base classes or virtual functions the struct format outside of the field parts is also augmented.

In this simple example the field part of the C++ class stab representing member data looks just like the field part of a C struct stab. The section on protections describes how its format is sometimes extended for member data.

The field part of a C++ class stab representing a member function differs substantially from the field part of a C struct stab. It still begins with name: but then goes on to define a new type number for the member function, describe its return type, its argument types, its protection level, any qualifiers applied to the method definition, and whether the method is virtual or not. If the method is virtual then the method description goes on to give the vtable index of the method, and the type number of the first base class defining the method.

When the field name is a method name it is followed by two colons rather than one. This is followed by a new type definition for the method. This is a number followed by an equal sign and the type of the method. Normally this will be a type declared using the # type descriptor; see Method Type Descriptor; static member functions are declared using the f type descriptor instead; see Function Types.

The format of an overloaded operator method name differs from that of other methods. It is op$::operator-name. where operator-name is the operator name such as + or +=. The name ends with a period, and any characters except the period can occur in the operator-name string.

The next part of the method description represents the arguments to the method, preceded by a colon and ending with a semi-colon. The types of the arguments are expressed in the same way argument types are expressed in C++ name mangling. In this example an int and a char map to ic.

This is followed by a number, a letter, and an asterisk or period, followed by another semicolon. The number indicates the protections that apply to the member function. Here the 2 means public. The letter encodes any qualifier applied to the method definition. In this case, A means that it is a normal function definition. The dot shows that the method is not virtual. The sections that follow elaborate further on these fields and describe the additional information present for virtual methods.

     .stabs "class_name:sym_desc(type)type_def(20)=type_desc(struct)struct_bytes(4)
             field_name(Adat):type(int),bit_offset(0),field_bits(32);
     
             method_name(Ameth)::type_def(21)=type_desc(method)return_type(int);
             :arg_types(int char);
             protection(public)qualifier(normal)virtual(no);;"
             N_LSYM,NIL,NIL,NIL
     .stabs "baseA:t20=s4Adat:1,0,32;Ameth::21=##1;:ic;2A.;;",128,0,0,0
     
     .stabs "class_name:sym_desc(struct tag)",N_LSYM,NIL,NIL,NIL
     
     .stabs "baseA:T20",128,0,0,0