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