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