|
|
1.1 root 1: /* GDB symbol table format definitions.
2: Copyright (C) 1986 Free Software Foundation, Inc.
3:
4: GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5: WARRANTY. No author or distributor accepts responsibility to anyone
6: for the consequences of using it or for whether it serves any
7: particular purpose or works at all, unless he says so in writing.
8: Refer to the GDB General Public License for full details.
9:
10: Everyone is granted permission to copy, modify and redistribute GDB,
11: but only under the conditions described in the GDB General Public
12: License. A copy of this license is supposed to have been given to you
13: along with GDB so you can know your rights and responsibilities. It
14: should be in a file named COPYING. Among other things, the copyright
15: notice and this notice must be preserved on all copies.
16:
17: In other words, go ahead and share GDB, but don't try to stop
18: anyone else from sharing it farther. Help stamp out software hoarding!
19: */
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 */
80: char *filename; /* Name of main source file compiled */
81: char *filedir; /* Name of directory it was reached from */
82: struct blockvector *blockvector; /* Vector of all symbol-naming blocks */
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 */
89: struct sourcevector *sourcevector; /* Vector of line-number info */
90: };
91:
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: {
99: int length; /* Number of types described */
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 */
120: };
121:
122: /* This appears in a type's flags word for an unsigned integer type. */
123: #define TYPE_FLAG_UNSIGNED 1
124:
125: /* Other flag bits are used with GDB. */
126:
127: struct type
128: {
129: /* Code for kind of type */
130: enum type_code code;
131: /* Name of this type, or zero if none.
132: This is used for printing only.
133: Type names specified as input are defined by symbols. */
134: char *name;
135: /* Length in bytes of storage for a value of this type */
136: int length;
137: /* For a pointer type, describes the type of object pointed to.
138: For an array type, describes the type of the elements.
139: For a function type, describes the type of the value.
140: Unused otherwise. */
141: struct type *target_type;
142: /* Type that is a pointer to this type.
143: Zero if no such pointer-to type is known yet.
144: The debugger may add the address of such a type
145: if it has to construct one later. */
146: struct type *pointer_type;
147: /* Type that is a function returning this type.
148: Zero if no such function type is known here.
149: The debugger may add the address of such a type
150: if it has to construct one later. */
151: struct type *function_type;
152: /* Flags about this type. */
153: short flags;
154: /* Number of fields described for this type */
155: short nfields;
156: /* For structure and union types, a description of each field.
157: For set and pascal array types, there is one "field",
158: whose type is the domain type of the set or array.
159: For range types, there are two "fields",
160: the minimum and maximum values (both inclusive).
161: For enum types, each possible value is described by one "field".
162: For range types, there are two "fields", that record constant values
163: (inclusive) for the minimum and maximum.
164:
165: Using a pointer to a separate array of fields
166: allows all types to have the same size, which is useful
167: because we can allocate the space for a type before
168: we know what to put in it. */
169: struct field
170: {
171: /* Position of this field, counting in bits from start of
172: containing structure. For a function type, this is the
173: position in the argument list of this argument.
174: For a range bound or enum value, this is the value itself. */
175: int bitpos;
176: /* Size of this field, in bits, or zero if not packed.
177: For an unpacked field, the field's type's length
178: says how many bytes the field occupies. */
179: int bitsize;
180: /* In a struct or enum type, type of this field.
181: In a function type, type of this argument.
182: In an array type, the domain-type of the array. */
183: struct type *type;
184: /* Name of field, value or argument.
185: Zero for range bounds and array domains. */
186: char *name;
187: } *fields;
188: };
189:
190: /* All of the name-scope contours of the program
191: are represented by `struct block' objects.
192: All of these objects are pointed to by the blockvector.
193:
194: Each block represents one name scope.
195: Each lexical context has its own block.
196:
197: The first two blocks in the blockvector are special.
198: The first one contains all the symbols defined in this compilation
199: whose scope is the entire program linked together.
200: The second one contains all the symbols whose scope is the
201: entire compilation excluding other separate compilations.
202: In C, these correspond to global symbols and static symbols.
203:
204: Each block records a range of core addresses for the code that
205: is in the scope of the block. The first two special blocks
206: give, for the range of code, the entire range of code produced
207: by the compilation that the symbol segment belongs to.
208:
209: The blocks appear in the blockvector
210: in order of increasing starting-address,
211: and, within that, in order of decreasing ending-address.
212:
213: This implies that within the body of one function
214: the blocks appear in the order of a depth-first tree walk. */
215:
216: struct blockvector
217: {
218: /* Number of blocks in the list. */
219: int nblocks;
220: /* The blocks themselves. */
221: struct block *block[1];
222: };
223:
224: struct block
225: {
226: /* Addresses in the executable code that are in this block.
227: Note: in an unrelocated symbol segment in a file,
228: these are always zero. They can be filled in from the
229: N_LBRAC and N_RBRAC symbols in the loader symbol table. */
230: int startaddr, endaddr;
231: /* The symbol that names this block,
232: if the block is the body of a function;
233: otherwise, zero.
234: Note: In an unrelocated symbol segment in an object file,
235: this field may be zero even when the block has a name.
236: That is because the block is output before the name
237: (since the name resides in a higher block).
238: Since the symbol does point to the block (as its value),
239: it is possible to find the block and set its name properly. */
240: struct symbol *function;
241: /* The `struct block' for the containing block, or 0 if none. */
242: /* Note that in an unrelocated symbol segment in an object file
243: this pointer may be zero when the correct value should be
244: the second special block (for symbols whose scope is one compilation).
245: This is because the compiler ouptuts the special blocks at the
246: very end, after the other blocks. */
247: struct block *superblock;
248: /* Number of local symbols. */
249: int nsyms;
250: /* The symbols. */
251: struct symbol *sym[1];
252: };
253:
254: /* Represent one symbol name; a variable, constant, function or typedef. */
255:
256: /* Different name spaces for symbols. Looking up a symbol specifies
257: a namespace and ignores symbol definitions in other name spaces.
258:
259: VAR_NAMESPACE is the usual namespace.
260: In C, this contains variables, function names, typedef names
261: and enum type values.
262:
263: STRUCT_NAMESPACE is used in C to hold struct, union and enum type names.
264: Thus, if `struct foo' is used in a C program,
265: it produces a symbol named `foo' in the STRUCT_NAMESPACE.
266:
267: LABEL_NAMESPACE may be used for names of labels (for gotos);
268: currently it is not used and labels are not recorded at all. */
269:
270: /* For a non-global symbol allocated statically,
271: the correct core address cannot be determined by the compiler.
272: The compiler puts an index number into the symbol's value field.
273: This index number can be matched with the "desc" field of
274: an entry in the loader symbol table. */
275:
276: enum namespace
277: {
278: UNDEF_NAMESPACE, VAR_NAMESPACE, STRUCT_NAMESPACE, LABEL_NAMESPACE,
279: };
280:
281: /* An address-class says where to find the value of the symbol in core. */
282:
283: enum address_class
284: {
285: LOC_UNDEF, /* Not used; catches errors */
286: LOC_CONST, /* Value is constant int */
287: LOC_STATIC, /* Value is at fixed address */
288: LOC_REGISTER, /* Value is in register */
289: LOC_ARG, /* Value is at spec'd position in arglist */
290: LOC_LOCAL, /* Value is at spec'd pos in stack frame */
291: LOC_TYPEDEF, /* Value not used; definition in SYMBOL_TYPE
292: Symbols in the namespace STRUCT_NAMESPACE
293: all have this class. */
294: LOC_LABEL, /* Value is address in the code */
295: LOC_BLOCK, /* Value is address of a `struct block'.
296: Function names have this class. */
297: LOC_EXTERNAL, /* Value is at address not in this compilation.
298: This is used for .comm symbols
299: and for extern symbols within functions.
300: Inside GDB, this is changed to LOC_STATIC once the
301: real address is obtained from a loader symbol. */
302: LOC_CONST_BYTES /* Value is a constant byte-sequence. */
303: };
304:
305: struct symbol
306: {
307: /* Symbol name */
308: char *name;
309: /* Name space code. */
310: enum namespace namespace;
311: /* Address class */
312: enum address_class class;
313: /* Data type of value */
314: struct type *type;
315: /* constant value, or address if static, or register number,
316: or offset in arguments, or offset in stack frame. */
317: union
318: {
319: long value;
320: struct block *block; /* for LOC_BLOCK */
321: char *bytes; /* for LOC_CONST_BYTES */
322: }
323: value;
324: };
325:
326: /* Source-file information.
327: This describes the relation between source files and line numbers
328: and addresses in the program text. */
329:
330: struct sourcevector
331: {
332: int length; /* Number of source files described */
333: struct source *source[1]; /* Descriptions of the files */
334: };
335:
336: /* Each item is either minus a line number, or a program counter.
337: If it represents a line number, that is the line described by the next
338: program counter value. If it is positive, it is the program
339: counter at which the code for the next line starts.
340:
341: Consecutive lines can be recorded by program counter entries
342: with no line number entries between them. Line number entries
343: are used when there are lines to skip with no code on them.
344: This is to make the table shorter. */
345:
346: struct linetable
347: {
348: int nitems;
349: int item[1];
350: };
351:
352: /* All the information on one source file. */
353:
354: struct source
355: {
356: char *name; /* Name of file */
357: struct linetable contents;
358: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.