gdb-3.1
[deliverable/binutils-gdb.git] / gdb / symtab.h
1 /* Symbol table definitions for GDB.
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 #include <obstack.h>
22
23 /* An obstack to hold objects that should be freed
24 when we load a new symbol table.
25 This includes the symbols made by dbxread
26 and the types that are not permanent. */
27
28 extern struct obstack *symbol_obstack;
29 extern struct obstack *psymbol_obstack;
30
31 /* Some definitions and declarations to go with use of obstacks. */
32 #define obstack_chunk_alloc xmalloc
33 #define obstack_chunk_free free
34 extern char *xmalloc ();
35 extern void free ();
36
37 /* gdb can know one or several symbol tables at the same time;
38 the ultimate intent is to have one for each separately-compiled module.
39 Each such symbol table is recorded by a struct symtab, and they
40 are all chained together. */
41
42 /* In addition, gdb can record any number of miscellaneous undebuggable
43 functions' addresses. In a system that appends _ to function names,
44 the _'s are removed from the names stored in this table. The type is
45 used when sorting so that find_pc_misc_function will pick a global name
46 over a local name for the same address. */
47
48 struct misc_function
49 {
50 char *name;
51 CORE_ADDR address;
52 unsigned char type;
53 };
54
55 /* Address and length of the vector recording all misc function names/addresses. */
56
57 struct misc_function *misc_function_vector;
58 int misc_function_count;
59 \f
60 #include "symseg.h"
61
62 /* Each source file is represented by a struct symtab. */
63 /* These objects are chained through the `next' field. */
64
65 struct symtab
66 {
67 /* Chain of all existing symtabs. */
68 struct symtab *next;
69 /* List of all symbol scope blocks for this symtab. */
70 struct blockvector *blockvector;
71 /* Table mapping core addresses to line numbers for this file. */
72 struct linetable *linetable;
73 /* Vector containing all types defined for this symtab. */
74 struct typevector *typevector;
75 /* Name of this source file. */
76 char *filename;
77 /* This component says how to free the data we point to:
78 free_contents => do a tree walk and free each object.
79 free_nothing => do nothing; some other symtab will free
80 the data this one uses.
81 free_linetable => free just the linetable. */
82 enum free_code {free_nothing, free_contents, free_linetable}
83 free_code;
84 /* Pointer to one block of storage to be freed, if nonzero. */
85 char *free_ptr;
86 /* Total number of lines found in source file. */
87 int nlines;
88 /* Array mapping line number to character position. */
89 int *line_charpos;
90 /* Language of this source file. */
91 enum language language;
92 /* String of version information. May be zero. */
93 char *version;
94 /* String of compilation information. May be zero. */
95 char *compilation;
96 /* Offset within loader symbol table
97 of first local symbol for this file. */
98 int ldsymoff;
99 /* Full name of file as found by searching the source path.
100 0 if not yet known. */
101 char *fullname;
102 };
103
104 /*
105 * Each source file that has not been fully read in is represented by
106 * a partial_symtab. This contains the information on where in the
107 * executable the debugging symbols for a specific file are, and a
108 * list of names of global symbols which are located in this file.
109 */
110 struct partial_symtab
111 {
112 /* Chain of all existing partial symtabs. */
113 struct partial_symtab *next;
114 /* Name of the source file which this partial_symtab defines */
115 char *filename;
116 /* Offset within loader symbol table of first local symbol for this
117 file and length (in bytes) of the section of the symbol table
118 devoted to this file's symbols (actually, the section bracketed
119 may contain more than just this files symbols
120 If ldsymlen is 0, the only reason for this things existence is
121 the dependency list below. Nothing else will happen when it is
122 read in. */
123 int ldsymoff, ldsymlen;
124 /* Range of text addresses covered by this file; texthigh is the
125 beginning of the next section. */
126 int textlow, texthigh;
127 /* Non-zero if the symtab corresponding to this psymtab has been
128 readin */
129 unsigned char readin;
130 /* Array of pointers to all of the partial_symtab s which this one
131 depends one. Since this array can only be set to previous or
132 the current (?) psymtab, this dependency tree is guarranteed not
133 to have any loops. */
134 struct partial_symtab **dependencies;
135 int number_of_dependencies;
136 /* Global symbol list. This list will be sorted after readin to
137 improve access. Binary search will be the usual method of
138 finding a symbol within it. globals_offset is an integer offset
139 within ps_globals */
140 int globals_offset, n_global_syms;
141 /* Static symbol list. This list will *not* be sorted after readin;
142 to find a symbol in it, exhaustive search must be used. This is
143 reasonable because searches through this list will eventually
144 lead to either the read in of a files symbols for real (assumed
145 to take a *lot* of time; check) or an error (and we don't care
146 how long errors take). */
147 int statics_offset, n_static_syms;
148 };
149
150 /* This is the list of struct symtab's that gdb considers current. */
151
152 struct symtab *symtab_list;
153
154 /* This is the list of struct partial_symtab's that gdb may need to access */
155
156 struct partial_symtab *partial_symtab_list;
157
158 /* This symtab variable specifies the current file for printing source lines */
159
160 struct symtab *current_source_symtab;
161
162 /* This is the next line to print for listing source lines. */
163
164 int current_source_line;
165
166 #define BLOCKLIST(symtab) (symtab)->blockvector
167 #define BLOCKVECTOR(symtab) (symtab)->blockvector
168
169 #define TYPEVECTOR(symtab) (symtab)->typevector
170
171 #define LINELIST(symtab) (symtab)->linetable
172 #define LINETABLE(symtab) (symtab)->linetable
173 \f
174 /* Macros normally used to access components of symbol table structures. */
175
176 #define BLOCKLIST_NBLOCKS(blocklist) (blocklist)->nblocks
177 #define BLOCKLIST_BLOCK(blocklist,n) (blocklist)->block[n]
178 #define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks
179 #define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n]
180
181 #define TYPEVECTOR_NTYPES(typelist) (typelist)->length
182 #define TYPEVECTOR_TYPE(typelist,n) (typelist)->type[n]
183
184 #define BLOCK_START(bl) (bl)->startaddr
185 #define BLOCK_END(bl) (bl)->endaddr
186 #define BLOCK_NSYMS(bl) (bl)->nsyms
187 #define BLOCK_SYM(bl, n) (bl)->sym[n]
188 #define BLOCK_FUNCTION(bl) (bl)->function
189 #define BLOCK_SUPERBLOCK(bl) (bl)->superblock
190 #define BLOCK_GCC_COMPILED(bl) (bl)->gcc_compile_flag
191
192 /* Nonzero if symbols of block BL should be sorted alphabetically. */
193 #define BLOCK_SHOULD_SORT(bl) ((bl)->nsyms >= 40)
194
195 #define SYMBOL_NAME(symbol) (symbol)->name
196 #define SYMBOL_NAMESPACE(symbol) (symbol)->namespace
197 #define SYMBOL_CLASS(symbol) (symbol)->class
198 #define SYMBOL_VALUE(symbol) (symbol)->value.value
199 #define SYMBOL_VALUE_BYTES(symbol) (symbol)->value.bytes
200 #define SYMBOL_BLOCK_VALUE(symbol) (symbol)->value.block
201 #define SYMBOL_TYPE(symbol) (symbol)->type
202
203 /* This appears in a type's flags word
204 if it is a (pointer to a|function returning a)* built in scalar type.
205 These types are never freed. */
206 #define TYPE_FLAG_PERM 4
207
208 /* Some macros for bitfields. */
209 #define B_SET(a,x) (a[x>>5] |= (1 << (x&31)))
210 #define B_CLR(a,x) (a[x>>5] &= ~(1 << (x&31)))
211 #define B_TST(a,x) (a[x>>5] & (1 << (x&31)))
212
213 #define TYPE_NAME(thistype) (thistype)->name
214 #define TYPE_TARGET_TYPE(thistype) (thistype)->target_type
215 #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
216 #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
217 #define TYPE_FUNCTION_TYPE(thistype) (thistype)->function_type
218 #define TYPE_MAIN_VARIANT(thistype) (thistype)->main_variant
219 #define TYPE_NEXT_VARIANT(thistype) (thistype)->next_variant
220 #define TYPE_LENGTH(thistype) (thistype)->length
221 #define TYPE_FLAGS(thistype) (thistype)->flags
222 #define TYPE_UNSIGNED(thistype) ((thistype)->flags & TYPE_FLAG_UNSIGNED)
223 #define TYPE_CODE(thistype) (thistype)->code
224 #define TYPE_NFIELDS(thistype) (thistype)->nfields
225 #define TYPE_FIELDS(thistype) (thistype)->fields
226 /* C++ */
227 #define TYPE_VPTR_BASETYPE(thistype) (thistype)->vptr_basetype
228 #define TYPE_DOMAIN_TYPE(thistype) (thistype)->vptr_basetype
229 #define TYPE_VPTR_FIELDNO(thistype) (thistype)->vptr_fieldno
230 #define TYPE_FN_FIELDS(thistype) (thistype)->fn_fields
231 #define TYPE_NFN_FIELDS(thistype) (thistype)->nfn_fields
232 #define TYPE_NFN_FIELDS_TOTAL(thistype) (thistype)->nfn_fields_total
233 #define TYPE_BASECLASSES(thistype) (thistype)->baseclasses
234 #define TYPE_BASECLASS(thistype,index) (thistype)->baseclasses[index]
235 #define TYPE_N_BASECLASSES(thistype) (thistype)->n_baseclasses
236 #define TYPE_VIA_PUBLIC(thistype) ((thistype)->flags & TYPE_FLAG_VIA_PUBLIC)
237 #define TYPE_VIA_VIRTUAL(thistype) ((thistype)->flags & TYPE_FLAG_VIA_VIRTUAL)
238
239 #define TYPE_FIELD(thistype, n) (thistype)->fields[n]
240 #define TYPE_FIELD_TYPE(thistype, n) (thistype)->fields[n].type
241 #define TYPE_FIELD_NAME(thistype, n) (thistype)->fields[n].name
242 #define TYPE_FIELD_VALUE(thistype, n) (* (int*) &(thistype)->fields[n].type)
243 #define TYPE_FIELD_BITPOS(thistype, n) (thistype)->fields[n].bitpos
244 #define TYPE_FIELD_BITSIZE(thistype, n) (thistype)->fields[n].bitsize
245 #define TYPE_FIELD_PACKED(thistype, n) (thistype)->fields[n].bitsize
246
247 #define TYPE_FIELD_PRIVATE_BITS(thistype) (thistype)->private_field_bits
248 #define TYPE_FIELD_PROTECTED_BITS(thistype) (thistype)->protected_field_bits
249 #define SET_TYPE_FIELD_PRIVATE(thistype, n) B_SET ((thistype)->private_field_bits, (n))
250 #define SET_TYPE_FIELD_PROTECTED(thistype, n) B_SET ((thistype)->protected_field_bits, (n))
251 #define TYPE_FIELD_PRIVATE(thistype, n) B_TST((thistype)->private_field_bits, (n))
252 #define TYPE_FIELD_PROTECTED(thistype, n) B_TST((thistype)->protected_field_bits, (n))
253
254 #define TYPE_HAS_DESTRUCTOR(thistype) ((thistype)->flags & TYPE_FLAG_HAS_DESTRUCTOR)
255 #define TYPE_HAS_CONSTRUCTOR(thistype) ((thistype)->flags & TYPE_FLAG_HAS_CONSTRUCTOR)
256
257 #define TYPE_FIELD_STATIC(thistype, n) ((thistype)->fields[n].bitpos == -1)
258 #define TYPE_FIELD_STATIC_PHYSNAME(thistype, n) ((char *)(thistype)->fields[n].bitsize)
259
260 #define TYPE_FN_FIELDLISTS(thistype) (thistype)->fn_fieldlists
261 #define TYPE_FN_FIELDLIST(thistype, n) (thistype)->fn_fieldlists[n]
262 #define TYPE_FN_FIELDLIST1(thistype, n) (thistype)->fn_fieldlists[n].fn_fields
263 #define TYPE_FN_FIELDLIST_NAME(thistype, n) (thistype)->fn_fieldlists[n].name
264 #define TYPE_FN_FIELDLIST_LENGTH(thistype, n) (thistype)->fn_fieldlists[n].length
265
266 #define TYPE_FN_FIELD(thistype) (thistype)[n]
267 #define TYPE_FN_FIELD_NAME(thistype, n) (thistype)[n].name
268 #define TYPE_FN_FIELD_TYPE(thistype, n) (thistype)[n].type
269 #define TYPE_FN_FIELD_ARGS(thistype, n) (thistype)[n].args
270 #define TYPE_FN_FIELD_PHYSNAME(thistype, n) (thistype)[n].physname
271 #define TYPE_FN_FIELD_VIRTUAL_P(thistype, n) (thistype)[n].voffset
272 #define TYPE_FN_FIELD_VOFFSET(thistype, n) ((thistype)[n].voffset-1)
273
274 #define TYPE_FN_PRIVATE_BITS(thistype) (thistype).private_fn_field_bits
275 #define TYPE_FN_PROTECTED_BITS(thistype) (thistype).protected_fn_field_bits
276 #define SET_TYPE_FN_PRIVATE(thistype, n) B_SET ((thistype).private_fn_field_bits, n)
277 #define SET_TYPE_FN_PROTECTED(thistype, n) B_SET ((thistype).protected_fn_field_bits, n)
278 #define TYPE_FN_PRIVATE(thistype, n) B_TST ((thistype).private_fn_field_bits, n)
279 #define TYPE_FN_PROTECTED(thistype, n) B_TST ((thistype).protected_fn_field_bits, n)
280 \f
281 /* Functions that work on the objects described above */
282
283 extern struct symtab *lookup_symtab ();
284 extern struct symbol *lookup_symbol ();
285 extern struct type *lookup_typename ();
286 extern struct type *lookup_unsigned_typename ();
287 extern struct type *lookup_struct ();
288 extern struct type *lookup_union ();
289 extern struct type *lookup_enum ();
290 extern struct type *lookup_pointer_type ();
291 extern struct type *lookup_function_type ();
292 extern struct type *lookup_basetype_type ();
293 extern struct symbol *block_function ();
294 extern struct symbol *find_pc_function ();
295 extern int find_pc_misc_function ();
296
297 /* C++ stuff. */
298 extern struct type *lookup_reference_type ();
299 extern struct type *lookup_member_type ();
300 extern struct type *lookup_class ();
301 /* end of C++ stuff. */
302
303 extern struct type *builtin_type_void;
304 extern struct type *builtin_type_char;
305 extern struct type *builtin_type_short;
306 extern struct type *builtin_type_int;
307 extern struct type *builtin_type_long;
308 extern struct type *builtin_type_unsigned_char;
309 extern struct type *builtin_type_unsigned_short;
310 extern struct type *builtin_type_unsigned_int;
311 extern struct type *builtin_type_unsigned_long;
312 extern struct type *builtin_type_float;
313 extern struct type *builtin_type_double;
314 #ifdef LONG_LONG
315 extern struct type *builtin_type_long_long;
316 extern struct type *builtin_type_unsigned_long_long;
317 #endif
318
319 struct symtab_and_line
320 {
321 struct symtab *symtab;
322 int line;
323 CORE_ADDR pc;
324 CORE_ADDR end;
325 };
326
327 struct symtabs_and_lines
328 {
329 struct symtab_and_line *sals;
330 int nelts;
331 };
332
333 /* Given a pc value, return line number it is in.
334 Second arg nonzero means if pc is on the boundary
335 use the previous statement's line number. */
336
337 struct symtab_and_line find_pc_line ();
338
339 /* Given a string, return the line specified by it.
340 For commands like "list" and "breakpoint". */
341
342 struct symtabs_and_lines decode_line_spec ();
343 struct symtabs_and_lines decode_line_spec_1 ();
344 struct symtabs_and_lines decode_line_1 ();
This page took 0.060384 seconds and 5 git commands to generate.