Enumerations are defined with the ‘e’ type descriptor.
The source line below declares an enumeration type at file scope.
The type definition is located after the N_RBRAC
that marks the end of
the previous procedure's block scope, and before the N_FUN
that marks
the beginning of the next procedure's block scope. Therefore it does not
describe a block local symbol, but a file local one.
The source line:
enum e_places {first,second=3,last};
generates the following stab:
.stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
The symbol descriptor (‘T’) says that the stab describes a structure, enumeration, or union tag. The type descriptor ‘e’, following the ‘22=’ of the type definition narrows it down to an enumeration type. Following the ‘e’ is a list of the elements of the enumeration. The format is ‘name:value,’. The list of elements ends with ‘;’. The fact that value is specified as an integer can cause problems if the value is large. GCC 2.5.2 tries to output it in octal in that case with a leading zero, which is probably a good thing, although GDB 4.11 supports octal only in cases where decimal is perfectly good. Negative decimal values are supported by both GDB and dbx.
There is no standard way to specify the size of an enumeration type; it is determined by the architecture (normally all enumerations types are 32 bits). Type attributes can be used to specify an enumeration type of another size for debuggers which support them; see String Field.
Enumeration types are unusual in that they define symbols for the
enumeration values (first
, second
, and third
in the
above example), and even though these symbols are visible in the file as
a whole (rather than being in a more local namespace like structure
member names), they are defined in the type definition for the
enumeration type rather than each having their own symbol. In order to
be fast, GDB will only get symbols from such types (in its initial scan
of the stabs) if the type is the first thing defined after a ‘T’ or
‘t’ symbol descriptor (the above example fulfills this
requirement). If the type does not have a name, the compiler should
emit it in a nameless stab (see String Field); GCC does this.