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