Break out symbol-table-building routines
[platform/upstream/binutils.git] / gdb / buildsym.h
1 /* Build symbol tables in GDB's internal format.
2    Copyright (C) 1986-1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 /* This module provides definitions used for creating and adding to
21    the symbol table.  These routines are called from various symbol-
22    file-reading routines.  
23
24    They originated in dbxread.c of gdb-4.2, and were split out to
25    make xcoffread.c more maintainable by sharing code.
26
27    Variables declared in this file can be defined by #define-ing
28    the name EXTERN to null.  It is used to declare variables that
29    are normally extern, but which get defined in a single module
30    using this technique.  */
31
32 #ifndef EXTERN
33 #define EXTERN  extern
34 #endif
35
36 extern void add_symbol_to_list ();
37 extern void process_one_symbol ();
38 extern struct type *read_type ();
39 extern struct type *read_range_type ();
40 extern struct type *read_enum_type ();
41 extern struct type *read_struct_type ();
42 extern struct type *read_array_type ();
43 extern struct type **read_args ();
44 extern struct type **dbx_lookup_type ();
45 extern long read_number ();
46 extern void finish_block ();
47 extern struct blockvector *make_blockvector ();
48 extern void add_undefined_type ();
49 extern void really_free_pendings ();
50 extern struct symtab *end_symtab ();
51 extern void scan_file_globals ();
52 extern void buildsym_new_init ();
53 extern void buildsym_init ();
54
55 /* Convert stab register number (from `r' declaration) to a gdb REGNUM.  */
56
57 #ifndef STAB_REG_TO_REGNUM
58 #define STAB_REG_TO_REGNUM(VALUE) (VALUE)
59 #endif
60 \f
61 /* Name of source file whose symbol data we are now processing.
62    This comes from a symbol of type N_SO.  */
63
64 EXTERN char *last_source_file;
65
66 /* Core address of start of text of current source file.
67    This too comes from the N_SO symbol.  */
68
69 EXTERN CORE_ADDR last_source_start_addr;
70
71 /* The list of sub-source-files within the current individual compilation.
72    Each file gets its own symtab with its own linetable and associated info,
73    but they all share one blockvector.  */
74
75 struct subfile
76 {
77   struct subfile *next;
78   char *name;
79   char *dirname;
80   struct linetable *line_vector;
81   int line_vector_length;
82   int line_vector_index;
83   int prev_line_number;
84 };
85
86 EXTERN struct subfile *subfiles;
87
88 EXTERN struct subfile *current_subfile;
89
90 /* Global variable which, when set, indicates that we are processing a
91    .o file compiled with gcc */
92
93 EXTERN unsigned char processing_gcc_compilation;
94
95 /* Count symbols as they are processed, for error messages.  */
96
97 EXTERN unsigned int symnum;
98
99 /* Vector of types defined so far, indexed by their dbx type numbers.
100    (In newer sun systems, dbx uses a pair of numbers in parens,
101     as in "(SUBFILENUM,NUMWITHINSUBFILE)".  Then these numbers must be
102     translated through the type_translations hash table to get
103     the index into the type vector.)  */
104
105 EXTERN struct type **type_vector;
106
107 /* Number of elements allocated for type_vector currently.  */
108
109 EXTERN int type_vector_length;
110
111 /* Vector of line number information.  */
112
113 EXTERN struct linetable *line_vector;
114
115 /* Index of next entry to go in line_vector_index.  */
116
117 EXTERN int line_vector_index;
118
119 /* Last line number recorded in the line vector.  */
120
121 EXTERN int prev_line_number;
122
123 /* Number of elements allocated for line_vector currently.  */
124
125 EXTERN int line_vector_length;
126
127 /* Hash table of global symbols whose values are not known yet.
128    They are chained thru the SYMBOL_VALUE_CHAIN, since we don't
129    have the correct data for that slot yet.  */
130 /* The use of the LOC_BLOCK code in this chain is nonstandard--
131    it refers to a FORTRAN common block rather than the usual meaning.  */
132
133 #define HASHSIZE 127
134 EXTERN struct symbol *global_sym_chain[HASHSIZE];
135
136 /* Record the symbols defined for each context in a list.
137    We don't create a struct block for the context until we
138    know how long to make it.  */
139
140 #define PENDINGSIZE 100
141
142 struct pending
143 {
144   struct pending *next;
145   int nsyms;
146   struct symbol *symbol[PENDINGSIZE];
147 };
148
149 /* List of free `struct pending' structures for reuse.  */
150 EXTERN struct pending *free_pendings;
151
152 /* Here are the three lists that symbols are put on.  */
153
154 EXTERN struct pending *file_symbols;    /* static at top level, and types */
155
156 EXTERN struct pending *global_symbols;  /* global functions and variables */
157
158 EXTERN struct pending *local_symbols;   /* everything local to lexical context */
159
160 /* List of symbols declared since the last BCOMM.  This list is a tail
161    of local_symbols.  When ECOMM is seen, the symbols on the list
162    are noted so their proper addresses can be filled in later,
163    using the common block base address gotten from the assembler
164    stabs.  */
165
166 EXTERN struct pending *common_block;
167 EXTERN int common_block_i;
168
169 /* Stack representing unclosed lexical contexts
170    (that will become blocks, eventually).  */
171
172 struct context_stack
173 {
174   struct pending *locals;
175   struct pending_block *old_blocks;
176   struct symbol *name;
177   CORE_ADDR start_addr;
178   CORE_ADDR end_addr;           /* Temp slot for exception handling. */
179   int depth;
180 };
181
182 EXTERN struct context_stack *context_stack;
183
184 /* Index of first unused entry in context stack.  */
185 EXTERN int context_stack_depth;
186
187 /* Currently allocated size of context stack.  */
188
189 EXTERN int context_stack_size;
190
191 /* Nonzero if within a function (so symbols should be local,
192    if nothing says specifically).  */
193
194 EXTERN int within_function;
195
196 /* List of blocks already made (lexical contexts already closed).
197    This is used at the end to make the blockvector.  */
198
199 struct pending_block
200 {
201   struct pending_block *next;
202   struct block *block;
203 };
204
205 EXTERN struct pending_block *pending_blocks;
206
207 extern CORE_ADDR startup_file_start;    /* From blockframe.c */
208 extern CORE_ADDR startup_file_end;      /* From blockframe.c */
209
210 /* Global variable which, when set, indicates that we are processing a
211    .o file compiled with gcc */
212
213 EXTERN unsigned char processing_gcc_compilation;
214
215 /* Setup a define to deal cleanly with the underscore problem */
216
217 #ifdef NAMES_HAVE_UNDERSCORE
218 #define HASH_OFFSET 1
219 #else
220 #define HASH_OFFSET 0
221 #endif
222 \f
223 /* Support for Sun changes to dbx symbol format */
224
225 /* For each identified header file, we have a table of types defined
226    in that header file.
227
228    header_files maps header file names to their type tables.
229    It is a vector of n_header_files elements.
230    Each element describes one header file.
231    It contains a vector of types.
232
233    Sometimes it can happen that the same header file produces
234    different results when included in different places.
235    This can result from conditionals or from different
236    things done before including the file.
237    When this happens, there are multiple entries for the file in this table,
238    one entry for each distinct set of results.
239    The entries are distinguished by the INSTANCE field.
240    The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is
241    used to match header-file references to their corresponding data.  */
242
243 struct header_file
244 {
245   char *name;                   /* Name of header file */
246   int instance;                 /* Numeric code distinguishing instances
247                                    of one header file that produced
248                                    different results when included.
249                                    It comes from the N_BINCL or N_EXCL.  */
250   struct type **vector;         /* Pointer to vector of types */
251   int length;                   /* Allocated length (# elts) of that vector */
252 };
253
254 EXTERN struct header_file *header_files;
255
256 EXTERN int n_header_files;
257
258 EXTERN int n_allocated_header_files;
259
260 /* Within each object file, various header files are assigned numbers.
261    A type is defined or referred to with a pair of numbers
262    (FILENUM,TYPENUM) where FILENUM is the number of the header file
263    and TYPENUM is the number within that header file.
264    TYPENUM is the index within the vector of types for that header file.
265
266    FILENUM == 1 is special; it refers to the main source of the object file,
267    and not to any header file.  FILENUM != 1 is interpreted by looking it up
268    in the following table, which contains indices in header_files.  */
269
270 EXTERN int *this_object_header_files;
271
272 EXTERN int n_this_object_header_files;
273
274 EXTERN int n_allocated_this_object_header_files;