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