STABS: Arrays |
---|
Arrays use the ‘a’ type descriptor. Following the type descriptor is the type of the index and the type of the array elements. If the index type is a range type, it ends in a semicolon; otherwise (for example, if it is a type reference), there does not appear to be any way to tell where the types are separated. In an effort to clean up this mess, IBM documents the two types as being separated by a semicolon, and a range type as not ending in a semicolon (but this is not right for range types which are not array indexes, see Subranges). I think probably the best solution is to specify that a semicolon ends a range type, and that the index type and element type of an array are separated by a semicolon, but that if the index type is a range type, the extra semicolon can be omitted. GDB (at least through version 4.9) doesn’t support any kind of index type other than a range anyway; I’m not sure about dbx.
It is well established, and widely used, that the type of the index, unlike most types found in the stabs, is merely a type definition, not type information (see String Field) (that is, it need not start with ‘ type-number=’ if it is defining a new type). According to a comment in GDB, this is also true of the type of the array elements; it gives ‘ar1;1;10;ar1;1;10;4’ as a legitimate way to express a two dimensional array. According to AIX documentation, the element type must be type information. GDB accepts either.
The type of the index is often a range type, expressed as the type descriptor ‘r’ and some parameters. It defines the size of the array. In the example below, the range ‘r1;0;2;’ defines an index type which is a subrange of type 1 (integer), with a lower bound of 0 and an upper bound of 2. This defines the valid range of subscripts of a three-element C array.
For example, the definition:
char char_vec[3] = {'a','b','c'};
produces the output:
.stabs "char_vec:G19=ar1;0;2;2",32,0,0,0 .global _char_vec .align 4 _char_vec: .byte 97 .byte 98 .byte 99
If an array is packed, the elements are spaced more closely than normal, saving memory at the expense of speed. For example, an array of 3-byte objects might, if unpacked, have each element aligned on a 4-byte boundary, but if packed, have no padding. One way to specify that something is packed is with type attributes (see String Field). In the case of arrays, another is to use the ‘P’ type descriptor instead of ‘a’. Other than specifying a packed array, ‘P’ is identical to ‘a’.
An open array is represented by the ‘A’ type descriptor followed by type information specifying the type of the array elements.
An N-dimensional dynamic array is represented by
D dimensions ; type-information
dimensions is the number of dimensions; type-information specifies the type of the array elements.
A subarray of an N-dimensional array is represented by
E dimensions ; type-information
dimensions is the number of dimensions; type-information specifies the type of the array elements.