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