RIP gzip, we found a nicer playmate.
[dragonfly.git] / gnu / usr.bin / ld / symseg.h
1 /*-
2  *
3  * This code is derived from software copyrighted by the Free Software
4  * Foundation.
5  *
6  *      from: @(#)symseg.h      5.4 (Berkeley) 4/30/91
7  * $FreeBSD: src/gnu/usr.bin/ld/symseg.h,v 1.7 1999/08/27 23:36:02 peter Exp $
8  * $DragonFly: src/gnu/usr.bin/ld/Attic/symseg.h,v 1.2 2003/06/17 04:25:46 dillon Exp $
9  */
10
11 /* GDB symbol table format definitions.
12    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
13
14 This file is part of GNU CC.
15
16 GNU CC is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 1, or (at your option)
19 any later version.
20
21 GNU CC is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with GNU CC; see the file COPYING.  If not, write to
28 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
29
30 /* Format of GDB symbol table data.
31    There is one symbol segment for each source file or
32    independant compilation.  These segments are simply concatenated
33    to form the GDB symbol table.  A zero word where the beginning
34    of a segment is expected indicates there are no more segments.
35
36 Format of a symbol segment:
37
38    The symbol segment begins with a word containing 1
39    if it is in the format described here.  Other formats may
40    be designed, with other code numbers.
41
42    The segment contains many objects which point at each other.
43    The pointers are offsets in bytes from the beginning of the segment.
44    Thus, each segment can be loaded into core and its pointers relocated
45    to make valid in-core pointers.
46
47    All the data objects in the segment can be found indirectly from
48    one of them, the root object, of type `struct symbol_root'.
49    It appears at the beginning of the segment.
50
51    The total size of the segment, in bytes, appears as the `length'
52    field of this object.  This size includes the size of the
53    root object.
54
55    All the object data types are defined here to contain pointer types
56    appropriate for in-core use on a relocated symbol segment.
57    Casts to and from type int are required for working with
58    unrelocated symbol segments such as are found in the file.
59
60    The ldsymaddr word is filled in by the loader to contain
61    the offset (in bytes) within the ld symbol table
62    of the first nonglobal symbol from this compilation.
63    This makes it possible to match those symbols
64    (which contain line number information) reliably with
65    the segment they go with.
66
67    Core addresses within the program that appear in the symbol segment
68    are not relocated by the loader.  They are inserted by the assembler
69    and apply to addresses as output by the assembler, so GDB must
70    relocate them when it loads the symbol segment.  It gets the information
71    on how to relocate from the textrel, datarel, bssrel, databeg and bssbeg
72    words of the root object.
73
74    The words textrel, datarel and bssrel
75    are filled in by ld with the amounts to relocate within-the-file
76    text, data and bss addresses by; databeg and bssbeg can be
77    used to tell which kind of relocation an address needs.  */
78
79 enum language {language_c};
80
81 struct symbol_root
82 {
83   int format;                   /* Data format version */
84   int length;                   /* # bytes in this symbol segment */
85   int ldsymoff;                 /* Offset in ld symtab of this file's syms */
86   int textrel;                  /* Relocation for text addresses */
87   int datarel;                  /* Relocation for data addresses */
88   int bssrel;                   /* Relocation for bss addresses */
89   char *filename;               /* Name of main source file compiled */
90   char *filedir;                /* Name of directory it was reached from */
91   struct blockvector *blockvector; /* Vector of all symbol-naming blocks */
92   struct typevector *typevector; /* Vector of all data types */
93   enum language language;       /* Code identifying the language used */
94   char *version;                /* Version info.  Not fully specified */
95   char *compilation;            /* Compilation info.  Not fully specified */
96   int databeg;                  /* Address within the file of data start */
97   int bssbeg;                   /* Address within the file of bss start */
98   struct sourcevector *sourcevector; /* Vector of line-number info */
99 };
100 \f
101 /* All data types of symbols in the compiled program
102    are represented by `struct type' objects.
103    All of these objects are pointed to by the typevector.
104    The type vector may have empty slots that contain zero.  */
105
106 struct typevector
107 {
108   int length;                   /* Number of types described */
109   struct type *type[1];
110 };
111
112 /* Different kinds of data types are distinguished by the `code' field.  */
113
114 enum type_code
115 {
116   TYPE_CODE_UNDEF,              /* Not used; catches errors */
117   TYPE_CODE_PTR,                /* Pointer type */
118   TYPE_CODE_ARRAY,              /* Array type, lower bound zero */
119   TYPE_CODE_STRUCT,             /* C struct or Pascal record */
120   TYPE_CODE_UNION,              /* C union or Pascal variant part */
121   TYPE_CODE_ENUM,               /* Enumeration type */
122   TYPE_CODE_FUNC,               /* Function type */
123   TYPE_CODE_INT,                /* Integer type */
124   TYPE_CODE_FLT,                /* Floating type */
125   TYPE_CODE_VOID,               /* Void type (values zero length) */
126   TYPE_CODE_SET,                /* Pascal sets */
127   TYPE_CODE_RANGE,              /* Range (integers within spec'd bounds) */
128   TYPE_CODE_PASCAL_ARRAY,       /* Array with explicit type of index */
129 };
130
131 /* This appears in a type's flags word for an unsigned integer type.  */
132 #define TYPE_FLAG_UNSIGNED 1
133
134 /* Other flag bits are used with GDB.  */
135
136 struct type
137 {
138   /* Code for kind of type */
139   enum type_code code;
140   /* Name of this type, or zero if none.
141      This is used for printing only.
142      Type names specified as input are defined by symbols.  */
143   char *name;
144   /* Length in bytes of storage for a value of this type */
145   int length;
146   /* For a pointer type, describes the type of object pointed to.
147      For an array type, describes the type of the elements.
148      For a function type, describes the type of the value.
149      Unused otherwise.  */
150   struct type *target_type;
151   /* Type that is a pointer to this type.
152      Zero if no such pointer-to type is known yet.
153      The debugger may add the address of such a type
154      if it has to construct one later.  */
155   struct type *pointer_type;
156   /* Type that is a function returning this type.
157      Zero if no such function type is known here.
158      The debugger may add the address of such a type
159      if it has to construct one later.  */
160   struct type *function_type;
161   /* Flags about this type.  */
162   short flags;
163   /* Number of fields described for this type */
164   short nfields;
165   /* For structure and union types, a description of each field.
166      For set and pascal array types, there is one "field",
167      whose type is the domain type of the set or array.
168      For range types, there are two "fields",
169      the minimum and maximum values (both inclusive).
170      For enum types, each possible value is described by one "field".
171      For range types, there are two "fields", that record constant values
172      (inclusive) for the minimum and maximum.
173
174      Using a pointer to a separate array of fields
175      allows all types to have the same size, which is useful
176      because we can allocate the space for a type before
177      we know what to put in it.  */
178   struct field
179     {
180       /* Position of this field, counting in bits from start of
181          containing structure.  For a function type, this is the
182          position in the argument list of this argument.
183          For a range bound or enum value, this is the value itself.  */
184       int bitpos;
185       /* Size of this field, in bits, or zero if not packed.
186          For an unpacked field, the field's type's length
187          says how many bytes the field occupies.  */
188       int bitsize;
189       /* In a struct or enum type, type of this field.
190          In a function type, type of this argument.
191          In an array type, the domain-type of the array.  */
192       struct type *type;
193       /* Name of field, value or argument.
194          Zero for range bounds and array domains.  */
195       char *name;
196     } *fields;
197 };
198 \f
199 /* All of the name-scope contours of the program
200    are represented by `struct block' objects.
201    All of these objects are pointed to by the blockvector.
202
203    Each block represents one name scope.
204    Each lexical context has its own block.
205
206    The first two blocks in the blockvector are special.
207    The first one contains all the symbols defined in this compilation
208    whose scope is the entire program linked together.
209    The second one contains all the symbols whose scope is the
210    entire compilation excluding other separate compilations.
211    In C, these correspond to global symbols and static symbols.
212
213    Each block records a range of core addresses for the code that
214    is in the scope of the block.  The first two special blocks
215    give, for the range of code, the entire range of code produced
216    by the compilation that the symbol segment belongs to.
217
218    The blocks appear in the blockvector
219    in order of increasing starting-address,
220    and, within that, in order of decreasing ending-address.
221
222    This implies that within the body of one function
223    the blocks appear in the order of a depth-first tree walk.  */
224
225 struct blockvector
226 {
227   /* Number of blocks in the list.  */
228   int nblocks;
229   /* The blocks themselves.  */
230   struct block *block[1];
231 };
232
233 struct block
234 {
235   /* Addresses in the executable code that are in this block.
236      Note: in an unrelocated symbol segment in a file,
237      these are always zero.  They can be filled in from the
238      N_LBRAC and N_RBRAC symbols in the loader symbol table.  */
239   int startaddr, endaddr;
240   /* The symbol that names this block,
241      if the block is the body of a function;
242      otherwise, zero.
243      Note: In an unrelocated symbol segment in an object file,
244      this field may be zero even when the block has a name.
245      That is because the block is output before the name
246      (since the name resides in a higher block).
247      Since the symbol does point to the block (as its value),
248      it is possible to find the block and set its name properly.  */
249   struct symbol *function;
250   /* The `struct block' for the containing block, or 0 if none.  */
251   /* Note that in an unrelocated symbol segment in an object file
252      this pointer may be zero when the correct value should be
253      the second special block (for symbols whose scope is one compilation).
254      This is because the compiler ouptuts the special blocks at the
255      very end, after the other blocks.   */
256   struct block *superblock;
257   /* Number of local symbols.  */
258   int nsyms;
259   /* The symbols.  */
260   struct symbol *sym[1];
261 };
262 \f
263 /* Represent one symbol name; a variable, constant, function or typedef.  */
264
265 /* Different name spaces for symbols.  Looking up a symbol specifies
266    a namespace and ignores symbol definitions in other name spaces.
267
268    VAR_NAMESPACE is the usual namespace.
269    In C, this contains variables, function names, typedef names
270    and enum type values.
271
272    STRUCT_NAMESPACE is used in C to hold struct, union and enum type names.
273    Thus, if `struct foo' is used in a C program,
274    it produces a symbol named `foo' in the STRUCT_NAMESPACE.
275
276    LABEL_NAMESPACE may be used for names of labels (for gotos);
277    currently it is not used and labels are not recorded at all.  */
278
279 /* For a non-global symbol allocated statically,
280    the correct core address cannot be determined by the compiler.
281    The compiler puts an index number into the symbol's value field.
282    This index number can be matched with the "desc" field of
283    an entry in the loader symbol table.  */
284
285 enum namespace
286 {
287   UNDEF_NAMESPACE, VAR_NAMESPACE, STRUCT_NAMESPACE, LABEL_NAMESPACE,
288 };
289
290 /* An address-class says where to find the value of the symbol in core.  */
291
292 enum address_class
293 {
294   LOC_UNDEF,            /* Not used; catches errors */
295   LOC_CONST,            /* Value is constant int */
296   LOC_STATIC,           /* Value is at fixed address */
297   LOC_REGISTER,         /* Value is in register */
298   LOC_ARG,              /* Value is at spec'd position in arglist */
299   LOC_LOCAL,            /* Value is at spec'd pos in stack frame */
300   LOC_TYPEDEF,          /* Value not used; definition in SYMBOL_TYPE
301                            Symbols in the namespace STRUCT_NAMESPACE
302                            all have this class.  */
303   LOC_LABEL,            /* Value is address in the code */
304   LOC_BLOCK,            /* Value is address of a `struct block'.
305                            Function names have this class.  */
306   LOC_EXTERNAL,         /* Value is at address not in this compilation.
307                            This is used for .comm symbols
308                            and for extern symbols within functions.
309                            Inside GDB, this is changed to LOC_STATIC once the
310                            real address is obtained from a loader symbol.  */
311   LOC_CONST_BYTES       /* Value is a constant byte-sequence.   */
312 };
313
314 struct symbol
315 {
316   /* Symbol name */
317   char *name;
318   /* Name space code.  */
319   enum namespace namespace;
320   /* Address class */
321   enum address_class class;
322   /* Data type of value */
323   struct type *type;
324   /* constant value, or address if static, or register number,
325      or offset in arguments, or offset in stack frame.  */
326   union
327     {
328       long value;
329       struct block *block;      /* for LOC_BLOCK */
330       char *bytes;              /* for LOC_CONST_BYTES */
331     }
332   value;
333 };
334 \f
335 /* Source-file information.
336    This describes the relation between source files and line numbers
337    and addresses in the program text.  */
338
339 struct sourcevector
340 {
341   int length;                   /* Number of source files described */
342   struct source *source[1];     /* Descriptions of the files */
343 };
344
345 /* Line number and address of one line.  */
346
347 struct line
348 {
349   int linenum;
350   int address;
351 };
352
353 /* All the information on one source file.  */
354
355 struct source
356 {
357   char *name;                   /* Name of file */
358   int nlines;                   /* Number of lines that follow */
359   struct line lines[1]; /* Information on each line */
360 };