Next: , Previous: Member Type Descriptor, Up: Cplusplus   [Contents][Index]


8.9 Protections

In the simple class definition shown above all member data and functions were publicly accessible. The example that follows contrasts public, protected and privately accessible fields and shows how these protections are encoded in C++ stabs.

If the character following the ‘field-name:’ part of the string is ‘/’, then the next character is the visibility. ‘0’ means private, ‘1’ means protected, and ‘2’ means public. Debuggers should ignore visibility characters they do not recognize, and assume a reasonable default (such as public) (GDB 4.11 does not, but this should be fixed in the next GDB release). If no visibility is specified the field is public. The visibility ‘9’ means that the field has been optimized out and is public (there is no way to specify an optimized out field with a private or protected visibility). Visibility ‘9’ is not supported by GDB 4.11; this should be fixed in the next GDB release.

The following C++ source:

class vis {
private:
        int   priv;
protected:
        char  prot;
public:
        float pub;
};

generates the following stab:

# 128 is N_LSYM
.stabs "vis:T19=s12priv:/01,0,32;prot:/12,32,8;pub:12,64,32;;",128,0,0,0

vis:T19=s12’ indicates that type number 19 is a 12 byte structure named vis The priv field has public visibility (‘/0’), type int (‘1’), and offset and size ‘,0,32;’. The prot field has protected visibility (‘/1’), type char (‘2’) and offset and size ‘,32,8;’. The pub field has type float (‘12’), and offset and size ‘,64,32;’.

Protections for member functions are signified by one digit embedded in the field part of the stab describing the method. The digit is 0 if private, 1 if protected and 2 if public. Consider the C++ class definition below:

class all_methods {
private:
        int   priv_meth(int in){return in;};
protected:
        char  protMeth(char in){return in;};
public:
        float pubMeth(float in){return in;};
};

It generates the following stab. The digit in question is to the left of an ‘A’ in each case. Notice also that in this case two symbol descriptors apply to the class name struct tag and struct type.

.stabs "class_name:sym_desc(struct tag&type)type_def(21)=
        sym_desc(struct)struct_bytes(1)
        meth_name::type_def(22)=sym_desc(method)returning(int);
        :args(int);protection(private)modifier(normal)virtual(no);
        meth_name::type_def(23)=sym_desc(method)returning(char);
        :args(char);protection(protected)modifier(normal)virtual(no);
        meth_name::type_def(24)=sym_desc(method)returning(float);
        :args(float);protection(public)modifier(normal)virtual(no);;",
        N_LSYM,NIL,NIL,NIL
.stabs "all_methods:Tt21=s1priv_meth::22=##1;:i;0A.;protMeth::23=##2;:c;1A.;
        pubMeth::24=##12;:f;2A.;;",128,0,0,0

Next: , Previous: Member Type Descriptor, Up: Cplusplus   [Contents][Index]