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