* Check in Fred Fish's changes in these modules. Fred
[binutils-gdb.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 #if !defined (BUILDSYM_H)
21 #define BUILDSYM_H 1
22
23 /* This module provides definitions used for creating and adding to
24 the symbol table. These routines are called from various symbol-
25 file-reading routines.
26
27 They originated in dbxread.c of gdb-4.2, and were split out to
28 make xcoffread.c more maintainable by sharing code.
29
30 Variables declared in this file can be defined by #define-ing
31 the name EXTERN to null. It is used to declare variables that
32 are normally extern, but which get defined in a single module
33 using this technique. */
34
35 #ifndef EXTERN
36 #define EXTERN extern
37 #endif
38
39 /* Convert stab register number (from `r' declaration) to a gdb REGNUM. */
40
41 #ifndef STAB_REG_TO_REGNUM
42 #define STAB_REG_TO_REGNUM(VALUE) (VALUE)
43 #endif
44 \f
45 /* Name of source file whose symbol data we are now processing.
46 This comes from a symbol of type N_SO. */
47
48 EXTERN char *last_source_file;
49
50 /* Core address of start of text of current source file.
51 This too comes from the N_SO symbol. */
52
53 EXTERN CORE_ADDR last_source_start_addr;
54
55 /* The list of sub-source-files within the current individual compilation.
56 Each file gets its own symtab with its own linetable and associated info,
57 but they all share one blockvector. */
58
59 struct subfile
60 {
61 struct subfile *next;
62 char *name;
63 char *dirname;
64 struct linetable *line_vector;
65 int line_vector_length;
66 };
67
68 EXTERN struct subfile *subfiles;
69
70 EXTERN struct subfile *current_subfile;
71
72 /* Global variable which, when set, indicates that we are processing a
73 .o file compiled with gcc */
74
75 EXTERN unsigned char processing_gcc_compilation;
76
77 /* Count symbols as they are processed, for error messages. */
78
79 EXTERN unsigned int symnum;
80
81 /* Vector of types defined so far, indexed by their dbx type numbers.
82 (In newer sun systems, dbx uses a pair of numbers in parens,
83 as in "(SUBFILENUM,NUMWITHINSUBFILE)". Then these numbers must be
84 translated through the type_translations hash table to get
85 the index into the type vector.) */
86
87 EXTERN struct type **type_vector;
88
89 /* Number of elements allocated for type_vector currently. */
90
91 EXTERN int type_vector_length;
92
93 /* Hash table of global symbols whose values are not known yet.
94 They are chained thru the SYMBOL_VALUE_CHAIN, since we don't
95 have the correct data for that slot yet. */
96 /* The use of the LOC_BLOCK code in this chain is nonstandard--
97 it refers to a FORTRAN common block rather than the usual meaning. */
98
99 #define HASHSIZE 127
100 EXTERN struct symbol *global_sym_chain[HASHSIZE];
101
102 /* Record the symbols defined for each context in a list.
103 We don't create a struct block for the context until we
104 know how long to make it. */
105
106 #define PENDINGSIZE 100
107
108 struct pending
109 {
110 struct pending *next;
111 int nsyms;
112 struct symbol *symbol[PENDINGSIZE];
113 };
114
115 /* List of free `struct pending' structures for reuse. */
116 EXTERN struct pending *free_pendings;
117
118 /* Here are the three lists that symbols are put on. */
119
120 EXTERN struct pending *file_symbols; /* static at top level, and types */
121
122 EXTERN struct pending *global_symbols; /* global functions and variables */
123
124 EXTERN struct pending *local_symbols; /* everything local to lexic context */
125
126 /* Kludge for xcoffread.c */
127 struct pending_stabs {
128 int count, length;
129 char *stab[1];
130 };
131
132 EXTERN struct pending_stabs *global_stabs;
133 EXTERN struct pending_stabs *file_stabs;
134
135 /* List of symbols declared since the last BCOMM. This list is a tail
136 of local_symbols. When ECOMM is seen, the symbols on the list
137 are noted so their proper addresses can be filled in later,
138 using the common block base address gotten from the assembler
139 stabs. */
140
141 EXTERN struct pending *common_block;
142 EXTERN int common_block_i;
143
144 /* Stack representing unclosed lexical contexts
145 (that will become blocks, eventually). */
146
147 struct context_stack
148 {
149 struct pending *locals; /* Outer locals at the time we entered */
150 struct pending_block *old_blocks; /* Pointer into blocklist as of entry */
151 struct symbol *name; /* Name of function, if any, defining context*/
152 CORE_ADDR start_addr; /* PC where this context starts */
153 CORE_ADDR end_addr; /* Temp slot for exception handling. */
154 int depth; /* For error-checking matching push/pop */
155 };
156
157 EXTERN struct context_stack *context_stack;
158
159 /* Index of first unused entry in context stack. */
160 EXTERN int context_stack_depth;
161
162 /* Currently allocated size of context stack. */
163
164 EXTERN int context_stack_size;
165
166 /* Macro "function" for popping contexts from the stack. Pushing is done
167 by a real function, push_context. This returns a pointer to a struct
168 context_stack. */
169
170 #define pop_context() \
171 (&context_stack[--context_stack_depth]);
172
173 /* Nonzero if within a function (so symbols should be local,
174 if nothing says specifically). */
175
176 EXTERN int within_function;
177
178 /* List of blocks already made (lexical contexts already closed).
179 This is used at the end to make the blockvector. */
180
181 struct pending_block
182 {
183 struct pending_block *next;
184 struct block *block;
185 };
186
187 EXTERN struct pending_block *pending_blocks;
188
189 extern CORE_ADDR startup_file_start; /* From blockframe.c */
190 extern CORE_ADDR startup_file_end; /* From blockframe.c */
191
192 /* Global variable which, when set, indicates that we are processing a
193 .o file compiled with gcc */
194
195 EXTERN unsigned char processing_gcc_compilation;
196
197 /* The type code that process_one_symbol saw on its previous invocation.
198 Used to detect pairs of N_SO symbols. */
199
200 EXTERN int previous_stab_code;
201
202 /* Setup a define to deal cleanly with the underscore problem */
203
204 #ifdef NAMES_HAVE_UNDERSCORE
205 #define HASH_OFFSET 1
206 #else
207 #define HASH_OFFSET 0
208 #endif
209 \f
210 /* Support for Sun changes to dbx symbol format */
211
212 /* For each identified header file, we have a table of types defined
213 in that header file.
214
215 header_files maps header file names to their type tables.
216 It is a vector of n_header_files elements.
217 Each element describes one header file.
218 It contains a vector of types.
219
220 Sometimes it can happen that the same header file produces
221 different results when included in different places.
222 This can result from conditionals or from different
223 things done before including the file.
224 When this happens, there are multiple entries for the file in this table,
225 one entry for each distinct set of results.
226 The entries are distinguished by the INSTANCE field.
227 The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is
228 used to match header-file references to their corresponding data. */
229
230 struct header_file
231 {
232 char *name; /* Name of header file */
233 int instance; /* Numeric code distinguishing instances
234 of one header file that produced
235 different results when included.
236 It comes from the N_BINCL or N_EXCL. */
237 struct type **vector; /* Pointer to vector of types */
238 int length; /* Allocated length (# elts) of that vector */
239 };
240
241 EXTERN struct header_file *header_files;
242
243 EXTERN int n_header_files;
244
245 EXTERN int n_allocated_header_files;
246
247 /* Within each object file, various header files are assigned numbers.
248 A type is defined or referred to with a pair of numbers
249 (FILENUM,TYPENUM) where FILENUM is the number of the header file
250 and TYPENUM is the number within that header file.
251 TYPENUM is the index within the vector of types for that header file.
252
253 FILENUM == 1 is special; it refers to the main source of the object file,
254 and not to any header file. FILENUM != 1 is interpreted by looking it up
255 in the following table, which contains indices in header_files. */
256
257 EXTERN int *this_object_header_files;
258
259 EXTERN int n_this_object_header_files;
260
261 EXTERN int n_allocated_this_object_header_files;
262
263 /* When a header file is getting special overriding definitions
264 for one source file, record here the header_files index
265 of its normal definition vector.
266 At other times, this is -1. */
267
268 EXTERN int header_file_prev_index;
269
270 struct subfile_stack
271 {
272 struct subfile_stack *next;
273 char *name;
274 int prev_index;
275 };
276
277 EXTERN struct subfile_stack *subfile_stack;
278
279 extern struct complaint unknown_symtype_complaint;
280
281 #define next_symbol_text() (*next_symbol_text_func)()
282
283 /* Function to invoke get the next symbol. Return the symbol name. */
284
285 EXTERN char *(*next_symbol_text_func) PARAMS ((void));
286
287 extern void
288 add_symbol_to_list PARAMS ((struct symbol *, struct pending **));
289
290 extern struct symbol *
291 find_symbol_in_list PARAMS ((struct pending *, char *, int));
292
293 extern void
294 read_type_number PARAMS ((char **, int *));
295
296 extern struct type *
297 read_type PARAMS ((char **, struct objfile *));
298
299 extern struct type **
300 dbx_lookup_type PARAMS ((int [2]));
301
302 extern long
303 read_number PARAMS ((char **, int));
304
305 extern void
306 finish_block PARAMS ((struct symbol *, struct pending **,
307 struct pending_block *, CORE_ADDR, CORE_ADDR,
308 struct objfile *));
309
310 extern void
311 add_undefined_type PARAMS ((struct type *));
312
313 extern void
314 really_free_pendings PARAMS ((int foo));
315
316 extern void
317 start_subfile PARAMS ((char *, char *));
318
319 extern void
320 push_subfile PARAMS ((void));
321
322 extern char *
323 pop_subfile PARAMS ((void));
324
325 extern struct symtab *
326 end_symtab PARAMS ((CORE_ADDR, int, int,struct objfile *));
327
328 extern void
329 scan_file_globals PARAMS ((struct objfile *));
330
331 extern void
332 buildsym_new_init PARAMS ((void));
333
334 extern void
335 buildsym_init PARAMS ((void));
336
337 extern struct context_stack *
338 push_context PARAMS ((int, CORE_ADDR));
339
340 extern void
341 record_line PARAMS ((struct subfile *, int, CORE_ADDR));
342
343 extern void
344 start_symtab PARAMS ((char *, char *, CORE_ADDR));
345
346 extern struct symbol *
347 define_symbol PARAMS ((unsigned int, char *, int, int, struct objfile *));
348
349 extern struct partial_symtab *
350 start_psymtab PARAMS ((struct objfile *, CORE_ADDR, char *, CORE_ADDR, int,
351 struct partial_symbol *, struct partial_symbol *));
352
353 extern void
354 end_psymtab PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
355 struct partial_symtab **, int));
356
357 extern void
358 process_one_symbol PARAMS ((int, int, CORE_ADDR, char *, int));
359
360 extern int
361 hashname PARAMS ((char *));
362
363 #endif /* defined (BUILDSYM_H) */