7b4ac7e1 |
1 | /* GDB symbol table format definitions. |
4187119d |
2 | Copyright (C) 1986, 1989 Free Software Foundation, Inc. |
bb7592f0 |
3 | Hacked by Michael Tiemann (tiemann@mcc.com) |
7b4ac7e1 |
4 | |
4187119d |
5 | This file is part of GDB. |
7b4ac7e1 |
6 | |
4187119d |
7 | GDB is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 1, or (at your option) |
10 | any later version. |
7b4ac7e1 |
11 | |
4187119d |
12 | GDB is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU General Public License |
18 | along with GDB; see the file COPYING. If not, write to |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
7b4ac7e1 |
20 | |
21 | /* Format of GDB symbol table data. |
22 | There is one symbol segment for each source file or |
23 | independant compilation. These segments are simply concatenated |
24 | to form the GDB symbol table. A zero word where the beginning |
25 | of a segment is expected indicates there are no more segments. |
26 | |
27 | Format of a symbol segment: |
28 | |
29 | The symbol segment begins with a word containing 1 |
30 | if it is in the format described here. Other formats may |
31 | be designed, with other code numbers. |
32 | |
33 | The segment contains many objects which point at each other. |
34 | The pointers are offsets in bytes from the beginning of the segment. |
35 | Thus, each segment can be loaded into core and its pointers relocated |
36 | to make valid in-core pointers. |
37 | |
38 | All the data objects in the segment can be found indirectly from |
39 | one of them, the root object, of type `struct symbol_root'. |
40 | It appears at the beginning of the segment. |
41 | |
42 | The total size of the segment, in bytes, appears as the `length' |
43 | field of this object. This size includes the size of the |
44 | root object. |
45 | |
46 | All the object data types are defined here to contain pointer types |
47 | appropriate for in-core use on a relocated symbol segment. |
48 | Casts to and from type int are required for working with |
49 | unrelocated symbol segments such as are found in the file. |
50 | |
51 | The ldsymaddr word is filled in by the loader to contain |
52 | the offset (in bytes) within the ld symbol table |
53 | of the first nonglobal symbol from this compilation. |
54 | This makes it possible to match those symbols |
55 | (which contain line number information) reliably with |
56 | the segment they go with. |
57 | |
58 | Core addresses within the program that appear in the symbol segment |
59 | are not relocated by the loader. They are inserted by the assembler |
60 | and apply to addresses as output by the assembler, so GDB must |
61 | relocate them when it loads the symbol segment. It gets the information |
62 | on how to relocate from the textrel, datarel, bssrel, databeg and bssbeg |
63 | words of the root object. |
64 | |
65 | The words textrel, datarel and bssrel |
66 | are filled in by ld with the amounts to relocate within-the-file |
67 | text, data and bss addresses by; databeg and bssbeg can be |
68 | used to tell which kind of relocation an address needs. */ |
69 | |
70 | enum language {language_c}; |
71 | |
72 | struct symbol_root |
73 | { |
74 | int format; /* Data format version */ |
75 | int length; /* # bytes in this symbol segment */ |
76 | int ldsymoff; /* Offset in ld symtab of this file's syms */ |
77 | int textrel; /* Relocation for text addresses */ |
78 | int datarel; /* Relocation for data addresses */ |
79 | int bssrel; /* Relocation for bss addresses */ |
632ea0cc |
80 | char *filename; /* Name of main source file compiled */ |
7b4ac7e1 |
81 | char *filedir; /* Name of directory it was reached from */ |
632ea0cc |
82 | struct blockvector *blockvector; /* Vector of all symbol-naming blocks */ |
7b4ac7e1 |
83 | struct typevector *typevector; /* Vector of all data types */ |
84 | enum language language; /* Code identifying the language used */ |
85 | char *version; /* Version info. Not fully specified */ |
86 | char *compilation; /* Compilation info. Not fully specified */ |
87 | int databeg; /* Address within the file of data start */ |
88 | int bssbeg; /* Address within the file of bss start */ |
632ea0cc |
89 | struct sourcevector *sourcevector; /* Vector of line-number info */ |
7b4ac7e1 |
90 | }; |
91 | \f |
92 | /* All data types of symbols in the compiled program |
93 | are represented by `struct type' objects. |
94 | All of these objects are pointed to by the typevector. |
95 | The type vector may have empty slots that contain zero. */ |
96 | |
97 | struct typevector |
98 | { |
632ea0cc |
99 | int length; /* Number of types described */ |
7b4ac7e1 |
100 | struct type *type[1]; |
101 | }; |
102 | |
103 | /* Different kinds of data types are distinguished by the `code' field. */ |
104 | |
105 | enum type_code |
106 | { |
107 | TYPE_CODE_UNDEF, /* Not used; catches errors */ |
108 | TYPE_CODE_PTR, /* Pointer type */ |
109 | TYPE_CODE_ARRAY, /* Array type, lower bound zero */ |
110 | TYPE_CODE_STRUCT, /* C struct or Pascal record */ |
111 | TYPE_CODE_UNION, /* C union or Pascal variant part */ |
112 | TYPE_CODE_ENUM, /* Enumeration type */ |
113 | TYPE_CODE_FUNC, /* Function type */ |
114 | TYPE_CODE_INT, /* Integer type */ |
115 | TYPE_CODE_FLT, /* Floating type */ |
116 | TYPE_CODE_VOID, /* Void type (values zero length) */ |
117 | TYPE_CODE_SET, /* Pascal sets */ |
118 | TYPE_CODE_RANGE, /* Range (integers within spec'd bounds) */ |
119 | TYPE_CODE_PASCAL_ARRAY, /* Array with explicit type of index */ |
bb7592f0 |
120 | |
121 | /* C++ */ |
122 | TYPE_CODE_MEMBER, /* Member type */ |
4187119d |
123 | TYPE_CODE_METHOD, /* Method type */ |
bb7592f0 |
124 | TYPE_CODE_REF, /* C++ Reference types */ |
7b4ac7e1 |
125 | }; |
126 | |
127 | /* This appears in a type's flags word for an unsigned integer type. */ |
128 | #define TYPE_FLAG_UNSIGNED 1 |
4187119d |
129 | /* This appears in a type's flags word |
130 | if it is a (pointer to a|function returning a)* built in scalar type. |
131 | These types are never freed. */ |
132 | #define TYPE_FLAG_PERM 4 |
133 | /* This appears in a type's flags word if it is a stub type (eg. if |
134 | someone referenced a type that wasn't definined in a source file |
135 | via (struct sir_not_appearing_in_this_film *)). */ |
136 | #define TYPE_FLAG_STUB 8 |
137 | /* Set when a class has a constructor defined */ |
e91b87a3 |
138 | #define TYPE_FLAG_HAS_CONSTRUCTOR 256 |
4187119d |
139 | /* Set when a class has a destructor defined */ |
e91b87a3 |
140 | #define TYPE_FLAG_HAS_DESTRUCTOR 512 |
4187119d |
141 | /* Indicates that this type is a public baseclass of another class, |
142 | i.e. that all its public methods are available in the derived |
143 | class. */ |
e91b87a3 |
144 | #define TYPE_FLAG_VIA_PUBLIC 1024 |
4187119d |
145 | /* Indicates that this type is a virtual baseclass of another class, |
146 | i.e. that if this class is inherited more than once by another |
147 | class, only one set of member variables will be included. */ |
e91b87a3 |
148 | #define TYPE_FLAG_VIA_VIRTUAL 2048 |
bb7592f0 |
149 | |
7b4ac7e1 |
150 | struct type |
151 | { |
152 | /* Code for kind of type */ |
153 | enum type_code code; |
154 | /* Name of this type, or zero if none. |
155 | This is used for printing only. |
156 | Type names specified as input are defined by symbols. */ |
157 | char *name; |
158 | /* Length in bytes of storage for a value of this type */ |
159 | int length; |
160 | /* For a pointer type, describes the type of object pointed to. |
161 | For an array type, describes the type of the elements. |
4187119d |
162 | For a function or method type, describes the type of the value. |
e91b87a3 |
163 | For a range type, describes the type of the full range. |
7b4ac7e1 |
164 | Unused otherwise. */ |
165 | struct type *target_type; |
166 | /* Type that is a pointer to this type. |
167 | Zero if no such pointer-to type is known yet. |
168 | The debugger may add the address of such a type |
169 | if it has to construct one later. */ |
170 | struct type *pointer_type; |
bb7592f0 |
171 | /* C++: also need a reference type. */ |
172 | struct type *reference_type; |
4187119d |
173 | struct type **arg_types; |
174 | |
7b4ac7e1 |
175 | /* Type that is a function returning this type. |
176 | Zero if no such function type is known here. |
177 | The debugger may add the address of such a type |
178 | if it has to construct one later. */ |
179 | struct type *function_type; |
bb7592f0 |
180 | |
181 | /* Handling of pointers to members: |
e91b87a3 |
182 | TYPE_MAIN_VARIANT is used for pointer and pointer |
bb7592f0 |
183 | to member types. Normally it the value of the address of its |
184 | containing type. However, for pointers to members, we must be |
185 | able to allocate pointer to member types and look them up |
186 | from some place of reference. |
e91b87a3 |
187 | NEXT_VARIANT is the next element in the chain. */ |
bb7592f0 |
188 | struct type *main_variant, *next_variant; |
189 | |
7b4ac7e1 |
190 | /* Flags about this type. */ |
191 | short flags; |
192 | /* Number of fields described for this type */ |
193 | short nfields; |
194 | /* For structure and union types, a description of each field. |
195 | For set and pascal array types, there is one "field", |
196 | whose type is the domain type of the set or array. |
197 | For range types, there are two "fields", |
198 | the minimum and maximum values (both inclusive). |
199 | For enum types, each possible value is described by one "field". |
7b4ac7e1 |
200 | |
201 | Using a pointer to a separate array of fields |
202 | allows all types to have the same size, which is useful |
203 | because we can allocate the space for a type before |
204 | we know what to put in it. */ |
205 | struct field |
206 | { |
207 | /* Position of this field, counting in bits from start of |
208 | containing structure. For a function type, this is the |
209 | position in the argument list of this argument. |
210 | For a range bound or enum value, this is the value itself. */ |
211 | int bitpos; |
212 | /* Size of this field, in bits, or zero if not packed. |
213 | For an unpacked field, the field's type's length |
214 | says how many bytes the field occupies. */ |
215 | int bitsize; |
216 | /* In a struct or enum type, type of this field. |
217 | In a function type, type of this argument. |
218 | In an array type, the domain-type of the array. */ |
219 | struct type *type; |
220 | /* Name of field, value or argument. |
221 | Zero for range bounds and array domains. */ |
222 | char *name; |
223 | } *fields; |
bb7592f0 |
224 | |
225 | /* C++ */ |
226 | int *private_field_bits; |
227 | int *protected_field_bits; |
228 | |
229 | /* Number of methods described for this type */ |
230 | short nfn_fields; |
e91b87a3 |
231 | /* Number of base classes this type derives from. */ |
bb7592f0 |
232 | short n_baseclasses; |
233 | |
234 | /* Number of methods described for this type plus all the |
235 | methods that it derives from. */ |
236 | int nfn_fields_total; |
237 | |
238 | /* For classes, structures, and unions, a description of each field, |
239 | which consists of an overloaded name, followed by the types of |
240 | arguments that the method expects, and then the name after it |
4187119d |
241 | has been renamed to make it distinct. */ |
bb7592f0 |
242 | struct fn_fieldlist |
243 | { |
244 | /* The overloaded name. */ |
245 | char *name; |
246 | /* The number of methods with this name. */ |
247 | int length; |
248 | /* The list of methods. */ |
249 | struct fn_field |
250 | { |
251 | #if 0 |
252 | /* The overloaded name */ |
253 | char *name; |
254 | #endif |
4187119d |
255 | /* The return value of the method */ |
bb7592f0 |
256 | struct type *type; |
257 | /* The argument list */ |
258 | struct type **args; |
259 | /* The name after it has been processed */ |
260 | char *physname; |
261 | /* If this is a virtual function, the offset into the vtbl-1, |
262 | else 0. */ |
263 | int voffset; |
264 | } *fn_fields; |
265 | |
266 | int *private_fn_field_bits; |
267 | int *protected_fn_field_bits; |
268 | |
269 | } *fn_fieldlists; |
270 | |
e91b87a3 |
271 | unsigned char via_protected; |
272 | unsigned char via_public; |
273 | |
bb7592f0 |
274 | /* For types with virtual functions, VPTR_BASETYPE is the base class which |
275 | defined the virtual function table pointer. VPTR_FIELDNO is |
276 | the field number of that pointer in the structure. |
277 | |
278 | For types that are pointer to member types, VPTR_BASETYPE |
279 | ifs the type that this pointer is a member of. |
280 | |
281 | Unused otherwise. */ |
282 | struct type *vptr_basetype; |
283 | |
284 | int vptr_fieldno; |
285 | |
e91b87a3 |
286 | /* If this type has a base class, put it here. |
287 | If this type is a pointer type, the chain of member pointer |
288 | types goes here. |
7a67dd45 |
289 | Unused otherwise. |
290 | |
291 | Contrary to all maxims of C style and common sense, the baseclasses |
292 | are indexed from 1 to N_BASECLASSES rather than 0 to N_BASECLASSES-1 |
293 | (i.e. BASECLASSES points to one *before* the first element of |
294 | the array). */ |
bb7592f0 |
295 | struct type **baseclasses; |
7b4ac7e1 |
296 | }; |
297 | \f |
298 | /* All of the name-scope contours of the program |
299 | are represented by `struct block' objects. |
300 | All of these objects are pointed to by the blockvector. |
301 | |
302 | Each block represents one name scope. |
303 | Each lexical context has its own block. |
304 | |
305 | The first two blocks in the blockvector are special. |
306 | The first one contains all the symbols defined in this compilation |
307 | whose scope is the entire program linked together. |
308 | The second one contains all the symbols whose scope is the |
309 | entire compilation excluding other separate compilations. |
310 | In C, these correspond to global symbols and static symbols. |
311 | |
312 | Each block records a range of core addresses for the code that |
313 | is in the scope of the block. The first two special blocks |
314 | give, for the range of code, the entire range of code produced |
315 | by the compilation that the symbol segment belongs to. |
316 | |
317 | The blocks appear in the blockvector |
318 | in order of increasing starting-address, |
319 | and, within that, in order of decreasing ending-address. |
320 | |
321 | This implies that within the body of one function |
322 | the blocks appear in the order of a depth-first tree walk. */ |
323 | |
324 | struct blockvector |
325 | { |
326 | /* Number of blocks in the list. */ |
327 | int nblocks; |
328 | /* The blocks themselves. */ |
329 | struct block *block[1]; |
330 | }; |
331 | |
332 | struct block |
333 | { |
334 | /* Addresses in the executable code that are in this block. |
335 | Note: in an unrelocated symbol segment in a file, |
336 | these are always zero. They can be filled in from the |
337 | N_LBRAC and N_RBRAC symbols in the loader symbol table. */ |
338 | int startaddr, endaddr; |
339 | /* The symbol that names this block, |
340 | if the block is the body of a function; |
341 | otherwise, zero. |
342 | Note: In an unrelocated symbol segment in an object file, |
343 | this field may be zero even when the block has a name. |
344 | That is because the block is output before the name |
345 | (since the name resides in a higher block). |
346 | Since the symbol does point to the block (as its value), |
347 | it is possible to find the block and set its name properly. */ |
348 | struct symbol *function; |
349 | /* The `struct block' for the containing block, or 0 if none. */ |
350 | /* Note that in an unrelocated symbol segment in an object file |
351 | this pointer may be zero when the correct value should be |
352 | the second special block (for symbols whose scope is one compilation). |
353 | This is because the compiler ouptuts the special blocks at the |
354 | very end, after the other blocks. */ |
355 | struct block *superblock; |
e91b87a3 |
356 | /* A flag indicating whether or not the fucntion corresponding |
357 | to this block was compiled with gcc or not. If there is no |
358 | function corresponding to this block, this meaning of this flag |
359 | is undefined. (In practice it will be 1 if the block was created |
360 | while processing a file compiled with gcc and 0 when not). */ |
361 | unsigned char gcc_compile_flag; |
7b4ac7e1 |
362 | /* Number of local symbols. */ |
363 | int nsyms; |
364 | /* The symbols. */ |
365 | struct symbol *sym[1]; |
366 | }; |
367 | \f |
368 | /* Represent one symbol name; a variable, constant, function or typedef. */ |
369 | |
370 | /* Different name spaces for symbols. Looking up a symbol specifies |
371 | a namespace and ignores symbol definitions in other name spaces. |
372 | |
373 | VAR_NAMESPACE is the usual namespace. |
374 | In C, this contains variables, function names, typedef names |
375 | and enum type values. |
376 | |
377 | STRUCT_NAMESPACE is used in C to hold struct, union and enum type names. |
378 | Thus, if `struct foo' is used in a C program, |
379 | it produces a symbol named `foo' in the STRUCT_NAMESPACE. |
380 | |
381 | LABEL_NAMESPACE may be used for names of labels (for gotos); |
382 | currently it is not used and labels are not recorded at all. */ |
383 | |
384 | /* For a non-global symbol allocated statically, |
385 | the correct core address cannot be determined by the compiler. |
386 | The compiler puts an index number into the symbol's value field. |
387 | This index number can be matched with the "desc" field of |
388 | an entry in the loader symbol table. */ |
389 | |
390 | enum namespace |
391 | { |
392 | UNDEF_NAMESPACE, VAR_NAMESPACE, STRUCT_NAMESPACE, LABEL_NAMESPACE, |
393 | }; |
394 | |
395 | /* An address-class says where to find the value of the symbol in core. */ |
396 | |
397 | enum address_class |
398 | { |
399 | LOC_UNDEF, /* Not used; catches errors */ |
400 | LOC_CONST, /* Value is constant int */ |
401 | LOC_STATIC, /* Value is at fixed address */ |
402 | LOC_REGISTER, /* Value is in register */ |
403 | LOC_ARG, /* Value is at spec'd position in arglist */ |
4187119d |
404 | LOC_REF_ARG, /* Value address is at spec'd position in */ |
405 | /* arglist. */ |
e91b87a3 |
406 | LOC_REGPARM, /* Value is at spec'd position in register window */ |
7b4ac7e1 |
407 | LOC_LOCAL, /* Value is at spec'd pos in stack frame */ |
408 | LOC_TYPEDEF, /* Value not used; definition in SYMBOL_TYPE |
409 | Symbols in the namespace STRUCT_NAMESPACE |
410 | all have this class. */ |
411 | LOC_LABEL, /* Value is address in the code */ |
412 | LOC_BLOCK, /* Value is address of a `struct block'. |
413 | Function names have this class. */ |
414 | LOC_EXTERNAL, /* Value is at address not in this compilation. |
415 | This is used for .comm symbols |
416 | and for extern symbols within functions. |
417 | Inside GDB, this is changed to LOC_STATIC once the |
418 | real address is obtained from a loader symbol. */ |
419 | LOC_CONST_BYTES /* Value is a constant byte-sequence. */ |
420 | }; |
421 | |
422 | struct symbol |
423 | { |
424 | /* Symbol name */ |
425 | char *name; |
426 | /* Name space code. */ |
427 | enum namespace namespace; |
428 | /* Address class */ |
429 | enum address_class class; |
430 | /* Data type of value */ |
431 | struct type *type; |
432 | /* constant value, or address if static, or register number, |
433 | or offset in arguments, or offset in stack frame. */ |
434 | union |
435 | { |
436 | long value; |
437 | struct block *block; /* for LOC_BLOCK */ |
438 | char *bytes; /* for LOC_CONST_BYTES */ |
439 | } |
440 | value; |
441 | }; |
e91b87a3 |
442 | |
443 | struct partial_symbol |
444 | { |
445 | /* Symbol name */ |
446 | char *name; |
447 | /* Name space code. */ |
448 | enum namespace namespace; |
449 | /* Address class (for info_symbols) */ |
450 | enum address_class class; |
4187119d |
451 | /* Value (only used for static functions currently). Done this |
7a67dd45 |
452 | way so that we can use the struct symbol macros. |
453 | Note that the address of a function is SYMBOL_VALUE (pst) |
454 | in a partial symbol table, but BLOCK_START (SYMBOL_BLOCK_VALUE (st)) |
455 | in a symbol table. */ |
4187119d |
456 | union |
457 | { |
458 | long value; |
459 | } |
460 | value; |
e91b87a3 |
461 | }; |
462 | |
463 | /* |
464 | * Vectors of all partial symbols read in from file; actually declared |
465 | * and used in dbxread.c. |
466 | */ |
4187119d |
467 | extern struct psymbol_allocation_list { |
468 | struct partial_symbol *list, *next; |
469 | int size; |
470 | } global_psymbols, static_psymbols; |
e91b87a3 |
471 | |
632ea0cc |
472 | \f |
473 | /* Source-file information. |
474 | This describes the relation between source files and line numbers |
475 | and addresses in the program text. */ |
476 | |
477 | struct sourcevector |
478 | { |
479 | int length; /* Number of source files described */ |
480 | struct source *source[1]; /* Descriptions of the files */ |
481 | }; |
482 | |
e91b87a3 |
483 | /* Each item represents a line-->pc (or the reverse) mapping. This is |
484 | somewhat more wasteful of space than one might wish, but since only |
485 | the files which are actually debugged are read in to core, we don't |
486 | waste much space. |
487 | |
488 | Each item used to be an int; either minus a line number, or a |
489 | program counter. If it represents a line number, that is the line |
490 | described by the next program counter value. If it is positive, it |
491 | is the program counter at which the code for the next line starts. */ |
632ea0cc |
492 | |
e91b87a3 |
493 | struct linetable_entry |
494 | { |
495 | int line; |
496 | CORE_ADDR pc; |
497 | }; |
632ea0cc |
498 | |
499 | struct linetable |
e91b87a3 |
500 | { |
501 | int nitems; |
502 | struct linetable_entry item[1]; |
503 | }; |
632ea0cc |
504 | |
505 | /* All the information on one source file. */ |
506 | |
507 | struct source |
508 | { |
509 | char *name; /* Name of file */ |
510 | struct linetable contents; |
511 | }; |