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