]>
Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Read a symbol table in MIPS' format (Third-Eye). |
6c2e7392 PS |
2 | Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993 Free Software |
3 | Foundation, Inc. | |
4 | Contributed by Alessandro Forin ([email protected]) at CMU. Major work | |
5 | by Per Bothner, John Gilmore and Ian Lance Taylor at Cygnus Support. | |
bd5635a1 RP |
6 | |
7 | This file is part of GDB. | |
8 | ||
b8c50f09 | 9 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 10 | it under the terms of the GNU General Public License as published by |
b8c50f09 JG |
11 | the Free Software Foundation; either version 2 of the License, or |
12 | (at your option) any later version. | |
bd5635a1 | 13 | |
b8c50f09 | 14 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
b8c50f09 JG |
20 | along with this program; if not, write to the Free Software |
21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 | 22 | |
3eaebb75 | 23 | /* This module provides three functions: mipscoff_symfile_init, |
817bc7b8 | 24 | which initializes to read a symbol file; mipscoff_new_init, which |
3eaebb75 SG |
25 | discards existing cached information when all symbols are being |
26 | discarded; and mipscoff_symfile_read, which reads a symbol table | |
27 | from a file. | |
28 | ||
29 | mipscoff_symfile_read only does the minimum work necessary for letting the | |
30 | user "name" things symbolically; it does not read the entire symtab. | |
31 | Instead, it reads the external and static symbols and puts them in partial | |
32 | symbol tables. When more extensive information is requested of a | |
33 | file, the corresponding partial symbol table is mutated into a full | |
34 | fledged symbol table by going back and reading the symbols | |
35 | for real. mipscoff_psymtab_to_symtab() is called indirectly through | |
d747e0af MT |
36 | a pointer in the psymtab to do this. |
37 | ||
38 | ECOFF symbol tables are mostly written in the byte order of the | |
39 | target machine. However, one section of the table (the auxiliary | |
40 | symbol information) is written in the host byte order. There is a | |
41 | bit in the other symbol info which describes which host byte order | |
42 | was used. ECOFF thereby takes the trophy from Intel `b.out' for | |
43 | the most brain-dead adaptation of a file format to byte order. | |
44 | ||
45 | This module can read all four of the known byte-order combinations, | |
6c2e7392 | 46 | on any type of host. */ |
d747e0af MT |
47 | |
48 | #define TM_FILE_OVERRIDE | |
bd5635a1 | 49 | #include "defs.h" |
1a0edbc7 | 50 | #include "mips/tm-mips.h" |
bd5635a1 | 51 | #include "symtab.h" |
d747e0af | 52 | #include "gdbtypes.h" |
bd5635a1 RP |
53 | #include "gdbcore.h" |
54 | #include "symfile.h" | |
5e2e79f8 | 55 | #include "objfiles.h" |
7d9884b9 | 56 | #include "obstack.h" |
7e258d18 | 57 | #include "buildsym.h" |
dac4929a | 58 | #include "stabsread.h" |
51b80b00 | 59 | #include "complaints.h" |
817bc7b8 JG |
60 | |
61 | #ifdef USG | |
62 | #include <sys/types.h> | |
63 | #define L_SET 0 | |
64 | #define L_INCR 1 | |
65 | #endif | |
66 | ||
7d9884b9 JG |
67 | #include <sys/param.h> |
68 | #include <sys/file.h> | |
69 | #include <sys/stat.h> | |
85f0a848 | 70 | #include <string.h> |
fa0bcaa3 | 71 | |
dac4929a SG |
72 | #include "gdb-stabs.h" |
73 | ||
6c2e7392 PS |
74 | #include "bfd.h" |
75 | ||
76 | #include "coff/internal.h" | |
817bc7b8 | 77 | #include "coff/mips.h" /* COFF-like aspects of ecoff files */ |
817bc7b8 | 78 | #include "coff/ecoff-ext.h" /* External forms of ecoff sym structures */ |
e10a3052 | 79 | |
6c2e7392 PS |
80 | /* FIXME: coff/internal.h and aout/aout64.h both define N_ABS. We |
81 | want the definition from aout/aout64.h. */ | |
82 | #undef N_ABS | |
83 | /* FIXME: coff/mips.h and aout/aout64.h both define ZMAGIC. We don't | |
84 | use it. */ | |
85 | #undef ZMAGIC | |
86 | ||
87 | #include "libaout.h" /* Private BFD a.out information. */ | |
7e258d18 | 88 | #include "aout/aout64.h" |
817bc7b8 | 89 | #include "aout/stab_gnu.h" /* STABS information */ |
6c2e7392 PS |
90 | |
91 | /* FIXME: libcoff.h and libaout.h both define a couple of macros. We | |
92 | don't use them. */ | |
93 | #undef exec_hdr | |
94 | #undef obj_sym_filepos | |
95 | ||
96 | #include "libcoff.h" /* Private BFD COFF information. */ | |
97 | #include "libecoff.h" /* Private BFD ECOFF information. */ | |
98 | ||
85f0a848 FF |
99 | #include "expression.h" |
100 | #include "language.h" /* Needed inside partial-stab.h */ | |
bd5635a1 | 101 | |
6c2e7392 PS |
102 | /* Each partial symbol table entry contains a pointer to private data |
103 | for the read_symtab() function to use when expanding a partial | |
104 | symbol table entry to a full symbol table entry. | |
4a35d6e9 | 105 | |
6c2e7392 PS |
106 | For mipsread this structure contains the index of the FDR that this |
107 | psymtab represents and a pointer to the BFD that the psymtab was | |
108 | created from. */ | |
4a35d6e9 | 109 | |
d4ea2aba PB |
110 | #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private) |
111 | #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx) | |
6c2e7392 | 112 | #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd) |
4a35d6e9 | 113 | |
5f7b2142 ILT |
114 | struct symloc |
115 | { | |
4a35d6e9 | 116 | int fdr_idx; |
6c2e7392 PS |
117 | bfd *cur_bfd; |
118 | EXTR *extern_tab; /* Pointer to external symbols for this file. */ | |
119 | int extern_count; /* Size of extern_tab. */ | |
120 | struct mips_pending **pending_list; | |
4a35d6e9 FF |
121 | }; |
122 | ||
bd5635a1 RP |
123 | /* Things we import explicitly from other modules */ |
124 | ||
5f7b2142 | 125 | extern int info_verbose; |
bd5635a1 | 126 | |
3eaebb75 | 127 | /* Various complaints about symbol reading that don't abort the process */ |
817bc7b8 JG |
128 | |
129 | struct complaint bad_file_number_complaint = | |
5f7b2142 | 130 | {"bad file number %d", 0, 0}; |
021959e2 | 131 | |
817bc7b8 | 132 | struct complaint index_complaint = |
5f7b2142 | 133 | {"bad aux index at symbol %s", 0, 0}; |
817bc7b8 JG |
134 | |
135 | struct complaint aux_index_complaint = | |
5f7b2142 | 136 | {"bad proc end in aux found from symbol %s", 0, 0}; |
817bc7b8 | 137 | |
6edd74ae | 138 | struct complaint block_index_complaint = |
5f7b2142 | 139 | {"bad aux index at block symbol %s", 0, 0}; |
6edd74ae | 140 | |
817bc7b8 | 141 | struct complaint unknown_ext_complaint = |
5f7b2142 | 142 | {"unknown external symbol %s", 0, 0}; |
bd5635a1 | 143 | |
817bc7b8 | 144 | struct complaint unknown_sym_complaint = |
5f7b2142 | 145 | {"unknown local symbol %s", 0, 0}; |
101f259c | 146 | |
817bc7b8 | 147 | struct complaint unknown_st_complaint = |
5f7b2142 | 148 | {"with type %d", 0, 0}; |
101f259c | 149 | |
817bc7b8 | 150 | struct complaint block_overflow_complaint = |
5f7b2142 | 151 | {"block containing %s overfilled", 0, 0}; |
3eaebb75 | 152 | |
817bc7b8 | 153 | struct complaint basic_type_complaint = |
5f7b2142 | 154 | {"cannot map MIPS basic type 0x%x", 0, 0}; |
3eaebb75 | 155 | |
817bc7b8 | 156 | struct complaint unknown_type_qual_complaint = |
5f7b2142 | 157 | {"unknown type qualifier 0x%x", 0, 0}; |
3eaebb75 | 158 | |
817bc7b8 | 159 | struct complaint array_bitsize_complaint = |
5f7b2142 | 160 | {"size of array target type not known, assuming %d bits", 0, 0}; |
3eaebb75 | 161 | |
817bc7b8 | 162 | struct complaint bad_tag_guess_complaint = |
5f7b2142 | 163 | {"guessed tag type of %s incorrectly", 0, 0}; |
817bc7b8 JG |
164 | |
165 | struct complaint block_member_complaint = | |
5f7b2142 | 166 | {"declaration block contains unhandled symbol type %d", 0, 0}; |
817bc7b8 JG |
167 | |
168 | struct complaint stEnd_complaint = | |
5f7b2142 | 169 | {"stEnd with storage class %d not handled", 0, 0}; |
817bc7b8 JG |
170 | |
171 | struct complaint unknown_mips_symtype_complaint = | |
5f7b2142 | 172 | {"unknown symbol type 0x%x", 0, 0}; |
817bc7b8 JG |
173 | |
174 | struct complaint stab_unknown_complaint = | |
5f7b2142 | 175 | {"unknown stabs symbol %s", 0, 0}; |
817bc7b8 JG |
176 | |
177 | struct complaint pdr_for_nonsymbol_complaint = | |
5f7b2142 | 178 | {"PDR for %s, but no symbol", 0, 0}; |
817bc7b8 JG |
179 | |
180 | struct complaint pdr_static_symbol_complaint = | |
5f7b2142 | 181 | {"can't handle PDR for static proc at 0x%x", 0, 0}; |
c55e6167 | 182 | |
3eaebb75 SG |
183 | /* Macros and extra defs */ |
184 | ||
185 | /* Already-parsed symbols are marked specially */ | |
bd5635a1 RP |
186 | |
187 | #define stParsed stType | |
188 | ||
189 | /* Puns: hard to find whether -g was used and how */ | |
190 | ||
191 | #define MIN_GLEVEL GLEVEL_0 | |
192 | #define compare_glevel(a,b) \ | |
193 | (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \ | |
194 | ((b) == GLEVEL_3) ? -1 : (int)((b) - (a))) | |
e072c738 JG |
195 | \f |
196 | /* Things that really are local to this module */ | |
197 | ||
c4413e2c FF |
198 | /* Remember what we deduced to be the source language of this psymtab. */ |
199 | ||
200 | static enum language psymtab_language = language_unknown; | |
201 | ||
6c2e7392 | 202 | /* Current BFD. */ |
3eaebb75 | 203 | |
6c2e7392 | 204 | static bfd *cur_bfd; |
3eaebb75 | 205 | |
e072c738 JG |
206 | /* Pointer to current file decriptor record, and its index */ |
207 | ||
5f7b2142 ILT |
208 | static FDR *cur_fdr; |
209 | static int cur_fd; | |
e072c738 JG |
210 | |
211 | /* Index of current symbol */ | |
212 | ||
5f7b2142 | 213 | static int cur_sdx; |
e072c738 JG |
214 | |
215 | /* Note how much "debuggable" this image is. We would like | |
216 | to see at least one FDR with full symbols */ | |
217 | ||
218 | static max_gdbinfo; | |
219 | static max_glevel; | |
220 | ||
221 | /* When examining .o files, report on undefined symbols */ | |
222 | ||
223 | static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs; | |
224 | ||
7e258d18 PB |
225 | /* Pseudo symbol to use when putting stabs into the symbol table. */ |
226 | ||
c55e6167 | 227 | static char stabs_symbol[] = STABS_SYMBOL; |
7e258d18 | 228 | |
e072c738 JG |
229 | /* Extra builtin types */ |
230 | ||
231 | struct type *builtin_type_complex; | |
232 | struct type *builtin_type_double_complex; | |
233 | struct type *builtin_type_fixed_dec; | |
234 | struct type *builtin_type_float_dec; | |
235 | struct type *builtin_type_string; | |
236 | ||
3eaebb75 | 237 | /* Forward declarations */ |
e072c738 | 238 | |
d747e0af | 239 | static void |
dac4929a | 240 | read_mips_symtab PARAMS ((struct objfile *, struct section_offsets *)); |
84ffdec2 JG |
241 | |
242 | static void | |
6c2e7392 | 243 | read_the_mips_symtab PARAMS ((bfd *)); |
84ffdec2 JG |
244 | |
245 | static int | |
e10a3052 | 246 | upgrade_type PARAMS ((struct type **, int, union aux_ext *, int)); |
84ffdec2 JG |
247 | |
248 | static void | |
6c2e7392 | 249 | parse_partial_symbols PARAMS ((struct objfile *, |
dac4929a | 250 | struct section_offsets *)); |
d747e0af MT |
251 | |
252 | static int | |
e5578a31 SG |
253 | cross_ref PARAMS ((union aux_ext *, struct type **, enum type_code, char **, |
254 | int)); | |
84ffdec2 JG |
255 | |
256 | static void | |
257 | fixup_sigtramp PARAMS ((void)); | |
258 | ||
259 | static struct symbol * | |
260 | new_symbol PARAMS ((char *)); | |
261 | ||
262 | static struct type * | |
263 | new_type PARAMS ((char *)); | |
264 | ||
265 | static struct block * | |
266 | new_block PARAMS ((int)); | |
267 | ||
268 | static struct symtab * | |
269 | new_symtab PARAMS ((char *, int, int, struct objfile *)); | |
270 | ||
271 | static struct linetable * | |
272 | new_linetable PARAMS ((int)); | |
273 | ||
274 | static struct blockvector * | |
275 | new_bvect PARAMS ((int)); | |
276 | ||
277 | static struct type * | |
278 | parse_type PARAMS ((union aux_ext *, int *, int)); | |
279 | ||
280 | static struct symbol * | |
281 | mylookup_symbol PARAMS ((char *, struct block *, enum namespace, | |
282 | enum address_class)); | |
283 | ||
284 | static struct block * | |
285 | shrink_block PARAMS ((struct block *, struct symtab *)); | |
286 | ||
287 | static PTR | |
288 | xzalloc PARAMS ((unsigned int)); | |
d747e0af MT |
289 | |
290 | static void | |
84ffdec2 | 291 | sort_blocks PARAMS ((struct symtab *)); |
d747e0af MT |
292 | |
293 | static int | |
391ca579 | 294 | compare_blocks PARAMS ((const void *, const void *)); |
84ffdec2 JG |
295 | |
296 | static struct partial_symtab * | |
297 | new_psymtab PARAMS ((char *, struct objfile *)); | |
298 | ||
299 | #if 0 | |
300 | static struct partial_symtab * | |
301 | parse_fdr PARAMS ((int, int, struct objfile *)); | |
302 | #endif | |
d747e0af MT |
303 | |
304 | static void | |
84ffdec2 | 305 | psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *)); |
c55e6167 | 306 | |
84ffdec2 JG |
307 | static void |
308 | add_block PARAMS ((struct block *, struct symtab *)); | |
309 | ||
310 | static void | |
311 | add_symbol PARAMS ((struct symbol *, struct block *)); | |
312 | ||
313 | static int | |
314 | add_line PARAMS ((struct linetable *, int, CORE_ADDR, int)); | |
315 | ||
316 | static struct linetable * | |
317 | shrink_linetable PARAMS ((struct linetable *)); | |
318 | ||
319 | static char * | |
320 | mips_next_symbol_text PARAMS ((void)); | |
bd5635a1 RP |
321 | \f |
322 | /* Things we export to other modules */ | |
323 | ||
bd5635a1 | 324 | /* Address bounds for the signal trampoline in inferior, if any */ |
101f259c | 325 | /* FIXME: Nothing really seems to use this. Why is it here? */ |
bd5635a1 RP |
326 | |
327 | CORE_ADDR sigtramp_address, sigtramp_end; | |
328 | ||
4ad1963e | 329 | static void |
84ffdec2 JG |
330 | mipscoff_new_init (ignore) |
331 | struct objfile *ignore; | |
bd5635a1 RP |
332 | { |
333 | } | |
334 | ||
4ad1963e | 335 | static void |
80d68b1d FF |
336 | mipscoff_symfile_init (objfile) |
337 | struct objfile *objfile; | |
bd5635a1 | 338 | { |
5f7b2142 | 339 | if (objfile->sym_private != NULL) |
80d68b1d | 340 | { |
5f7b2142 | 341 | mfree (objfile->md, objfile->sym_private); |
80d68b1d | 342 | } |
5f7b2142 | 343 | objfile->sym_private = NULL; |
bd5635a1 RP |
344 | } |
345 | ||
4ad1963e | 346 | static void |
dac4929a | 347 | mipscoff_symfile_read (objfile, section_offsets, mainline) |
80d68b1d | 348 | struct objfile *objfile; |
dac4929a | 349 | struct section_offsets *section_offsets; |
bd5635a1 RP |
350 | int mainline; |
351 | { | |
021959e2 JG |
352 | init_minimal_symbol_collection (); |
353 | make_cleanup (discard_minimal_symbols, 0); | |
bd5635a1 RP |
354 | |
355 | /* Now that the executable file is positioned at symbol table, | |
356 | process it and define symbols accordingly. */ | |
357 | ||
5f7b2142 | 358 | read_mips_symtab (objfile, section_offsets); |
bd5635a1 | 359 | |
021959e2 JG |
360 | /* Install any minimal symbols that have been collected as the current |
361 | minimal symbols for this objfile. */ | |
bd5635a1 | 362 | |
80d68b1d | 363 | install_minimal_symbols (objfile); |
bd5635a1 | 364 | } |
817bc7b8 | 365 | |
80d68b1d FF |
366 | /* Perform any local cleanups required when we are done with a particular |
367 | objfile. I.E, we are in the process of discarding all symbol information | |
368 | for an objfile, freeing up all memory held for it, and unlinking the | |
369 | objfile struct from the global list of known objfiles. */ | |
370 | ||
371 | static void | |
372 | mipscoff_symfile_finish (objfile) | |
373 | struct objfile *objfile; | |
374 | { | |
5f7b2142 | 375 | if (objfile->sym_private != NULL) |
80d68b1d | 376 | { |
5f7b2142 | 377 | mfree (objfile->md, objfile->sym_private); |
80d68b1d FF |
378 | } |
379 | ||
6c2e7392 | 380 | cur_bfd = 0; |
80d68b1d FF |
381 | } |
382 | ||
d747e0af | 383 | /* Allocate zeroed memory */ |
bd5635a1 | 384 | |
84ffdec2 | 385 | static PTR |
5f7b2142 | 386 | xzalloc (size) |
e10a3052 | 387 | unsigned int size; |
bd5635a1 | 388 | { |
51b57ded | 389 | PTR p = xmalloc (size); |
bd5635a1 | 390 | |
4ed3a9ea | 391 | memset (p, 0, size); |
51b57ded | 392 | return p; |
bd5635a1 RP |
393 | } |
394 | ||
395 | /* Exported procedure: Builds a symtab from the PST partial one. | |
396 | Restores the environment in effect when PST was created, delegates | |
397 | most of the work to an ancillary procedure, and sorts | |
398 | and reorders the symtab list at the end */ | |
399 | ||
3eaebb75 | 400 | static void |
5f7b2142 ILT |
401 | mipscoff_psymtab_to_symtab (pst) |
402 | struct partial_symtab *pst; | |
bd5635a1 | 403 | { |
bd5635a1 | 404 | |
5f7b2142 ILT |
405 | if (!pst) |
406 | return; | |
bd5635a1 | 407 | |
5f7b2142 ILT |
408 | if (info_verbose) |
409 | { | |
410 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
411 | fflush (stdout); | |
412 | } | |
6c2e7392 PS |
413 | /* Get the BFD and list of pending typedefs */ |
414 | cur_bfd = CUR_BFD (pst); | |
bd5635a1 | 415 | |
5f7b2142 | 416 | next_symbol_text_func = mips_next_symbol_text; |
c55e6167 | 417 | |
5f7b2142 | 418 | psymtab_to_symtab_1 (pst, pst->filename); |
bd5635a1 | 419 | |
5f7b2142 ILT |
420 | /* Match with global symbols. This only needs to be done once, |
421 | after all of the symtabs and dependencies have been read in. */ | |
422 | scan_file_globals (pst->objfile); | |
bd5635a1 | 423 | |
5f7b2142 ILT |
424 | if (info_verbose) |
425 | printf_filtered ("done.\n"); | |
bd5635a1 RP |
426 | } |
427 | ||
428 | /* Exported procedure: Is PC in the signal trampoline code */ | |
429 | ||
b8c50f09 | 430 | int |
5f7b2142 ILT |
431 | in_sigtramp (pc, ignore) |
432 | CORE_ADDR pc; | |
433 | char *ignore; /* function name */ | |
bd5635a1 | 434 | { |
5f7b2142 ILT |
435 | if (sigtramp_address == 0) |
436 | fixup_sigtramp (); | |
437 | return (pc >= sigtramp_address && pc < sigtramp_end); | |
bd5635a1 | 438 | } |
bd5635a1 RP |
439 | \f |
440 | /* File-level interface functions */ | |
441 | ||
6c2e7392 | 442 | /* Read the symtab information from file ABFD into memory. */ |
d747e0af MT |
443 | |
444 | static void | |
6c2e7392 | 445 | read_the_mips_symtab (abfd) |
5f7b2142 | 446 | bfd *abfd; |
bd5635a1 | 447 | { |
6c2e7392 PS |
448 | if (ecoff_slurp_symbolic_info (abfd) == false) |
449 | error ("Error reading symbol table: %s", bfd_errmsg (bfd_error)); | |
bd5635a1 RP |
450 | } |
451 | ||
bd5635a1 RP |
452 | /* Find a file descriptor given its index RF relative to a file CF */ |
453 | ||
3eaebb75 SG |
454 | static FDR * |
455 | get_rfd (cf, rf) | |
5f7b2142 | 456 | int cf, rf; |
bd5635a1 | 457 | { |
6c2e7392 | 458 | FDR *fdrs; |
5f7b2142 | 459 | register FDR *f; |
6c2e7392 | 460 | RFDT rfd; |
5f7b2142 | 461 | |
6c2e7392 PS |
462 | fdrs = ecoff_data (cur_bfd)->fdr; |
463 | f = fdrs + cf; | |
5f7b2142 ILT |
464 | /* Object files do not have the RFD table, all refs are absolute */ |
465 | if (f->rfdBase == 0) | |
6c2e7392 PS |
466 | return fdrs + rf; |
467 | ecoff_swap_rfd_in (cur_bfd, | |
468 | ecoff_data (cur_bfd)->external_rfd + f->rfdBase + rf, | |
469 | &rfd); | |
470 | return fdrs + rfd; | |
bd5635a1 RP |
471 | } |
472 | ||
473 | /* Return a safer print NAME for a file descriptor */ | |
474 | ||
3eaebb75 | 475 | static char * |
6c2e7392 PS |
476 | fdr_name (f) |
477 | FDR *f; | |
bd5635a1 | 478 | { |
6c2e7392 | 479 | if (f->rss == -1) |
5f7b2142 | 480 | return "<stripped file>"; |
6c2e7392 | 481 | if (f->rss == 0) |
5f7b2142 | 482 | return "<NFY>"; |
6c2e7392 | 483 | return ecoff_data (cur_bfd)->ss + f->issBase + f->rss; |
bd5635a1 RP |
484 | } |
485 | ||
486 | ||
dac4929a SG |
487 | /* Read in and parse the symtab of the file OBJFILE. Symbols from |
488 | different sections are relocated via the SECTION_OFFSETS. */ | |
bd5635a1 | 489 | |
d747e0af | 490 | static void |
dac4929a | 491 | read_mips_symtab (objfile, section_offsets) |
5f7b2142 ILT |
492 | struct objfile *objfile; |
493 | struct section_offsets *section_offsets; | |
bd5635a1 | 494 | { |
6c2e7392 | 495 | cur_bfd = objfile->obfd; |
bd5635a1 | 496 | |
6c2e7392 | 497 | read_the_mips_symtab (objfile->obfd); |
bd5635a1 | 498 | |
6c2e7392 | 499 | parse_partial_symbols (objfile, section_offsets); |
bd5635a1 | 500 | |
7e258d18 | 501 | #if 0 |
6c2e7392 PS |
502 | /* Check to make sure file was compiled with -g. If not, warn the |
503 | user of this limitation. */ | |
5f7b2142 ILT |
504 | if (compare_glevel (max_glevel, GLEVEL_2) < 0) |
505 | { | |
506 | if (max_gdbinfo == 0) | |
6c2e7392 | 507 | printf ("\n%s not compiled with -g, debugging support is limited.\n", |
5f7b2142 | 508 | objfile->name); |
6c2e7392 | 509 | printf ("You should compile with -g2 or -g3 for best debugging support.\n"); |
5f7b2142 ILT |
510 | fflush (stdout); |
511 | } | |
7e258d18 | 512 | #endif |
bd5635a1 | 513 | } |
bd5635a1 RP |
514 | \f |
515 | /* Local utilities */ | |
516 | ||
bd5635a1 RP |
517 | /* Map of FDR indexes to partial symtabs */ |
518 | ||
5f7b2142 ILT |
519 | struct pst_map |
520 | { | |
521 | struct partial_symtab *pst; /* the psymtab proper */ | |
522 | int n_globals; /* exported globals (external symbols) */ | |
523 | int globals_offset; /* cumulative */ | |
d4ea2aba | 524 | }; |
bd5635a1 RP |
525 | |
526 | ||
527 | /* Utility stack, used to nest procedures and blocks properly. | |
528 | It is a doubly linked list, to avoid too many alloc/free. | |
529 | Since we might need it quite a few times it is NOT deallocated | |
530 | after use. */ | |
531 | ||
5f7b2142 ILT |
532 | static struct parse_stack |
533 | { | |
534 | struct parse_stack *next, *prev; | |
535 | struct symtab *cur_st; /* Current symtab. */ | |
536 | struct block *cur_block; /* Block in it. */ | |
537 | int blocktype; /* What are we parsing. */ | |
538 | int maxsyms; /* Max symbols in this block. */ | |
539 | struct type *cur_type; /* Type we parse fields for. */ | |
540 | int cur_field; /* Field number in cur_type. */ | |
541 | int procadr; /* Start addres of this procedure */ | |
542 | int numargs; /* Its argument count */ | |
6c2e7392 PS |
543 | } |
544 | ||
545 | *top_stack; /* Top stack ptr */ | |
bd5635a1 RP |
546 | |
547 | ||
548 | /* Enter a new lexical context */ | |
549 | ||
4ad1963e | 550 | static void |
5f7b2142 | 551 | push_parse_stack () |
bd5635a1 | 552 | { |
5f7b2142 ILT |
553 | struct parse_stack *new; |
554 | ||
555 | /* Reuse frames if possible */ | |
556 | if (top_stack && top_stack->prev) | |
557 | new = top_stack->prev; | |
558 | else | |
559 | new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack)); | |
560 | /* Initialize new frame with previous content */ | |
561 | if (top_stack) | |
562 | { | |
563 | register struct parse_stack *prev = new->prev; | |
bd5635a1 | 564 | |
5f7b2142 ILT |
565 | *new = *top_stack; |
566 | top_stack->prev = new; | |
567 | new->prev = prev; | |
568 | new->next = top_stack; | |
569 | } | |
570 | top_stack = new; | |
bd5635a1 RP |
571 | } |
572 | ||
573 | /* Exit a lexical context */ | |
574 | ||
4ad1963e | 575 | static void |
5f7b2142 | 576 | pop_parse_stack () |
bd5635a1 | 577 | { |
5f7b2142 ILT |
578 | if (!top_stack) |
579 | return; | |
580 | if (top_stack->next) | |
581 | top_stack = top_stack->next; | |
bd5635a1 RP |
582 | } |
583 | ||
584 | ||
585 | /* Cross-references might be to things we haven't looked at | |
586 | yet, e.g. type references. To avoid too many type | |
587 | duplications we keep a quick fixup table, an array | |
588 | of lists of references indexed by file descriptor */ | |
589 | ||
5f7b2142 ILT |
590 | static struct mips_pending |
591 | { | |
592 | struct mips_pending *next; /* link */ | |
6c2e7392 | 593 | struct sym_ext *s; /* the symbol */ |
5f7b2142 | 594 | struct type *t; /* its partial type descriptor */ |
bd5635a1 RP |
595 | } **pending_list; |
596 | ||
597 | ||
598 | /* Check whether we already saw symbol SH in file FH as undefined */ | |
599 | ||
4ad1963e | 600 | static struct mips_pending * |
5f7b2142 ILT |
601 | is_pending_symbol (fh, sh) |
602 | FDR *fh; | |
6c2e7392 | 603 | struct sym_ext *sh; |
bd5635a1 | 604 | { |
6c2e7392 | 605 | int f_idx = fh - ecoff_data (cur_bfd)->fdr; |
5f7b2142 ILT |
606 | register struct mips_pending *p; |
607 | ||
608 | /* Linear search is ok, list is typically no more than 10 deep */ | |
609 | for (p = pending_list[f_idx]; p; p = p->next) | |
610 | if (p->s == sh) | |
611 | break; | |
612 | return p; | |
bd5635a1 RP |
613 | } |
614 | ||
bd5635a1 RP |
615 | /* Add a new undef symbol SH of type T */ |
616 | ||
4ad1963e | 617 | static void |
5f7b2142 ILT |
618 | add_pending (fh, sh, t) |
619 | FDR *fh; | |
6c2e7392 | 620 | struct sym_ext *sh; |
5f7b2142 | 621 | struct type *t; |
bd5635a1 | 622 | { |
6c2e7392 | 623 | int f_idx = fh - ecoff_data (cur_bfd)->fdr; |
5f7b2142 ILT |
624 | struct mips_pending *p = is_pending_symbol (fh, sh); |
625 | ||
626 | /* Make sure we do not make duplicates */ | |
627 | if (!p) | |
628 | { | |
629 | p = (struct mips_pending *) xmalloc (sizeof (*p)); | |
630 | p->s = sh; | |
631 | p->t = t; | |
632 | p->next = pending_list[f_idx]; | |
633 | pending_list[f_idx] = p; | |
634 | } | |
bd5635a1 RP |
635 | } |
636 | ||
637 | /* Throw away undef entries when done with file index F_IDX */ | |
84ffdec2 | 638 | /* FIXME -- storage leak. This is never called!!! --gnu */ |
bd5635a1 | 639 | |
51b57ded FF |
640 | #if 0 |
641 | ||
4ad1963e | 642 | static void |
5f7b2142 ILT |
643 | free_pending (f_idx) |
644 | int f_idx; | |
bd5635a1 | 645 | { |
5f7b2142 | 646 | register struct mips_pending *p, *q; |
bd5635a1 | 647 | |
5f7b2142 ILT |
648 | for (p = pending_list[f_idx]; p; p = q) |
649 | { | |
650 | q = p->next; | |
651 | free ((PTR) p); | |
652 | } | |
653 | pending_list[f_idx] = 0; | |
bd5635a1 RP |
654 | } |
655 | ||
51b57ded FF |
656 | #endif |
657 | ||
4ad1963e | 658 | static char * |
5f7b2142 | 659 | prepend_tag_kind (tag_name, type_code) |
bd49ef36 | 660 | char *tag_name; |
e5578a31 | 661 | enum type_code type_code; |
bd49ef36 | 662 | { |
5f7b2142 ILT |
663 | char *prefix; |
664 | char *result; | |
665 | switch (type_code) | |
666 | { | |
667 | case TYPE_CODE_ENUM: | |
668 | prefix = "enum "; | |
669 | break; | |
670 | case TYPE_CODE_STRUCT: | |
671 | prefix = "struct "; | |
672 | break; | |
673 | case TYPE_CODE_UNION: | |
674 | prefix = "union "; | |
675 | break; | |
676 | default: | |
677 | prefix = ""; | |
bd49ef36 PB |
678 | } |
679 | ||
5f7b2142 ILT |
680 | result = (char *) obstack_alloc (¤t_objfile->symbol_obstack, |
681 | strlen (prefix) + strlen (tag_name) + 1); | |
682 | sprintf (result, "%s%s", prefix, tag_name); | |
683 | return result; | |
bd49ef36 | 684 | } |
bd5635a1 | 685 | \f |
5f7b2142 | 686 | |
bd5635a1 RP |
687 | /* Parsing Routines proper. */ |
688 | ||
689 | /* Parse a single symbol. Mostly just make up a GDB symbol for it. | |
690 | For blocks, procedures and types we open a new lexical context. | |
6c2e7392 PS |
691 | This is basically just a big switch on the symbol's type. Argument |
692 | AX is the base pointer of aux symbols for this file (fh->iauxBase). | |
693 | EXT_SH points to the unswapped symbol, which is needed for struct, | |
694 | union, etc., types; it is NULL for an EXTR. BIGEND says whether | |
695 | aux symbols are big-endian or little-endian. Return count of | |
696 | SYMR's handled (normally one). | |
697 | ||
698 | FIXME: This modifies the symbol, but the only way we have to save | |
699 | the modified information is to stuff it back into the BFD data. */ | |
bd5635a1 | 700 | |
7e258d18 | 701 | static int |
6c2e7392 | 702 | parse_symbol (sh, ax, ext_sh, bigend) |
5f7b2142 ILT |
703 | SYMR *sh; |
704 | union aux_ext *ax; | |
6c2e7392 | 705 | struct sym_ext *ext_sh; |
5f7b2142 | 706 | int bigend; |
bd5635a1 | 707 | { |
5f7b2142 ILT |
708 | char *name; |
709 | struct symbol *s; | |
710 | struct block *b; | |
6c2e7392 | 711 | struct mips_pending *pend; |
5f7b2142 ILT |
712 | struct type *t; |
713 | struct field *f; | |
714 | int count = 1; | |
5f7b2142 ILT |
715 | enum address_class class; |
716 | TIR tir; | |
717 | ||
6c2e7392 PS |
718 | if (ext_sh == (struct sym_ext *) NULL) |
719 | name = ecoff_data (cur_bfd)->ssext + sh->iss; | |
720 | else | |
721 | name = ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh->iss; | |
722 | ||
5f7b2142 ILT |
723 | switch (sh->st) |
724 | { | |
5f7b2142 ILT |
725 | case stNil: |
726 | break; | |
727 | ||
728 | case stGlobal: /* external symbol, goes into global block */ | |
729 | class = LOC_STATIC; | |
730 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st), | |
731 | GLOBAL_BLOCK); | |
6c2e7392 | 732 | s = new_symbol (name); |
5f7b2142 ILT |
733 | SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value; |
734 | goto data; | |
735 | ||
736 | case stStatic: /* static data, goes into current block. */ | |
737 | class = LOC_STATIC; | |
738 | b = top_stack->cur_block; | |
6c2e7392 | 739 | s = new_symbol (name); |
5f7b2142 ILT |
740 | SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value; |
741 | goto data; | |
742 | ||
743 | case stLocal: /* local variable, goes into current block */ | |
744 | if (sh->sc == scRegister) | |
745 | { | |
746 | class = LOC_REGISTER; | |
747 | if (sh->value > 31) | |
748 | sh->value += FP0_REGNUM - 32; | |
749 | } | |
750 | else | |
751 | class = LOC_LOCAL; | |
752 | b = top_stack->cur_block; | |
6c2e7392 | 753 | s = new_symbol (name); |
5f7b2142 ILT |
754 | SYMBOL_VALUE (s) = sh->value; |
755 | ||
756 | data: /* Common code for symbols describing data */ | |
757 | SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; | |
758 | SYMBOL_CLASS (s) = class; | |
759 | add_symbol (s, b); | |
760 | ||
761 | /* Type could be missing in a number of cases */ | |
762 | if (sh->sc == scUndefined || sh->sc == scNil || | |
763 | sh->index == 0xfffff) | |
764 | SYMBOL_TYPE (s) = builtin_type_int; /* undefined? */ | |
765 | else | |
766 | SYMBOL_TYPE (s) = parse_type (ax + sh->index, 0, bigend); | |
767 | /* Value of a data symbol is its memory address */ | |
768 | break; | |
769 | ||
770 | case stParam: /* arg to procedure, goes into current block */ | |
771 | max_gdbinfo++; | |
772 | top_stack->numargs++; | |
773 | ||
5f7b2142 ILT |
774 | /* Special GNU C++ name. */ |
775 | if (name[0] == CPLUS_MARKER && name[1] == 't' && name[2] == 0) | |
776 | name = "this"; /* FIXME, not alloc'd in obstack */ | |
777 | s = new_symbol (name); | |
778 | ||
779 | SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; | |
780 | if (sh->sc == scRegister) | |
781 | { | |
782 | SYMBOL_CLASS (s) = LOC_REGPARM; | |
783 | if (sh->value > 31) | |
784 | sh->value += FP0_REGNUM - 32; | |
785 | } | |
786 | else | |
787 | SYMBOL_CLASS (s) = LOC_ARG; | |
788 | SYMBOL_VALUE (s) = sh->value; | |
789 | SYMBOL_TYPE (s) = parse_type (ax + sh->index, 0, bigend); | |
790 | add_symbol (s, top_stack->cur_block); | |
0c4d2cc2 | 791 | #if 0 |
5f7b2142 ILT |
792 | /* FIXME: This has not been tested. See dbxread.c */ |
793 | /* Add the type of this parameter to the function/procedure | |
0c4d2cc2 | 794 | type of this block. */ |
5f7b2142 | 795 | add_param_to_type (&top_stack->cur_block->function->type, s); |
0c4d2cc2 | 796 | #endif |
5f7b2142 ILT |
797 | break; |
798 | ||
799 | case stLabel: /* label, goes into current block */ | |
6c2e7392 | 800 | s = new_symbol (name); |
5f7b2142 ILT |
801 | SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; /* so that it can be used */ |
802 | SYMBOL_CLASS (s) = LOC_LABEL; /* but not misused */ | |
803 | SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value; | |
804 | SYMBOL_TYPE (s) = builtin_type_int; | |
805 | add_symbol (s, top_stack->cur_block); | |
806 | break; | |
807 | ||
808 | case stProc: /* Procedure, usually goes into global block */ | |
809 | case stStaticProc: /* Static procedure, goes into current block */ | |
6c2e7392 | 810 | s = new_symbol (name); |
5f7b2142 ILT |
811 | SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; |
812 | SYMBOL_CLASS (s) = LOC_BLOCK; | |
813 | /* Type of the return value */ | |
814 | if (sh->sc == scUndefined || sh->sc == scNil) | |
815 | t = builtin_type_int; | |
816 | else | |
817 | t = parse_type (ax + sh->index + 1, 0, bigend); | |
818 | b = top_stack->cur_block; | |
819 | if (sh->st == stProc) | |
820 | { | |
821 | struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st); | |
822 | /* The next test should normally be true, | |
0c4d2cc2 JG |
823 | but provides a hook for nested functions |
824 | (which we don't want to make global). */ | |
5f7b2142 ILT |
825 | if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) |
826 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
827 | } | |
828 | add_symbol (s, b); | |
bd5635a1 | 829 | |
5f7b2142 | 830 | /* Make a type for the procedure itself */ |
0c4d2cc2 | 831 | #if 0 |
5f7b2142 ILT |
832 | /* FIXME: This has not been tested yet! See dbxread.c */ |
833 | /* Generate a template for the type of this function. The | |
834 | types of the arguments will be added as we read the symbol | |
835 | table. */ | |
836 | bcopy (SYMBOL_TYPE (s), lookup_function_type (t), sizeof (struct type)); | |
0c4d2cc2 | 837 | #else |
5f7b2142 | 838 | SYMBOL_TYPE (s) = lookup_function_type (t); |
0c4d2cc2 | 839 | #endif |
bd5635a1 | 840 | |
5f7b2142 ILT |
841 | /* Create and enter a new lexical context */ |
842 | b = new_block (top_stack->maxsyms); | |
843 | SYMBOL_BLOCK_VALUE (s) = b; | |
844 | BLOCK_FUNCTION (b) = s; | |
845 | BLOCK_START (b) = BLOCK_END (b) = sh->value; | |
846 | BLOCK_SUPERBLOCK (b) = top_stack->cur_block; | |
847 | add_block (b, top_stack->cur_st); | |
848 | ||
849 | /* Not if we only have partial info */ | |
850 | if (sh->sc == scUndefined || sh->sc == scNil) | |
851 | break; | |
852 | ||
853 | push_parse_stack (); | |
854 | top_stack->cur_block = b; | |
855 | top_stack->blocktype = sh->st; | |
856 | top_stack->cur_type = SYMBOL_TYPE (s); | |
857 | top_stack->cur_field = -1; | |
858 | top_stack->procadr = sh->value; | |
859 | top_stack->numargs = 0; | |
860 | ||
861 | sh->value = (long) SYMBOL_TYPE (s); | |
862 | break; | |
863 | ||
864 | /* Beginning of code for structure, union, and enum definitions. | |
817bc7b8 | 865 | They all share a common set of local variables, defined here. */ |
5f7b2142 ILT |
866 | { |
867 | enum type_code type_code; | |
6c2e7392 | 868 | struct sym_ext *ext_tsym; |
5f7b2142 ILT |
869 | int nfields; |
870 | long max_value; | |
871 | struct field *f; | |
872 | ||
873 | case stStruct: /* Start a block defining a struct type */ | |
874 | type_code = TYPE_CODE_STRUCT; | |
875 | goto structured_common; | |
876 | ||
877 | case stUnion: /* Start a block defining a union type */ | |
878 | type_code = TYPE_CODE_UNION; | |
879 | goto structured_common; | |
880 | ||
881 | case stEnum: /* Start a block defining an enum type */ | |
882 | type_code = TYPE_CODE_ENUM; | |
883 | goto structured_common; | |
884 | ||
885 | case stBlock: /* Either a lexical block, or some type */ | |
886 | if (sh->sc != scInfo) | |
887 | goto case_stBlock_code; /* Lexical block */ | |
888 | ||
889 | type_code = TYPE_CODE_UNDEF; /* We have a type. */ | |
890 | ||
891 | /* Common code for handling struct, union, enum, and/or as-yet- | |
892 | unknown-type blocks of info about structured data. `type_code' | |
893 | has been set to the proper TYPE_CODE, if we know it. */ | |
894 | structured_common: | |
895 | push_parse_stack (); | |
896 | top_stack->blocktype = stBlock; | |
897 | ||
6c2e7392 | 898 | s = new_symbol (name); |
5f7b2142 ILT |
899 | SYMBOL_NAMESPACE (s) = STRUCT_NAMESPACE; |
900 | SYMBOL_CLASS (s) = LOC_TYPEDEF; | |
901 | SYMBOL_VALUE (s) = 0; | |
902 | add_symbol (s, top_stack->cur_block); | |
903 | ||
904 | /* First count the number of fields and the highest value. */ | |
905 | nfields = 0; | |
906 | max_value = 0; | |
6c2e7392 | 907 | for (ext_tsym = ext_sh + 1; ; ext_tsym++) |
5f7b2142 | 908 | { |
6c2e7392 PS |
909 | SYMR tsym; |
910 | ||
911 | ecoff_swap_sym_in (cur_bfd, ext_tsym, &tsym); | |
912 | ||
913 | if (tsym.st == stEnd) | |
914 | break; | |
915 | ||
916 | if (tsym.st == stMember) | |
5f7b2142 ILT |
917 | { |
918 | if (nfields == 0 && type_code == TYPE_CODE_UNDEF) | |
919 | /* If the type of the member is Nil (or Void), | |
920 | without qualifiers, assume the tag is an | |
921 | enumeration. */ | |
6c2e7392 | 922 | if (tsym.index == indexNil) |
5f7b2142 ILT |
923 | type_code = TYPE_CODE_ENUM; |
924 | else | |
925 | { | |
926 | ecoff_swap_tir_in (bigend, | |
6c2e7392 | 927 | &ax[tsym.index].a_ti, |
5f7b2142 ILT |
928 | &tir); |
929 | if ((tir.bt == btNil || tir.bt == btVoid) | |
930 | && tir.tq0 == tqNil) | |
931 | type_code = TYPE_CODE_ENUM; | |
817bc7b8 | 932 | } |
5f7b2142 | 933 | nfields++; |
6c2e7392 PS |
934 | if (tsym.value > max_value) |
935 | max_value = tsym.value; | |
5f7b2142 | 936 | } |
6c2e7392 PS |
937 | else if (tsym.st == stBlock |
938 | || tsym.st == stUnion | |
939 | || tsym.st == stEnum | |
940 | || tsym.st == stStruct | |
941 | || tsym.st == stParsed) | |
5f7b2142 | 942 | { |
6c2e7392 PS |
943 | if (tsym.sc == scVariant); /*UNIMPLEMENTED*/ |
944 | if (tsym.index != 0) | |
945 | { | |
946 | /* This is something like a struct within a | |
947 | struct. Skip over the fields of the inner | |
948 | struct. The -1 is because the for loop will | |
949 | increment ext_tsym. */ | |
950 | ext_tsym = (ecoff_data (cur_bfd)->external_sym | |
951 | + cur_fdr->isymBase | |
952 | + tsym.index | |
953 | - 1); | |
954 | } | |
5f7b2142 ILT |
955 | } |
956 | else | |
6c2e7392 | 957 | complain (&block_member_complaint, tsym.st); |
5f7b2142 ILT |
958 | } |
959 | ||
960 | /* In an stBlock, there is no way to distinguish structs, | |
961 | unions, and enums at this point. This is a bug in the | |
962 | original design (that has been fixed with the recent | |
963 | addition of the stStruct, stUnion, and stEnum symbol | |
964 | types.) The way you can tell is if/when you see a variable | |
965 | or field of that type. In that case the variable's type | |
966 | (in the AUX table) says if the type is struct, union, or | |
967 | enum, and points back to the stBlock here. So you can | |
968 | patch the tag kind up later - but only if there actually is | |
969 | a variable or field of that type. | |
970 | ||
971 | So until we know for sure, we will guess at this point. | |
972 | The heuristic is: | |
973 | If the first member has index==indexNil or a void type, | |
974 | assume we have an enumeration. | |
975 | Otherwise, if there is more than one member, and all | |
976 | the members have offset 0, assume we have a union. | |
977 | Otherwise, assume we have a struct. | |
978 | ||
979 | The heuristic could guess wrong in the case of of an | |
980 | enumeration with no members or a union with one (or zero) | |
981 | members, or when all except the last field of a struct have | |
982 | width zero. These are uncommon and/or illegal situations, | |
983 | and in any case guessing wrong probably doesn't matter | |
984 | much. | |
985 | ||
986 | But if we later do find out we were wrong, we fixup the tag | |
987 | kind. Members of an enumeration must be handled | |
988 | differently from struct/union fields, and that is harder to | |
989 | patch up, but luckily we shouldn't need to. (If there are | |
990 | any enumeration members, we can tell for sure it's an enum | |
991 | here.) */ | |
992 | ||
993 | if (type_code == TYPE_CODE_UNDEF) | |
994 | if (nfields > 1 && max_value == 0) | |
995 | type_code = TYPE_CODE_UNION; | |
996 | else | |
997 | type_code = TYPE_CODE_STRUCT; | |
998 | ||
999 | /* If this type was expected, use its partial definition */ | |
6c2e7392 PS |
1000 | pend = is_pending_symbol (cur_fdr, ext_sh); |
1001 | if (pend != (struct mips_pending *) NULL) | |
1002 | t = pend->t; | |
5f7b2142 | 1003 | else |
6c2e7392 | 1004 | t = new_type (prepend_tag_kind (name, type_code)); |
5f7b2142 ILT |
1005 | |
1006 | TYPE_CODE (t) = type_code; | |
1007 | TYPE_LENGTH (t) = sh->value; | |
1008 | TYPE_NFIELDS (t) = nfields; | |
6c2e7392 PS |
1009 | TYPE_FIELDS (t) = f = ((struct field *) |
1010 | TYPE_ALLOC (t, | |
1011 | nfields * sizeof (struct field))); | |
5f7b2142 ILT |
1012 | |
1013 | if (type_code == TYPE_CODE_ENUM) | |
1014 | { | |
1015 | /* This is a non-empty enum. */ | |
6c2e7392 | 1016 | for (ext_tsym = ext_sh + 1; ; ext_tsym++) |
5f7b2142 | 1017 | { |
6c2e7392 | 1018 | SYMR tsym; |
5f7b2142 | 1019 | struct symbol *enum_sym; |
6c2e7392 PS |
1020 | |
1021 | ecoff_swap_sym_in (cur_bfd, ext_tsym, &tsym); | |
1022 | ||
1023 | if (tsym.st != stMember) | |
1024 | break; | |
1025 | ||
1026 | f->bitpos = tsym.value; | |
5f7b2142 | 1027 | f->type = t; |
6c2e7392 PS |
1028 | f->name = (ecoff_data (cur_bfd)->ss |
1029 | + cur_fdr->issBase | |
1030 | + tsym.iss); | |
5f7b2142 ILT |
1031 | f->bitsize = 0; |
1032 | ||
1033 | enum_sym = ((struct symbol *) | |
817bc7b8 | 1034 | obstack_alloc (¤t_objfile->symbol_obstack, |
5f7b2142 ILT |
1035 | sizeof (struct symbol))); |
1036 | memset ((PTR) enum_sym, 0, sizeof (struct symbol)); | |
1037 | SYMBOL_NAME (enum_sym) = f->name; | |
1038 | SYMBOL_CLASS (enum_sym) = LOC_CONST; | |
1039 | SYMBOL_TYPE (enum_sym) = t; | |
1040 | SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE; | |
6c2e7392 | 1041 | SYMBOL_VALUE (enum_sym) = tsym.value; |
5f7b2142 ILT |
1042 | add_symbol (enum_sym, top_stack->cur_block); |
1043 | ||
1044 | /* Skip the stMembers that we've handled. */ | |
1045 | count++; | |
1046 | f++; | |
1047 | } | |
1048 | } | |
1049 | SYMBOL_TYPE (s) = t; | |
1050 | /* make this the current type */ | |
1051 | top_stack->cur_type = t; | |
1052 | top_stack->cur_field = 0; | |
1053 | /* Mark that symbol has a type, and say which one */ | |
1054 | sh->value = (long) t; | |
1055 | break; | |
1056 | ||
1057 | /* End of local variables shared by struct, union, enum, and | |
1058 | block (as yet unknown struct/union/enum) processing. */ | |
1059 | } | |
817bc7b8 | 1060 | |
5f7b2142 ILT |
1061 | case_stBlock_code: |
1062 | /* beginnning of (code) block. Value of symbol | |
1063 | is the displacement from procedure start */ | |
1064 | push_parse_stack (); | |
1065 | top_stack->blocktype = stBlock; | |
1066 | b = new_block (top_stack->maxsyms); | |
1067 | BLOCK_START (b) = sh->value + top_stack->procadr; | |
1068 | BLOCK_SUPERBLOCK (b) = top_stack->cur_block; | |
1069 | top_stack->cur_block = b; | |
1070 | add_block (b, top_stack->cur_st); | |
1071 | break; | |
1072 | ||
1073 | case stEnd: /* end (of anything) */ | |
1074 | if (sh->sc == scInfo) | |
1075 | { | |
1076 | /* Finished with type */ | |
1077 | top_stack->cur_type = 0; | |
1078 | } | |
6c2e7392 PS |
1079 | else if (sh->sc == scText && |
1080 | (top_stack->blocktype == stProc || | |
1081 | top_stack->blocktype == stStaticProc)) | |
5f7b2142 ILT |
1082 | { |
1083 | /* Finished with procedure */ | |
1084 | struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st); | |
1085 | struct mips_extra_func_info *e; | |
1086 | struct block *b; | |
1087 | int i; | |
1088 | ||
1089 | BLOCK_END (top_stack->cur_block) += sh->value; /* size */ | |
1090 | ||
1091 | /* Make up special symbol to contain procedure specific info */ | |
1092 | s = new_symbol (MIPS_EFI_SYMBOL_NAME); | |
1093 | SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE; | |
1094 | SYMBOL_CLASS (s) = LOC_CONST; | |
1095 | SYMBOL_TYPE (s) = builtin_type_void; | |
1096 | e = ((struct mips_extra_func_info *) | |
1097 | obstack_alloc (¤t_objfile->symbol_obstack, | |
1098 | sizeof (struct mips_extra_func_info))); | |
1099 | SYMBOL_VALUE (s) = (int) e; | |
1100 | e->numargs = top_stack->numargs; | |
1101 | add_symbol (s, top_stack->cur_block); | |
1102 | ||
1103 | /* Reallocate symbols, saving memory */ | |
1104 | b = shrink_block (top_stack->cur_block, top_stack->cur_st); | |
1105 | ||
1106 | /* f77 emits proc-level with address bounds==[0,0], | |
6c2e7392 | 1107 | So look for such child blocks, and patch them. */ |
5f7b2142 ILT |
1108 | for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++) |
1109 | { | |
1110 | struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i); | |
1111 | if (BLOCK_SUPERBLOCK (b_bad) == b | |
1112 | && BLOCK_START (b_bad) == top_stack->procadr | |
1113 | && BLOCK_END (b_bad) == top_stack->procadr) | |
1114 | { | |
1115 | BLOCK_START (b_bad) = BLOCK_START (b); | |
1116 | BLOCK_END (b_bad) = BLOCK_END (b); | |
1117 | } | |
1118 | } | |
1119 | } | |
1120 | else if (sh->sc == scText && top_stack->blocktype == stBlock) | |
1121 | { | |
6c2e7392 PS |
1122 | /* End of (code) block. The value of the symbol is the |
1123 | displacement from the procedure`s start address of the | |
1124 | end of this block. */ | |
5f7b2142 ILT |
1125 | BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr; |
1126 | shrink_block (top_stack->cur_block, top_stack->cur_st); | |
1127 | } | |
1128 | else if (sh->sc == scText && top_stack->blocktype == stFile) | |
1129 | { | |
1130 | /* End of file. Pop parse stack and ignore. Higher | |
6c2e7392 | 1131 | level code deals with this. */ |
5f7b2142 | 1132 | ; |
bd5635a1 | 1133 | } |
5f7b2142 ILT |
1134 | else |
1135 | complain (&stEnd_complaint, sh->sc); | |
1136 | ||
1137 | pop_parse_stack (); /* restore previous lexical context */ | |
1138 | break; | |
1139 | ||
1140 | case stMember: /* member of struct or union */ | |
1141 | f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++]; | |
6c2e7392 | 1142 | f->name = name; |
5f7b2142 ILT |
1143 | f->bitpos = sh->value; |
1144 | f->bitsize = 0; | |
1145 | f->type = parse_type (ax + sh->index, &f->bitsize, bigend); | |
1146 | break; | |
1147 | ||
1148 | case stTypedef: /* type definition */ | |
6c2e7392 | 1149 | s = new_symbol (name); |
5f7b2142 ILT |
1150 | SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; |
1151 | SYMBOL_CLASS (s) = LOC_TYPEDEF; | |
1152 | SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block; | |
1153 | add_symbol (s, top_stack->cur_block); | |
1154 | SYMBOL_TYPE (s) = parse_type (ax + sh->index, 0, bigend); | |
1155 | sh->value = (long) SYMBOL_TYPE (s); | |
1156 | break; | |
1157 | ||
1158 | case stFile: /* file name */ | |
1159 | push_parse_stack (); | |
1160 | top_stack->blocktype = sh->st; | |
1161 | break; | |
1162 | ||
1163 | /* I`ve never seen these for C */ | |
1164 | case stRegReloc: | |
1165 | break; /* register relocation */ | |
1166 | case stForward: | |
1167 | break; /* forwarding address */ | |
1168 | case stConstant: | |
1169 | break; /* constant */ | |
1170 | default: | |
1171 | complain (&unknown_mips_symtype_complaint, sh->st); | |
1172 | break; | |
1173 | } | |
6c2e7392 | 1174 | |
5f7b2142 | 1175 | sh->st = stParsed; |
6c2e7392 | 1176 | |
5f7b2142 | 1177 | return count; |
bd5635a1 RP |
1178 | } |
1179 | ||
d747e0af MT |
1180 | /* Parse the type information provided in the raw AX entries for |
1181 | the symbol SH. Return the bitfield size in BS, in case. | |
1182 | We must byte-swap the AX entries before we use them; BIGEND says whether | |
1183 | they are big-endian or little-endian (from fh->fBigendian). */ | |
bd5635a1 | 1184 | |
84ffdec2 | 1185 | static struct type * |
5f7b2142 ILT |
1186 | parse_type (ax, bs, bigend) |
1187 | union aux_ext *ax; | |
1188 | int *bs; | |
1189 | int bigend; | |
bd5635a1 | 1190 | { |
5f7b2142 ILT |
1191 | /* Null entries in this map are treated specially */ |
1192 | static struct type **map_bt[] = | |
1193 | { | |
1194 | &builtin_type_void, /* btNil */ | |
1195 | 0, /* btAdr */ | |
1196 | &builtin_type_char, /* btChar */ | |
1197 | &builtin_type_unsigned_char,/* btUChar */ | |
1198 | &builtin_type_short, /* btShort */ | |
1199 | &builtin_type_unsigned_short, /* btUShort */ | |
1200 | &builtin_type_int, /* btInt */ | |
1201 | &builtin_type_unsigned_int, /* btUInt */ | |
1202 | &builtin_type_long, /* btLong */ | |
1203 | &builtin_type_unsigned_long,/* btULong */ | |
1204 | &builtin_type_float, /* btFloat */ | |
1205 | &builtin_type_double, /* btDouble */ | |
1206 | 0, /* btStruct */ | |
1207 | 0, /* btUnion */ | |
1208 | 0, /* btEnum */ | |
1209 | 0, /* btTypedef */ | |
1210 | 0, /* btRange */ | |
1211 | 0, /* btSet */ | |
1212 | &builtin_type_complex, /* btComplex */ | |
1213 | &builtin_type_double_complex, /* btDComplex */ | |
1214 | 0, /* btIndirect */ | |
1215 | &builtin_type_fixed_dec, /* btFixedDec */ | |
1216 | &builtin_type_float_dec, /* btFloatDec */ | |
1217 | &builtin_type_string, /* btString */ | |
1218 | 0, /* btBit */ | |
1219 | 0, /* btPicture */ | |
1220 | &builtin_type_void, /* btVoid */ | |
1221 | &builtin_type_long_long, /* btLongLong */ | |
1222 | &builtin_type_unsigned_long_long, /* btULongLong */ | |
1223 | }; | |
1224 | ||
1225 | TIR t[1]; | |
1226 | struct type *tp = 0; | |
1227 | char *fmt; | |
1228 | union aux_ext *tax; | |
6c2e7392 | 1229 | enum type_code type_code = TYPE_CODE_UNDEF; |
5f7b2142 ILT |
1230 | |
1231 | /* Use aux as a type information record, map its basic type. */ | |
1232 | tax = ax; | |
1233 | ecoff_swap_tir_in (bigend, &tax->a_ti, t); | |
1234 | if (t->bt > (sizeof (map_bt) / sizeof (*map_bt))) | |
1235 | { | |
1236 | complain (&basic_type_complaint, t->bt); | |
1237 | return builtin_type_int; | |
1238 | } | |
1239 | if (map_bt[t->bt]) | |
1240 | { | |
1241 | tp = *map_bt[t->bt]; | |
1242 | fmt = "%s"; | |
1243 | } | |
1244 | else | |
1245 | { | |
1246 | tp = NULL; | |
1247 | /* Cannot use builtin types -- build our own */ | |
1248 | switch (t->bt) | |
bd5635a1 | 1249 | { |
5f7b2142 ILT |
1250 | case btAdr: |
1251 | tp = lookup_pointer_type (builtin_type_void); | |
1252 | fmt = "%s"; | |
1253 | break; | |
1254 | case btStruct: | |
1255 | type_code = TYPE_CODE_STRUCT; | |
1256 | fmt = "struct %s"; | |
1257 | break; | |
1258 | case btUnion: | |
1259 | type_code = TYPE_CODE_UNION; | |
1260 | fmt = "union %s"; | |
1261 | break; | |
1262 | case btEnum: | |
1263 | type_code = TYPE_CODE_ENUM; | |
1264 | fmt = "enum %s"; | |
1265 | break; | |
1266 | case btRange: | |
1267 | type_code = TYPE_CODE_RANGE; | |
1268 | fmt = "%s"; | |
1269 | break; | |
1270 | case btSet: | |
1271 | type_code = TYPE_CODE_SET; | |
1272 | fmt = "set %s"; | |
1273 | break; | |
1274 | case btTypedef: | |
1275 | default: | |
1276 | complain (&basic_type_complaint, t->bt); | |
1277 | return builtin_type_int; | |
bd5635a1 | 1278 | } |
5f7b2142 | 1279 | } |
bd5635a1 | 1280 | |
5f7b2142 ILT |
1281 | /* Skip over any further type qualifiers (FIXME). */ |
1282 | if (t->continued) | |
1283 | { | |
1284 | /* This is the way it would work if the compiler worked */ | |
1285 | TIR t1[1]; | |
1286 | do | |
1287 | { | |
1288 | ax++; | |
6c2e7392 | 1289 | ecoff_swap_tir_in (bigend, &ax->a_ti, t1); |
bd5635a1 | 1290 | } |
5f7b2142 ILT |
1291 | while (t1->continued); |
1292 | } | |
bd5635a1 | 1293 | |
5f7b2142 ILT |
1294 | /* Move on to next aux */ |
1295 | ax++; | |
d747e0af | 1296 | |
5f7b2142 ILT |
1297 | if (t->fBitfield) |
1298 | { | |
1299 | *bs = AUX_GET_WIDTH (bigend, ax); | |
1300 | ax++; | |
1301 | } | |
bd5635a1 | 1302 | |
5f7b2142 ILT |
1303 | /* All these types really point to some (common) MIPS type |
1304 | definition, and only the type-qualifiers fully identify | |
1305 | them. We'll make the same effort at sharing. */ | |
1306 | if (t->bt == btIndirect || | |
1307 | t->bt == btStruct || | |
1308 | t->bt == btUnion || | |
1309 | t->bt == btEnum || | |
1310 | t->bt == btTypedef || | |
1311 | t->bt == btRange || | |
1312 | t->bt == btSet) | |
1313 | { | |
1314 | char name[256], *pn; | |
1315 | ||
1316 | /* Try to cross reference this type */ | |
1317 | ax += cross_ref (ax, &tp, type_code, &pn, bigend); | |
1318 | /* reading .o file ? */ | |
6c2e7392 | 1319 | if (tp == (struct type *) NULL) |
5f7b2142 ILT |
1320 | tp = init_type (type_code, 0, 0, (char *) NULL, |
1321 | (struct objfile *) NULL); | |
1322 | /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */ | |
1323 | sprintf (name, fmt, pn); | |
1324 | ||
1325 | /* Usually, TYPE_CODE(tp) is already type_code. The main | |
1326 | exception is if we guessed wrong re struct/union/enum. */ | |
1327 | if (TYPE_CODE (tp) != type_code) | |
1328 | { | |
1329 | complain (&bad_tag_guess_complaint, name); | |
1330 | TYPE_CODE (tp) = type_code; | |
bd5635a1 | 1331 | } |
5f7b2142 ILT |
1332 | if (TYPE_NAME (tp) == NULL || !STREQ (TYPE_NAME (tp), name)) |
1333 | TYPE_NAME (tp) = obsavestring (name, strlen (name), | |
1334 | ¤t_objfile->type_obstack); | |
1335 | } | |
bd5635a1 | 1336 | |
5f7b2142 ILT |
1337 | /* Deal with range types */ |
1338 | if (t->bt == btRange) | |
1339 | { | |
1340 | TYPE_NFIELDS (tp) = 2; | |
1341 | TYPE_FIELDS (tp) = ((struct field *) | |
1342 | TYPE_ALLOC (tp, 2 * sizeof (struct field))); | |
1343 | TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"), | |
1344 | ¤t_objfile->type_obstack); | |
1345 | TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax); | |
1346 | ax++; | |
1347 | TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"), | |
1348 | ¤t_objfile->type_obstack); | |
1349 | TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax); | |
1350 | ax++; | |
1351 | } | |
bd5635a1 | 1352 | |
5f7b2142 | 1353 | /* Parse all the type qualifiers now. If there are more |
6c2e7392 | 1354 | than 6 the game will continue in the next aux */ |
bd5635a1 RP |
1355 | |
1356 | #define PARSE_TQ(tq) \ | |
d747e0af | 1357 | if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend); |
bd5635a1 | 1358 | |
5f7b2142 ILT |
1359 | again:PARSE_TQ (tq0); |
1360 | PARSE_TQ (tq1); | |
1361 | PARSE_TQ (tq2); | |
1362 | PARSE_TQ (tq3); | |
1363 | PARSE_TQ (tq4); | |
1364 | PARSE_TQ (tq5); | |
bd5635a1 RP |
1365 | #undef PARSE_TQ |
1366 | ||
5f7b2142 ILT |
1367 | if (t->continued) |
1368 | { | |
1369 | tax++; | |
1370 | ecoff_swap_tir_in (bigend, &tax->a_ti, t); | |
1371 | goto again; | |
1372 | } | |
1373 | return tp; | |
bd5635a1 RP |
1374 | } |
1375 | ||
1376 | /* Make up a complex type from a basic one. Type is passed by | |
1377 | reference in TPP and side-effected as necessary. The type | |
1378 | qualifier TQ says how to handle the aux symbols at AX for | |
d747e0af MT |
1379 | the symbol SX we are currently analyzing. BIGEND says whether |
1380 | aux symbols are big-endian or little-endian. | |
bd5635a1 RP |
1381 | Returns the number of aux symbols we parsed. */ |
1382 | ||
3eaebb75 | 1383 | static int |
5f7b2142 ILT |
1384 | upgrade_type (tpp, tq, ax, bigend) |
1385 | struct type **tpp; | |
1386 | int tq; | |
1387 | union aux_ext *ax; | |
1388 | int bigend; | |
bd5635a1 | 1389 | { |
5f7b2142 ILT |
1390 | int off; |
1391 | struct type *t; | |
1392 | ||
1393 | /* Used in array processing */ | |
1394 | int rf, id; | |
1395 | FDR *fh; | |
1396 | struct type *range; | |
1397 | struct type *indx; | |
1398 | int lower, upper; | |
1399 | RNDXR rndx; | |
1400 | ||
1401 | switch (tq) | |
1402 | { | |
1403 | case tqPtr: | |
1404 | t = lookup_pointer_type (*tpp); | |
1405 | *tpp = t; | |
1406 | return 0; | |
1407 | ||
1408 | case tqProc: | |
1409 | t = lookup_function_type (*tpp); | |
1410 | *tpp = t; | |
1411 | return 0; | |
1412 | ||
1413 | case tqArray: | |
1414 | off = 0; | |
1415 | ||
1416 | /* Determine and record the domain type (type of index) */ | |
6c2e7392 | 1417 | ecoff_swap_rndx_in (bigend, &ax->a_rndx, &rndx); |
5f7b2142 ILT |
1418 | id = rndx.index; |
1419 | rf = rndx.rfd; | |
1420 | if (rf == 0xfff) | |
1421 | { | |
1422 | ax++; | |
1423 | rf = AUX_GET_ISYM (bigend, ax); | |
1424 | off++; | |
1425 | } | |
1426 | fh = get_rfd (cur_fd, rf); | |
1427 | ||
6c2e7392 PS |
1428 | indx = parse_type ((ecoff_data (cur_bfd)->external_aux |
1429 | + fh->iauxBase | |
1430 | + id), | |
5f7b2142 ILT |
1431 | (int *) NULL, bigend); |
1432 | ||
1433 | /* Get the bounds, and create the array type. */ | |
1434 | ax++; | |
1435 | lower = AUX_GET_DNLOW (bigend, ax); | |
1436 | ax++; | |
1437 | upper = AUX_GET_DNHIGH (bigend, ax); | |
1438 | ax++; | |
1439 | rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */ | |
1440 | ||
1441 | range = create_range_type ((struct type *) NULL, indx, | |
1442 | lower, upper); | |
1443 | ||
1444 | t = create_array_type ((struct type *) NULL, *tpp, range); | |
1445 | ||
1446 | /* Check whether supplied array element bit size matches | |
1447 | the known size of the element type. If this complaint | |
1448 | ends up not happening, we can remove this code. It's | |
1449 | here because we aren't sure we understand this *&%&$ | |
1450 | symbol format. */ | |
1451 | id = TYPE_LENGTH (TYPE_TARGET_TYPE (t)) << 3; /* bitsize */ | |
1452 | if (id == 0) | |
1453 | { | |
1454 | /* Most likely an undefined type */ | |
1455 | id = rf; | |
1456 | TYPE_LENGTH (TYPE_TARGET_TYPE (t)) = id >> 3; | |
1457 | } | |
1458 | if (id != rf) | |
1459 | complain (&array_bitsize_complaint, rf); | |
3eaebb75 | 1460 | |
5f7b2142 ILT |
1461 | *tpp = t; |
1462 | return 4 + off; | |
bd5635a1 | 1463 | |
5f7b2142 ILT |
1464 | case tqVol: |
1465 | /* Volatile -- currently ignored */ | |
1466 | return 0; | |
3eaebb75 | 1467 | |
5f7b2142 ILT |
1468 | case tqConst: |
1469 | /* Const -- currently ignored */ | |
1470 | return 0; | |
817bc7b8 | 1471 | |
5f7b2142 ILT |
1472 | default: |
1473 | complain (&unknown_type_qual_complaint, tq); | |
1474 | return 0; | |
1475 | } | |
bd5635a1 RP |
1476 | } |
1477 | ||
1478 | ||
6c2e7392 PS |
1479 | /* Parse a procedure descriptor record PR. Note that the procedure is |
1480 | parsed _after_ the local symbols, now we just insert the extra | |
1481 | information we need into a MIPS_EFI_SYMBOL_NAME symbol that has | |
1482 | already been placed in the procedure's main block. Note also that | |
1483 | images that have been partially stripped (ld -x) have been deprived | |
1484 | of local symbols, and we have to cope with them here. FIRST_OFF is | |
1485 | the offset of the first procedure for this FDR; we adjust the | |
1486 | address by this amount, but I don't know why. */ | |
bd5635a1 | 1487 | |
d1bb1d41 | 1488 | static void |
6c2e7392 | 1489 | parse_procedure (pr, have_stabs, first_off) |
5f7b2142 | 1490 | PDR *pr; |
5f7b2142 | 1491 | int have_stabs; |
6c2e7392 | 1492 | unsigned long first_off; |
bd5635a1 | 1493 | { |
5f7b2142 | 1494 | struct symbol *s, *i; |
5f7b2142 ILT |
1495 | struct block *b; |
1496 | struct mips_extra_func_info *e; | |
1497 | char *sh_name; | |
1498 | ||
6c2e7392 PS |
1499 | /* Simple rule to find files linked "-x" */ |
1500 | if (cur_fdr->rss == -1) | |
5f7b2142 | 1501 | { |
6c2e7392 PS |
1502 | if (pr->isym == -1) |
1503 | { | |
1504 | /* Static procedure at address pr->adr. Sigh. */ | |
1505 | complain (&pdr_static_symbol_complaint, pr->adr); | |
1506 | return; | |
1507 | } | |
1508 | else | |
1509 | { | |
1510 | /* external */ | |
1511 | EXTR she; | |
1512 | ||
1513 | ecoff_swap_ext_in (cur_bfd, | |
1514 | ecoff_data (cur_bfd)->external_ext + pr->isym, | |
1515 | &she); | |
1516 | sh_name = ecoff_data (cur_bfd)->ssext + she.asym.iss; | |
1517 | } | |
5f7b2142 | 1518 | } |
6c2e7392 PS |
1519 | else |
1520 | { | |
1521 | /* Full symbols */ | |
1522 | SYMR sh; | |
1523 | ||
1524 | ecoff_swap_sym_in (cur_bfd, | |
1525 | (ecoff_data (cur_bfd)->external_sym | |
1526 | + cur_fdr->isymBase | |
1527 | + pr->isym), | |
1528 | &sh); | |
1529 | sh_name = ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh.iss; | |
1530 | } | |
1531 | ||
5f7b2142 | 1532 | if (have_stabs) |
6c2e7392 PS |
1533 | { |
1534 | /* We have to save the cur_fdr across the call to lookup_symbol. | |
1535 | If the pdr is for a static function and if a global function with | |
1536 | the same name exists, lookup_symbol will eventually read in the symtab | |
1537 | for the global function and clobber cur_fdr. */ | |
1538 | FDR *save_cur_fdr = cur_fdr; | |
1539 | s = lookup_symbol (sh_name, NULL, VAR_NAMESPACE, 0, NULL); | |
1540 | cur_fdr = save_cur_fdr; | |
1541 | } | |
5f7b2142 ILT |
1542 | else |
1543 | s = mylookup_symbol (sh_name, top_stack->cur_block, | |
1544 | VAR_NAMESPACE, LOC_BLOCK); | |
1545 | ||
1546 | if (s != 0) | |
1547 | { | |
1548 | b = SYMBOL_BLOCK_VALUE (s); | |
817bc7b8 | 1549 | } |
5f7b2142 ILT |
1550 | else |
1551 | { | |
1552 | complain (&pdr_for_nonsymbol_complaint, sh_name); | |
b303297a | 1553 | #if 1 |
5f7b2142 | 1554 | return; |
dac4929a | 1555 | #else |
817bc7b8 | 1556 | /* FIXME -- delete. We can't do symbol allocation now; it's all done. */ |
5f7b2142 ILT |
1557 | s = new_symbol (sh_name); |
1558 | SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; | |
1559 | SYMBOL_CLASS (s) = LOC_BLOCK; | |
1560 | /* Donno its type, hope int is ok */ | |
1561 | SYMBOL_TYPE (s) = lookup_function_type (builtin_type_int); | |
1562 | add_symbol (s, top_stack->cur_block); | |
1563 | /* Wont have symbols for this one */ | |
1564 | b = new_block (2); | |
1565 | SYMBOL_BLOCK_VALUE (s) = b; | |
1566 | BLOCK_FUNCTION (b) = s; | |
1567 | BLOCK_START (b) = pr->adr; | |
6c2e7392 PS |
1568 | /* BOUND used to be the end of procedure's text, but the |
1569 | argument is no longer passed in. */ | |
5f7b2142 ILT |
1570 | BLOCK_END (b) = bound; |
1571 | BLOCK_SUPERBLOCK (b) = top_stack->cur_block; | |
1572 | add_block (b, top_stack->cur_st); | |
817bc7b8 JG |
1573 | #endif |
1574 | } | |
d1bb1d41 | 1575 | |
5f7b2142 | 1576 | i = mylookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, LOC_CONST); |
d1bb1d41 | 1577 | |
5f7b2142 ILT |
1578 | if (i) |
1579 | { | |
1580 | e = (struct mips_extra_func_info *) SYMBOL_VALUE (i); | |
1581 | e->pdr = *pr; | |
1582 | e->pdr.isym = (long) s; | |
6c2e7392 | 1583 | e->pdr.adr += cur_fdr->adr - first_off; |
5f7b2142 | 1584 | } |
bd5635a1 RP |
1585 | } |
1586 | ||
1587 | /* Parse the external symbol ES. Just call parse_symbol() after | |
1588 | making sure we know where the aux are for it. For procedures, | |
1589 | parsing of the PDRs has already provided all the needed | |
1590 | information, we only parse them if SKIP_PROCEDURES is false, | |
101f259c | 1591 | and only if this causes no symbol duplication. |
d747e0af | 1592 | BIGEND says whether aux entries are big-endian or little-endian. |
101f259c JG |
1593 | |
1594 | This routine clobbers top_stack->cur_block and ->cur_st. */ | |
bd5635a1 | 1595 | |
4ad1963e | 1596 | static void |
5f7b2142 ILT |
1597 | parse_external (es, skip_procedures, bigend) |
1598 | EXTR *es; | |
1599 | int skip_procedures; | |
1600 | int bigend; | |
bd5635a1 | 1601 | { |
5f7b2142 | 1602 | union aux_ext *ax; |
bd5635a1 | 1603 | |
5f7b2142 ILT |
1604 | if (es->ifd != ifdNil) |
1605 | { | |
1606 | cur_fd = es->ifd; | |
6c2e7392 PS |
1607 | cur_fdr = ecoff_data (cur_bfd)->fdr + cur_fd; |
1608 | ax = ecoff_data (cur_bfd)->external_aux + cur_fdr->iauxBase; | |
5f7b2142 ILT |
1609 | } |
1610 | else | |
1611 | { | |
6c2e7392 | 1612 | cur_fdr = ecoff_data (cur_bfd)->fdr; |
5f7b2142 ILT |
1613 | ax = 0; |
1614 | } | |
bd5635a1 | 1615 | |
5f7b2142 ILT |
1616 | /* Reading .o files */ |
1617 | if (es->asym.sc == scUndefined || es->asym.sc == scNil) | |
1618 | { | |
1619 | char *what; | |
1620 | switch (es->asym.st) | |
1621 | { | |
1622 | case stStaticProc: | |
bd5635a1 | 1623 | case stProc: |
5f7b2142 ILT |
1624 | what = "procedure"; |
1625 | n_undef_procs++; | |
1626 | break; | |
bd5635a1 | 1627 | case stGlobal: |
5f7b2142 ILT |
1628 | what = "variable"; |
1629 | n_undef_vars++; | |
1630 | break; | |
bd5635a1 | 1631 | case stLabel: |
5f7b2142 ILT |
1632 | what = "label"; |
1633 | n_undef_labels++; | |
1634 | break; | |
1635 | default: | |
1636 | what = "symbol"; | |
1637 | break; | |
1638 | } | |
1639 | n_undef_symbols++; | |
1640 | /* FIXME: Turn this into a complaint? */ | |
1641 | if (info_verbose) | |
1642 | printf_filtered ("Warning: %s `%s' is undefined (in %s)\n", | |
6c2e7392 PS |
1643 | what, |
1644 | ecoff_data (cur_bfd)->ssext + es->asym.iss, | |
1645 | fdr_name (cur_fdr)); | |
5f7b2142 ILT |
1646 | return; |
1647 | } | |
1648 | ||
1649 | switch (es->asym.st) | |
1650 | { | |
1651 | case stProc: | |
1652 | /* If we have full symbols we do not need more */ | |
1653 | if (skip_procedures) | |
1654 | return; | |
6c2e7392 PS |
1655 | if (mylookup_symbol (ecoff_data (cur_bfd)->ssext + es->asym.iss, |
1656 | top_stack->cur_block, | |
5f7b2142 ILT |
1657 | VAR_NAMESPACE, LOC_BLOCK)) |
1658 | break; | |
1659 | /* fall through */ | |
1660 | case stGlobal: | |
1661 | case stLabel: | |
6c2e7392 PS |
1662 | /* Note that the case of a symbol with indexNil must be handled |
1663 | anyways by parse_symbol(). */ | |
1664 | parse_symbol (&es->asym, ax, (struct sym_ext *) NULL, bigend); | |
1665 | /* Note that parse_symbol changed es->asym. */ | |
5f7b2142 ILT |
1666 | break; |
1667 | default: | |
1668 | break; | |
1669 | } | |
bd5635a1 RP |
1670 | } |
1671 | ||
1672 | /* Parse the line number info for file descriptor FH into | |
1673 | GDB's linetable LT. MIPS' encoding requires a little bit | |
1674 | of magic to get things out. Note also that MIPS' line | |
1675 | numbers can go back and forth, apparently we can live | |
1676 | with that and do not need to reorder our linetables */ | |
1677 | ||
4ad1963e | 1678 | static void |
6c2e7392 | 1679 | parse_lines (fh, pr, lt) |
5f7b2142 | 1680 | FDR *fh; |
6c2e7392 | 1681 | PDR *pr; |
5f7b2142 | 1682 | struct linetable *lt; |
bd5635a1 | 1683 | { |
6c2e7392 | 1684 | unsigned char *base; |
5f7b2142 ILT |
1685 | int j, k; |
1686 | int delta, count, lineno = 0; | |
6c2e7392 | 1687 | unsigned long first_off = pr->adr; |
5f7b2142 | 1688 | |
6c2e7392 | 1689 | if (fh->cbLineOffset == 0) |
5f7b2142 ILT |
1690 | return; |
1691 | ||
6c2e7392 PS |
1692 | base = ecoff_data (cur_bfd)->line + fh->cbLineOffset; |
1693 | ||
5f7b2142 | 1694 | /* Scan by procedure descriptors */ |
6c2e7392 PS |
1695 | k = 0; |
1696 | for (j = 0; j < fh->cpd; j++, pr++) | |
5f7b2142 ILT |
1697 | { |
1698 | int l, halt; | |
6c2e7392 | 1699 | unsigned long adr; |
5f7b2142 ILT |
1700 | |
1701 | /* No code for this one */ | |
1702 | if (pr->iline == ilineNil || | |
1703 | pr->lnLow == -1 || pr->lnHigh == -1) | |
1704 | continue; | |
6c2e7392 PS |
1705 | |
1706 | /* Aurgh! To know where to stop expanding we must look-ahead. */ | |
5f7b2142 ILT |
1707 | for (l = 1; l < (fh->cpd - j); l++) |
1708 | if (pr[l].iline != -1) | |
1709 | break; | |
1710 | if (l == (fh->cpd - j)) | |
1711 | halt = fh->cline; | |
1712 | else | |
1713 | halt = pr[l].iline; | |
6c2e7392 PS |
1714 | |
1715 | /* When procedures are moved around the linenumbers are | |
1716 | attributed to the next procedure up. */ | |
5f7b2142 ILT |
1717 | if (pr->iline >= halt) |
1718 | continue; | |
1719 | ||
6c2e7392 PS |
1720 | base = ecoff_data (cur_bfd)->line + fh->cbLineOffset + pr->cbLineOffset; |
1721 | adr = fh->adr + pr->adr - first_off; | |
1722 | l = adr >> 2; /* in words */ | |
1723 | halt += (adr >> 2) - pr->iline; | |
5f7b2142 ILT |
1724 | for (lineno = pr->lnLow; l < halt;) |
1725 | { | |
1726 | count = *base & 0x0f; | |
1727 | delta = *base++ >> 4; | |
1728 | if (delta >= 8) | |
1729 | delta -= 16; | |
1730 | if (delta == -8) | |
1731 | { | |
1732 | delta = (base[0] << 8) | base[1]; | |
1733 | if (delta >= 0x8000) | |
1734 | delta -= 0x10000; | |
1735 | base += 2; | |
1736 | } | |
1737 | lineno += delta; /* first delta is 0 */ | |
1738 | k = add_line (lt, lineno, l, k); | |
1739 | l += count + 1; | |
bd5635a1 | 1740 | } |
5f7b2142 | 1741 | } |
bd5635a1 | 1742 | } |
101f259c JG |
1743 | \f |
1744 | /* Master parsing procedure for first-pass reading of file symbols | |
6c2e7392 | 1745 | into a partial_symtab. */ |
bd5635a1 | 1746 | |
d747e0af | 1747 | static void |
6c2e7392 | 1748 | parse_partial_symbols (objfile, section_offsets) |
d4ea2aba | 1749 | struct objfile *objfile; |
dac4929a | 1750 | struct section_offsets *section_offsets; |
bd5635a1 | 1751 | { |
5f7b2142 | 1752 | int f_idx, s_idx; |
6c2e7392 | 1753 | HDRR *hdr = &ecoff_data (cur_bfd)->symbolic_header; |
5f7b2142 ILT |
1754 | /* Running pointers */ |
1755 | FDR *fh; | |
6c2e7392 PS |
1756 | struct ext_ext *ext_out; |
1757 | struct ext_ext *ext_out_end; | |
1758 | EXTR *ext_block; | |
1759 | register EXTR *ext_in; | |
1760 | EXTR *ext_in_end; | |
1761 | SYMR sh; | |
5f7b2142 ILT |
1762 | struct partial_symtab *pst; |
1763 | ||
1764 | int past_first_source_file = 0; | |
1765 | ||
1766 | /* List of current psymtab's include files */ | |
1767 | char **psymtab_include_list; | |
1768 | int includes_allocated; | |
1769 | int includes_used; | |
6c2e7392 | 1770 | EXTR *extern_tab; |
5f7b2142 ILT |
1771 | struct pst_map *fdr_to_pst; |
1772 | /* Index within current psymtab dependency list */ | |
1773 | struct partial_symtab **dependency_list; | |
1774 | int dependencies_used, dependencies_allocated; | |
1775 | struct cleanup *old_chain; | |
1776 | char *name; | |
1777 | ||
6c2e7392 PS |
1778 | extern_tab = (EXTR *) obstack_alloc (&objfile->psymbol_obstack, |
1779 | sizeof (EXTR) * hdr->iextMax); | |
5f7b2142 ILT |
1780 | |
1781 | includes_allocated = 30; | |
1782 | includes_used = 0; | |
1783 | psymtab_include_list = (char **) alloca (includes_allocated * | |
1784 | sizeof (char *)); | |
1785 | next_symbol_text_func = mips_next_symbol_text; | |
1786 | ||
1787 | dependencies_allocated = 30; | |
1788 | dependencies_used = 0; | |
1789 | dependency_list = | |
1790 | (struct partial_symtab **) alloca (dependencies_allocated * | |
1791 | sizeof (struct partial_symtab *)); | |
1792 | ||
1793 | last_source_file = NULL; | |
1794 | ||
1795 | /* | |
6c2e7392 PS |
1796 | * Big plan: |
1797 | * | |
1798 | * Only parse the Local and External symbols, and the Relative FDR. | |
1799 | * Fixup enough of the loader symtab to be able to use it. | |
1800 | * Allocate space only for the file's portions we need to | |
1801 | * look at. (XXX) | |
1802 | */ | |
817bc7b8 | 1803 | |
5f7b2142 ILT |
1804 | max_gdbinfo = 0; |
1805 | max_glevel = MIN_GLEVEL; | |
1806 | ||
1807 | /* Allocate the map FDR -> PST. | |
1808 | Minor hack: -O3 images might claim some global data belongs | |
1809 | to FDR -1. We`ll go along with that */ | |
1810 | fdr_to_pst = (struct pst_map *) xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst); | |
1811 | old_chain = make_cleanup (free, fdr_to_pst); | |
1812 | fdr_to_pst++; | |
1813 | { | |
1814 | struct partial_symtab *pst = new_psymtab ("", objfile); | |
1815 | fdr_to_pst[-1].pst = pst; | |
1816 | FDR_IDX (pst) = -1; | |
1817 | } | |
1818 | ||
6c2e7392 PS |
1819 | /* Pass 0 over external syms: swap them in. */ |
1820 | ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR)); | |
1821 | make_cleanup (free, ext_block); | |
1822 | ||
1823 | ext_out = ecoff_data (cur_bfd)->external_ext; | |
1824 | ext_out_end = ext_out + hdr->iextMax; | |
1825 | ext_in = ext_block; | |
1826 | for (; ext_out < ext_out_end; ext_out++, ext_in++) | |
1827 | ecoff_swap_ext_in (cur_bfd, ext_out, ext_in); | |
1828 | ||
5f7b2142 | 1829 | /* Pass 1 over external syms: Presize and partition the list */ |
6c2e7392 PS |
1830 | ext_in = ext_block; |
1831 | ext_in_end = ext_in + hdr->iextMax; | |
1832 | for (; ext_in < ext_in_end; ext_in++) | |
1833 | fdr_to_pst[ext_in->ifd].n_globals++; | |
817bc7b8 | 1834 | |
5f7b2142 ILT |
1835 | /* Pass 1.5 over files: partition out global symbol space */ |
1836 | s_idx = 0; | |
1837 | for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) | |
1838 | { | |
1839 | fdr_to_pst[f_idx].globals_offset = s_idx; | |
1840 | s_idx += fdr_to_pst[f_idx].n_globals; | |
1841 | fdr_to_pst[f_idx].n_globals = 0; | |
d4ea2aba | 1842 | } |
bd5635a1 | 1843 | |
5f7b2142 | 1844 | /* Pass 2 over external syms: fill in external symbols */ |
6c2e7392 PS |
1845 | ext_in = ext_block; |
1846 | ext_in_end = ext_in + hdr->iextMax; | |
1847 | for (; ext_in < ext_in_end; ext_in++) | |
5f7b2142 ILT |
1848 | { |
1849 | enum minimal_symbol_type ms_type = mst_text; | |
bd5635a1 | 1850 | |
6c2e7392 PS |
1851 | extern_tab[fdr_to_pst[ext_in->ifd].globals_offset |
1852 | + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in; | |
d4ea2aba | 1853 | |
6c2e7392 | 1854 | if (ext_in->asym.sc == scUndefined || ext_in->asym.sc == scNil) |
5f7b2142 | 1855 | continue; |
101f259c | 1856 | |
6c2e7392 PS |
1857 | name = ecoff_data (cur_bfd)->ssext + ext_in->asym.iss; |
1858 | switch (ext_in->asym.st) | |
5f7b2142 | 1859 | { |
817bc7b8 | 1860 | case stProc: |
5f7b2142 | 1861 | break; |
817bc7b8 | 1862 | case stGlobal: |
5f7b2142 ILT |
1863 | ms_type = mst_data; |
1864 | break; | |
817bc7b8 | 1865 | case stLabel: |
5f7b2142 | 1866 | break; |
817bc7b8 | 1867 | default: |
5f7b2142 | 1868 | ms_type = mst_unknown; |
6c2e7392 | 1869 | complain (&unknown_ext_complaint, name); |
bd5635a1 | 1870 | } |
6c2e7392 | 1871 | prim_record_minimal_symbol (name, ext_in->asym.value, ms_type); |
817bc7b8 | 1872 | } |
bd5635a1 | 1873 | |
5f7b2142 ILT |
1874 | /* Pass 3 over files, over local syms: fill in static symbols */ |
1875 | for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) | |
1876 | { | |
1877 | struct partial_symtab *save_pst; | |
6c2e7392 | 1878 | EXTR *ext_ptr; |
dac4929a | 1879 | |
6c2e7392 | 1880 | cur_fdr = fh = ecoff_data (cur_bfd)->fdr + f_idx; |
c55e6167 | 1881 | |
5f7b2142 ILT |
1882 | if (fh->csym == 0) |
1883 | { | |
1884 | fdr_to_pst[f_idx].pst = NULL; | |
1885 | continue; | |
817bc7b8 | 1886 | } |
6c2e7392 PS |
1887 | pst = start_psymtab_common (objfile, section_offsets, |
1888 | fdr_name (fh), | |
5f7b2142 ILT |
1889 | fh->cpd ? fh->adr : 0, |
1890 | objfile->global_psymbols.next, | |
1891 | objfile->static_psymbols.next); | |
1892 | pst->read_symtab_private = ((char *) | |
1893 | obstack_alloc (&objfile->psymbol_obstack, | |
1894 | sizeof (struct symloc))); | |
6c2e7392 | 1895 | memset ((PTR) pst->read_symtab_private, 0, sizeof (struct symloc)); |
5f7b2142 ILT |
1896 | |
1897 | save_pst = pst; | |
1898 | /* Make everything point to everything. */ | |
1899 | FDR_IDX (pst) = f_idx; | |
1900 | fdr_to_pst[f_idx].pst = pst; | |
6c2e7392 PS |
1901 | |
1902 | /* FIXME: This tampers with data from BFD. */ | |
5f7b2142 ILT |
1903 | fh->ioptBase = (int) pst; |
1904 | ||
6c2e7392 | 1905 | CUR_BFD (pst) = cur_bfd; |
5f7b2142 ILT |
1906 | |
1907 | /* The way to turn this into a symtab is to call... */ | |
1908 | pst->read_symtab = mipscoff_psymtab_to_symtab; | |
1909 | ||
1910 | pst->texthigh = pst->textlow; | |
1911 | ||
1912 | /* For stabs-in-ecoff files, the second symbol must be @stab. | |
6c2e7392 PS |
1913 | This symbol is emitted by mips-tfile to signal that the |
1914 | current object file uses encapsulated stabs instead of mips | |
1915 | ecoff for local symbols. (It is the second symbol because | |
1916 | the first symbol is the stFile used to signal the start of a | |
1917 | file). */ | |
1918 | processing_gcc_compilation = 0; | |
1919 | if (fh->csym >= 2) | |
1920 | { | |
1921 | ecoff_swap_sym_in (cur_bfd, | |
1922 | (ecoff_data (cur_bfd)->external_sym | |
1923 | + fh->isymBase | |
1924 | + 1), | |
1925 | &sh); | |
1926 | if (STREQ (ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss, | |
1927 | stabs_symbol)) | |
1928 | processing_gcc_compilation = 2; | |
1929 | } | |
1930 | ||
1931 | if (processing_gcc_compilation != 0) | |
5f7b2142 | 1932 | { |
5f7b2142 ILT |
1933 | for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) |
1934 | { | |
1935 | int type_code; | |
1936 | char *namestring; | |
6c2e7392 PS |
1937 | |
1938 | ecoff_swap_sym_in (cur_bfd, | |
1939 | (ecoff_data (cur_bfd)->external_sym | |
1940 | + fh->isymBase | |
1941 | + cur_sdx), | |
1942 | &sh); | |
1943 | type_code = MIPS_UNMARK_STAB (sh.index); | |
1944 | if (!MIPS_IS_STAB (&sh)) | |
5f7b2142 | 1945 | { |
6c2e7392 | 1946 | if (sh.st == stProc || sh.st == stStaticProc) |
5f7b2142 | 1947 | { |
6c2e7392 PS |
1948 | long procaddr = sh.value; |
1949 | long isym; | |
1950 | ||
1951 | ||
1952 | isym = AUX_GET_ISYM (fh->fBigendian, | |
1953 | (ecoff_data (cur_bfd)->external_aux | |
1954 | + fh->iauxBase | |
1955 | + sh.index)); | |
1956 | ecoff_swap_sym_in (cur_bfd, | |
1957 | (ecoff_data (cur_bfd)->external_sym | |
1958 | + fh->isymBase | |
1959 | + isym | |
1960 | - 1), | |
1961 | &sh); | |
1962 | if (sh.st == stEnd) | |
5f7b2142 | 1963 | { |
6c2e7392 | 1964 | long high = procaddr + sh.value; |
5f7b2142 ILT |
1965 | if (high > pst->texthigh) |
1966 | pst->texthigh = high; | |
101f259c | 1967 | } |
7e258d18 | 1968 | } |
5f7b2142 | 1969 | continue; |
817bc7b8 | 1970 | } |
6c2e7392 PS |
1971 | #define SET_NAMESTRING() \ |
1972 | namestring = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss | |
7e258d18 | 1973 | #define CUR_SYMBOL_TYPE type_code |
6c2e7392 | 1974 | #define CUR_SYMBOL_VALUE sh.value |
dac4929a | 1975 | #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\ |
7e258d18 PB |
1976 | pst = save_pst |
1977 | #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0 | |
7e258d18 PB |
1978 | #define HANDLE_RBRAC(val) \ |
1979 | if ((val) > save_pst->texthigh) save_pst->texthigh = (val); | |
7e258d18 | 1980 | #include "partial-stab.h" |
7e258d18 | 1981 | } |
817bc7b8 | 1982 | } |
5f7b2142 ILT |
1983 | else |
1984 | { | |
5f7b2142 ILT |
1985 | for (cur_sdx = 0; cur_sdx < fh->csym;) |
1986 | { | |
1987 | char *name; | |
1988 | enum address_class class; | |
5f7b2142 | 1989 | |
6c2e7392 PS |
1990 | ecoff_swap_sym_in (cur_bfd, |
1991 | (ecoff_data (cur_bfd)->external_sym | |
1992 | + fh->isymBase | |
1993 | + cur_sdx), | |
1994 | &sh); | |
1995 | ||
1996 | if (MIPS_IS_STAB (&sh)) | |
5f7b2142 ILT |
1997 | { |
1998 | cur_sdx++; | |
1999 | continue; | |
817bc7b8 | 2000 | } |
101f259c | 2001 | |
6c2e7392 PS |
2002 | if (sh.sc == scUndefined || sh.sc == scNil || |
2003 | sh.index == 0xfffff) | |
5f7b2142 ILT |
2004 | { |
2005 | /* FIXME, premature? */ | |
2006 | cur_sdx++; | |
2007 | continue; | |
817bc7b8 | 2008 | } |
dac4929a | 2009 | |
6c2e7392 | 2010 | name = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss; |
817bc7b8 | 2011 | |
6c2e7392 | 2012 | switch (sh.st) |
5f7b2142 ILT |
2013 | { |
2014 | long high; | |
2015 | long procaddr; | |
2016 | int new_sdx; | |
2017 | ||
2018 | case stProc: /* Asm labels apparently */ | |
2019 | case stStaticProc: /* Function */ | |
2020 | ADD_PSYMBOL_TO_LIST (name, strlen (name), | |
2021 | VAR_NAMESPACE, LOC_BLOCK, | |
6c2e7392 | 2022 | objfile->static_psymbols, sh.value, |
5f7b2142 ILT |
2023 | psymtab_language, objfile); |
2024 | /* Skip over procedure to next one. */ | |
6c2e7392 | 2025 | if (sh.index >= hdr->iauxMax) |
5f7b2142 ILT |
2026 | { |
2027 | /* Should not happen, but does when cross-compiling | |
2028 | with the MIPS compiler. FIXME -- pull later. */ | |
2029 | complain (&index_complaint, name); | |
2030 | new_sdx = cur_sdx + 1; /* Don't skip at all */ | |
2031 | } | |
2032 | else | |
2033 | new_sdx = AUX_GET_ISYM (fh->fBigendian, | |
6c2e7392 PS |
2034 | (ecoff_data (cur_bfd)->external_aux |
2035 | + fh->iauxBase | |
2036 | + sh.index)); | |
2037 | procaddr = sh.value; | |
5f7b2142 ILT |
2038 | |
2039 | if (new_sdx <= cur_sdx) | |
2040 | { | |
2041 | /* This should not happen either... FIXME. */ | |
2042 | complain (&aux_index_complaint, name); | |
2043 | new_sdx = cur_sdx + 1; /* Don't skip backward */ | |
7e258d18 | 2044 | } |
817bc7b8 | 2045 | |
5f7b2142 | 2046 | cur_sdx = new_sdx; |
6c2e7392 PS |
2047 | ecoff_swap_sym_in (cur_bfd, |
2048 | (ecoff_data (cur_bfd)->external_sym | |
2049 | + fh->isymBase | |
2050 | + cur_sdx | |
2051 | - 1), | |
2052 | &sh); | |
2053 | if (sh.st != stEnd) | |
817bc7b8 | 2054 | continue; |
6c2e7392 | 2055 | high = procaddr + sh.value; |
5f7b2142 ILT |
2056 | if (high > pst->texthigh) |
2057 | pst->texthigh = high; | |
2058 | continue; | |
2059 | ||
2060 | case stStatic: /* Variable */ | |
2061 | class = LOC_STATIC; | |
2062 | break; | |
2063 | ||
2064 | case stTypedef:/* Typedef */ | |
2065 | class = LOC_TYPEDEF; | |
2066 | break; | |
2067 | ||
2068 | case stConstant: /* Constant decl */ | |
2069 | class = LOC_CONST; | |
2070 | break; | |
2071 | ||
2072 | case stUnion: | |
2073 | case stStruct: | |
2074 | case stEnum: | |
2075 | case stBlock: /* { }, str, un, enum*/ | |
6c2e7392 | 2076 | if (sh.sc == scInfo) |
5f7b2142 ILT |
2077 | { |
2078 | ADD_PSYMBOL_TO_LIST (name, strlen (name), | |
2079 | STRUCT_NAMESPACE, LOC_TYPEDEF, | |
2080 | objfile->static_psymbols, | |
6c2e7392 | 2081 | sh.value, |
5f7b2142 ILT |
2082 | psymtab_language, objfile); |
2083 | } | |
2084 | /* Skip over the block */ | |
6c2e7392 | 2085 | new_sdx = sh.index; |
5f7b2142 ILT |
2086 | if (new_sdx <= cur_sdx) |
2087 | { | |
2088 | /* This happens with the Ultrix kernel. */ | |
2089 | complain (&block_index_complaint, name); | |
2090 | new_sdx = cur_sdx + 1; /* Don't skip backward */ | |
2091 | } | |
2092 | cur_sdx = new_sdx; | |
2093 | continue; | |
2094 | ||
2095 | case stFile: /* File headers */ | |
2096 | case stLabel: /* Labels */ | |
2097 | case stEnd: /* Ends of files */ | |
2098 | goto skip; | |
2099 | ||
2100 | case stLocal: /* Local variables */ | |
2101 | /* Normally these are skipped because we skip over | |
2102 | all blocks we see. However, these can occur | |
2103 | as visible symbols in a .h file that contains code. */ | |
2104 | goto skip; | |
2105 | ||
2106 | default: | |
2107 | /* Both complaints are valid: one gives symbol name, | |
2108 | the other the offending symbol type. */ | |
6c2e7392 PS |
2109 | complain (&unknown_sym_complaint, name); |
2110 | complain (&unknown_st_complaint, sh.st); | |
5f7b2142 ILT |
2111 | cur_sdx++; |
2112 | continue; | |
101f259c | 2113 | } |
5f7b2142 ILT |
2114 | /* Use this gdb symbol */ |
2115 | ADD_PSYMBOL_TO_LIST (name, strlen (name), | |
2116 | VAR_NAMESPACE, class, | |
6c2e7392 | 2117 | objfile->static_psymbols, sh.value, |
5f7b2142 ILT |
2118 | psymtab_language, objfile); |
2119 | skip: | |
2120 | cur_sdx++; /* Go to next file symbol */ | |
817bc7b8 | 2121 | } |
d4ea2aba | 2122 | |
5f7b2142 ILT |
2123 | /* Now do enter the external symbols. */ |
2124 | ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset]; | |
2125 | cur_sdx = fdr_to_pst[f_idx].n_globals; | |
2126 | PST_PRIVATE (save_pst)->extern_count = cur_sdx; | |
2127 | PST_PRIVATE (save_pst)->extern_tab = ext_ptr; | |
2128 | for (; --cur_sdx >= 0; ext_ptr++) | |
2129 | { | |
2130 | register struct partial_symbol *psym; | |
2131 | enum address_class class; | |
6c2e7392 PS |
2132 | SYMR *psh; |
2133 | char *name; | |
5f7b2142 | 2134 | |
6c2e7392 | 2135 | if (ext_ptr->ifd != f_idx) |
5f7b2142 | 2136 | abort (); |
6c2e7392 PS |
2137 | psh = &ext_ptr->asym; |
2138 | switch (psh->st) | |
5f7b2142 ILT |
2139 | { |
2140 | case stProc: | |
2141 | class = LOC_BLOCK; | |
2142 | break; | |
2143 | case stLabel: | |
2144 | class = LOC_LABEL; | |
2145 | break; | |
2146 | default: | |
6c2e7392 PS |
2147 | complain (&unknown_ext_complaint, |
2148 | ecoff_data (cur_bfd)->ssext + psh->iss); | |
5f7b2142 ILT |
2149 | /* Fall through, pretend it's global. */ |
2150 | case stGlobal: | |
2151 | class = LOC_STATIC; | |
2152 | break; | |
d4ea2aba | 2153 | } |
6c2e7392 PS |
2154 | name = ecoff_data (cur_bfd)->ssext + psh->iss; |
2155 | ADD_PSYMBOL_ADDR_TO_LIST (name, strlen (name), | |
2156 | VAR_NAMESPACE, class, | |
2157 | objfile->global_psymbols, (CORE_ADDR) psh->value, | |
2158 | psymtab_language, objfile); | |
7e258d18 | 2159 | } |
bd5635a1 RP |
2160 | } |
2161 | ||
5f7b2142 ILT |
2162 | end_psymtab (save_pst, psymtab_include_list, includes_used, |
2163 | -1, save_pst->texthigh, | |
2164 | dependency_list, dependencies_used); | |
2165 | if (objfile->ei.entry_point >= save_pst->textlow && | |
2166 | objfile->ei.entry_point < save_pst->texthigh) | |
2167 | { | |
2168 | objfile->ei.entry_file_lowpc = save_pst->textlow; | |
2169 | objfile->ei.entry_file_highpc = save_pst->texthigh; | |
2170 | } | |
817bc7b8 JG |
2171 | } |
2172 | ||
5f7b2142 ILT |
2173 | /* Now scan the FDRs for dependencies */ |
2174 | for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) | |
2175 | { | |
2176 | int s_id0 = 0; | |
6c2e7392 | 2177 | fh = f_idx + ecoff_data (cur_bfd)->fdr; |
5f7b2142 ILT |
2178 | pst = fdr_to_pst[f_idx].pst; |
2179 | ||
2180 | /* This should catch stabs-in-ecoff. */ | |
2181 | if (fh->crfd <= 1) | |
2182 | continue; | |
2183 | ||
2184 | if (fh->cpd == 0) | |
6c2e7392 | 2185 | { /* If there are no functions defined here ... */ |
5f7b2142 ILT |
2186 | /* ...then presumably a .h file: drop reverse depends .h->.c */ |
2187 | for (; s_id0 < fh->crfd; s_id0++) | |
2188 | { | |
6c2e7392 PS |
2189 | RFDT rh; |
2190 | ||
2191 | ecoff_swap_rfd_in (cur_bfd, | |
2192 | (ecoff_data (cur_bfd)->external_rfd | |
2193 | + fh->rfdBase | |
2194 | + s_id0), | |
2195 | &rh); | |
2196 | if (rh == f_idx) | |
5f7b2142 ILT |
2197 | { |
2198 | s_id0++; /* Skip self-dependency */ | |
2199 | break; | |
021959e2 | 2200 | } |
5f7b2142 | 2201 | } |
021959e2 | 2202 | } |
5f7b2142 ILT |
2203 | pst->number_of_dependencies = fh->crfd - s_id0; |
2204 | pst->dependencies = | |
2205 | ((struct partial_symtab **) | |
2206 | obstack_alloc (&objfile->psymbol_obstack, | |
2207 | (pst->number_of_dependencies | |
2208 | * sizeof (struct partial_symtab *)))); | |
2209 | for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) | |
2210 | { | |
6c2e7392 PS |
2211 | RFDT rh; |
2212 | ||
2213 | ecoff_swap_rfd_in (cur_bfd, | |
2214 | (ecoff_data (cur_bfd)->external_rfd | |
2215 | + fh->rfdBase | |
2216 | + s_idx), | |
2217 | &rh); | |
2218 | if (rh < 0 || rh >= hdr->ifdMax) | |
2219 | complain (&bad_file_number_complaint, rh); | |
5f7b2142 | 2220 | else |
6c2e7392 | 2221 | pst->dependencies[s_idx - s_id0] = fdr_to_pst[rh].pst; |
021959e2 JG |
2222 | } |
2223 | } | |
5f7b2142 | 2224 | do_cleanups (old_chain); |
bd5635a1 RP |
2225 | } |
2226 | ||
2227 | ||
d4ea2aba | 2228 | #if 0 |
bd5635a1 RP |
2229 | /* Do the initial analisys of the F_IDX-th file descriptor. |
2230 | Allocates a partial symtab for it, and builds the list | |
2231 | of dependent files by recursion. LEV says at which level | |
2232 | of recursion we are called (to pretty up debug traces) */ | |
2233 | ||
2234 | static struct partial_symtab * | |
5f7b2142 ILT |
2235 | parse_fdr (f_idx, lev, objfile) |
2236 | int f_idx; | |
2237 | int lev; | |
2238 | struct objfile *objfile; | |
bd5635a1 | 2239 | { |
5f7b2142 ILT |
2240 | register FDR *fh; |
2241 | register struct partial_symtab *pst; | |
2242 | int s_idx, s_id0; | |
bd5635a1 | 2243 | |
6c2e7392 | 2244 | fh = ecoff_data (cur_bfd)->fdr + f_idx; |
5f7b2142 ILT |
2245 | |
2246 | /* Use this to indicate into which symtab this file was parsed */ | |
2247 | if (fh->ioptBase) | |
2248 | return (struct partial_symtab *) fh->ioptBase; | |
2249 | ||
2250 | /* Debuggability level */ | |
2251 | if (compare_glevel (max_glevel, fh->glevel) < 0) | |
2252 | max_glevel = fh->glevel; | |
2253 | ||
2254 | /* Make a new partial_symtab */ | |
6c2e7392 | 2255 | pst = new_psymtab (fdr_name (fh), objfile); |
5f7b2142 ILT |
2256 | if (fh->cpd == 0) |
2257 | { | |
2258 | pst->textlow = 0; | |
2259 | pst->texthigh = 0; | |
2260 | } | |
2261 | else | |
2262 | { | |
2263 | pst->textlow = fh->adr; | |
2264 | pst->texthigh = fh->cpd; /* To be fixed later */ | |
2265 | } | |
2266 | ||
2267 | /* Make everything point to everything. */ | |
2268 | FDR_IDX (pst) = f_idx; | |
2269 | fdr_to_pst[f_idx].pst = pst; | |
2270 | fh->ioptBase = (int) pst; | |
2271 | ||
2272 | /* Analyze its dependencies */ | |
2273 | if (fh->crfd <= 1) | |
2274 | return pst; | |
2275 | ||
2276 | s_id0 = 0; | |
2277 | if (fh->cpd == 0) | |
6c2e7392 | 2278 | { /* If there are no functions defined here ... */ |
5f7b2142 ILT |
2279 | /* ...then presumably a .h file: drop reverse depends .h->.c */ |
2280 | for (; s_id0 < fh->crfd; s_id0++) | |
2281 | { | |
6c2e7392 PS |
2282 | RFDT rh; |
2283 | ||
2284 | ecoff_swap_rfd_in (cur_bfd, | |
2285 | (ecoff_data (cur_bfd)->external_rfd | |
2286 | + fh->rfdBase | |
2287 | + s_id0), | |
2288 | &rh); | |
2289 | if (rh == f_idx) | |
5f7b2142 ILT |
2290 | { |
2291 | s_id0++; /* Skip self-dependency */ | |
2292 | break; | |
2293 | } | |
bd5635a1 | 2294 | } |
5f7b2142 ILT |
2295 | } |
2296 | pst->number_of_dependencies = fh->crfd - s_id0; | |
2297 | pst->dependencies = ((struct partial_symtab **) | |
2298 | obstack_alloc (&objfile->psymbol_obstack, | |
2299 | (pst->number_of_dependencies | |
2300 | * sizeof (struct partial_symtab *)))); | |
2301 | for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) | |
2302 | { | |
6c2e7392 PS |
2303 | RFDT rh; |
2304 | ||
2305 | ecoff_swap_rfd_in (cur_bfd, | |
2306 | (ecoff_data (cur_bfd)->external_rfd | |
2307 | + fh->rfdBase | |
2308 | + s_idx), | |
2309 | &rh); | |
2310 | pst->dependencies[s_idx - s_id0] = parse_fdr (rh, lev + 1, objfile); | |
5f7b2142 | 2311 | } |
bd5635a1 | 2312 | |
5f7b2142 | 2313 | return pst; |
bd5635a1 | 2314 | } |
5f7b2142 | 2315 | |
d4ea2aba | 2316 | #endif |
bd5635a1 | 2317 | |
5f7b2142 | 2318 | static char * |
c55e6167 | 2319 | mips_next_symbol_text () |
7e258d18 | 2320 | { |
6c2e7392 PS |
2321 | SYMR sh; |
2322 | ||
5f7b2142 | 2323 | cur_sdx++; |
6c2e7392 PS |
2324 | ecoff_swap_sym_in (cur_bfd, |
2325 | (ecoff_data (cur_bfd)->external_sym | |
2326 | + cur_fdr->isymBase | |
2327 | + cur_sdx), | |
2328 | &sh); | |
2329 | return ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh.iss; | |
7e258d18 | 2330 | } |
bd5635a1 RP |
2331 | |
2332 | /* Ancillary function to psymtab_to_symtab(). Does all the work | |
2333 | for turning the partial symtab PST into a symtab, recurring | |
3eaebb75 SG |
2334 | first on all dependent psymtabs. The argument FILENAME is |
2335 | only passed so we can see in debug stack traces what file | |
817bc7b8 JG |
2336 | is being read. |
2337 | ||
2338 | This function has a split personality, based on whether the | |
2339 | symbol table contains ordinary ecoff symbols, or stabs-in-ecoff. | |
2340 | The flow of control and even the memory allocation differs. FIXME. */ | |
bd5635a1 | 2341 | |
e072c738 | 2342 | static void |
5f7b2142 | 2343 | psymtab_to_symtab_1 (pst, filename) |
7e258d18 PB |
2344 | struct partial_symtab *pst; |
2345 | char *filename; | |
bd5635a1 | 2346 | { |
5f7b2142 ILT |
2347 | int i; |
2348 | struct symtab *st; | |
2349 | FDR *fh; | |
2350 | struct linetable *lines; | |
7e258d18 | 2351 | |
5f7b2142 ILT |
2352 | if (pst->readin) |
2353 | return; | |
2354 | pst->readin = 1; | |
7e258d18 | 2355 | |
5f7b2142 ILT |
2356 | /* Read in all partial symbtabs on which this one is dependent. |
2357 | NOTE that we do have circular dependencies, sigh. We solved | |
2358 | that by setting pst->readin before this point. */ | |
817bc7b8 | 2359 | |
5f7b2142 ILT |
2360 | for (i = 0; i < pst->number_of_dependencies; i++) |
2361 | if (!pst->dependencies[i]->readin) | |
2362 | { | |
2363 | /* Inform about additional files to be read in. */ | |
2364 | if (info_verbose) | |
2365 | { | |
2366 | fputs_filtered (" ", stdout); | |
2367 | wrap_here (""); | |
2368 | fputs_filtered ("and ", stdout); | |
2369 | wrap_here (""); | |
2370 | printf_filtered ("%s...", | |
2371 | pst->dependencies[i]->filename); | |
2372 | wrap_here (""); /* Flush output */ | |
2373 | fflush (stdout); | |
2374 | } | |
2375 | /* We only pass the filename for debug purposes */ | |
2376 | psymtab_to_symtab_1 (pst->dependencies[i], | |
2377 | pst->dependencies[i]->filename); | |
2378 | } | |
817bc7b8 | 2379 | |
5f7b2142 | 2380 | /* Now read the symbols for this symtab */ |
817bc7b8 | 2381 | |
5f7b2142 ILT |
2382 | current_objfile = pst->objfile; |
2383 | cur_fd = FDR_IDX (pst); | |
6c2e7392 | 2384 | fh = (cur_fd == -1) ? (FDR *) NULL : ecoff_data (cur_bfd)->fdr + cur_fd; |
5f7b2142 | 2385 | cur_fdr = fh; |
817bc7b8 | 2386 | |
5f7b2142 | 2387 | /* See comment in parse_partial_symbols about the @stabs sentinel. */ |
6c2e7392 PS |
2388 | processing_gcc_compilation = 0; |
2389 | if (fh != (FDR *) NULL && fh->csym >= 2) | |
5f7b2142 | 2390 | { |
6c2e7392 PS |
2391 | SYMR sh; |
2392 | ||
2393 | ecoff_swap_sym_in (cur_bfd, | |
2394 | (ecoff_data (cur_bfd)->external_sym | |
2395 | + fh->isymBase | |
2396 | + 1), | |
2397 | &sh); | |
2398 | if (STREQ (ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss, | |
2399 | stabs_symbol)) | |
2400 | { | |
2401 | /* We indicate that this is a GCC compilation so that certain | |
2402 | features will be enabled in stabsread/dbxread. */ | |
2403 | processing_gcc_compilation = 2; | |
2404 | } | |
2405 | } | |
817bc7b8 | 2406 | |
6c2e7392 PS |
2407 | if (processing_gcc_compilation != 0) |
2408 | { | |
2409 | struct pdr_ext *pdr_ptr; | |
2410 | struct pdr_ext *pdr_end; | |
2411 | int first_pdr; | |
2412 | unsigned long first_off; | |
817bc7b8 | 2413 | |
6c2e7392 | 2414 | /* This symbol table contains stabs-in-ecoff entries. */ |
dac4929a | 2415 | |
5f7b2142 | 2416 | /* Parse local symbols first */ |
817bc7b8 | 2417 | |
5f7b2142 ILT |
2418 | if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr */ |
2419 | { | |
2420 | current_objfile = NULL; | |
2421 | return; | |
2422 | } | |
2423 | for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) | |
2424 | { | |
6c2e7392 PS |
2425 | SYMR sh; |
2426 | char *name; | |
2427 | CORE_ADDR valu; | |
2428 | ||
2429 | ecoff_swap_sym_in (cur_bfd, | |
2430 | (ecoff_data (cur_bfd)->external_sym | |
2431 | + fh->isymBase | |
2432 | + cur_sdx), | |
2433 | &sh); | |
2434 | name = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss; | |
2435 | valu = sh.value; | |
2436 | if (MIPS_IS_STAB (&sh)) | |
5f7b2142 | 2437 | { |
6c2e7392 | 2438 | int type_code = MIPS_UNMARK_STAB (sh.index); |
5f7b2142 ILT |
2439 | process_one_symbol (type_code, 0, valu, name, |
2440 | pst->section_offsets, pst->objfile); | |
2441 | if (type_code == N_FUN) | |
2442 | { | |
2443 | /* Make up special symbol to contain | |
2444 | procedure specific info */ | |
2445 | struct mips_extra_func_info *e = | |
6c2e7392 PS |
2446 | ((struct mips_extra_func_info *) |
2447 | obstack_alloc (¤t_objfile->symbol_obstack, | |
2448 | sizeof (struct mips_extra_func_info))); | |
5f7b2142 ILT |
2449 | struct symbol *s = new_symbol (MIPS_EFI_SYMBOL_NAME); |
2450 | SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE; | |
2451 | SYMBOL_CLASS (s) = LOC_CONST; | |
2452 | SYMBOL_TYPE (s) = builtin_type_void; | |
2453 | SYMBOL_VALUE (s) = (int) e; | |
2454 | add_symbol_to_list (s, &local_symbols); | |
817bc7b8 JG |
2455 | } |
2456 | } | |
6c2e7392 | 2457 | else if (sh.st == stLabel && sh.index != indexNil) |
5f7b2142 ILT |
2458 | { |
2459 | /* Handle encoded stab line number. */ | |
6c2e7392 | 2460 | record_line (current_subfile, sh.index, valu); |
817bc7b8 | 2461 | } |
5f7b2142 | 2462 | else |
6c2e7392 | 2463 | complain (&stab_unknown_complaint, name); |
817bc7b8 | 2464 | } |
5f7b2142 ILT |
2465 | st = end_symtab (pst->texthigh, 0, 0, pst->objfile); |
2466 | end_stabs (); | |
817bc7b8 | 2467 | |
5f7b2142 ILT |
2468 | /* Sort the symbol table now, we are done adding symbols to it. |
2469 | We must do this before parse_procedure calls lookup_symbol. */ | |
2470 | sort_symtab_syms (st); | |
817bc7b8 | 2471 | |
5f7b2142 ILT |
2472 | /* This may not be necessary for stabs symtabs. FIXME. */ |
2473 | sort_blocks (st); | |
817bc7b8 | 2474 | |
6c2e7392 PS |
2475 | /* Fill in procedure info next. */ |
2476 | first_pdr = 1; | |
2477 | pdr_ptr = ecoff_data (cur_bfd)->external_pdr + fh->ipdFirst; | |
2478 | pdr_end = pdr_ptr + fh->cpd; | |
2479 | for (; pdr_ptr < pdr_end; pdr_ptr++) | |
5f7b2142 | 2480 | { |
6c2e7392 PS |
2481 | PDR pr; |
2482 | ||
2483 | ecoff_swap_pdr_in (cur_bfd, pdr_ptr, &pr); | |
2484 | if (first_pdr) | |
2485 | { | |
2486 | first_off = pr.adr; | |
2487 | first_pdr = 0; | |
2488 | } | |
2489 | parse_procedure (&pr, 1, first_off); | |
817bc7b8 | 2490 | } |
5f7b2142 ILT |
2491 | } |
2492 | else | |
2493 | { | |
6c2e7392 | 2494 | /* This symbol table contains ordinary ecoff entries. */ |
817bc7b8 | 2495 | |
5f7b2142 | 2496 | /* FIXME: doesn't use pst->section_offsets. */ |
dac4929a | 2497 | |
5f7b2142 ILT |
2498 | int f_max; |
2499 | int maxlines; | |
6c2e7392 | 2500 | EXTR *ext_ptr; |
85f0a848 | 2501 | |
5f7b2142 ILT |
2502 | /* How many symbols will we need */ |
2503 | /* FIXME, this does not count enum values. */ | |
2504 | f_max = pst->n_global_syms + pst->n_static_syms; | |
2505 | if (fh == 0) | |
2506 | { | |
2507 | maxlines = 0; | |
2508 | st = new_symtab ("unknown", f_max, 0, pst->objfile); | |
2509 | } | |
2510 | else | |
2511 | { | |
2512 | f_max += fh->csym + fh->cpd; | |
2513 | maxlines = 2 * fh->cline; | |
2514 | st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile); | |
817bc7b8 JG |
2515 | } |
2516 | ||
5f7b2142 | 2517 | lines = LINETABLE (st); |
6c2e7392 | 2518 | pending_list = PST_PRIVATE (pst)->pending_list; |
5f7b2142 ILT |
2519 | if (pending_list == 0) |
2520 | { | |
6c2e7392 PS |
2521 | pending_list = ((struct mips_pending **) |
2522 | xzalloc (ecoff_data (cur_bfd)->symbolic_header.ifdMax | |
2523 | * sizeof (struct mips_pending *))); | |
2524 | PST_PRIVATE (pst)->pending_list = pending_list; | |
817bc7b8 JG |
2525 | } |
2526 | ||
5f7b2142 ILT |
2527 | /* Get a new lexical context */ |
2528 | ||
2529 | push_parse_stack (); | |
2530 | top_stack->cur_st = st; | |
2531 | top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st), | |
2532 | STATIC_BLOCK); | |
2533 | BLOCK_START (top_stack->cur_block) = fh ? fh->adr : 0; | |
2534 | BLOCK_END (top_stack->cur_block) = 0; | |
2535 | top_stack->blocktype = stFile; | |
2536 | top_stack->maxsyms = 2 * f_max; | |
2537 | top_stack->cur_type = 0; | |
2538 | top_stack->procadr = 0; | |
2539 | top_stack->numargs = 0; | |
2540 | ||
2541 | if (fh) | |
2542 | { | |
6c2e7392 PS |
2543 | struct sym_ext *sym_ptr; |
2544 | struct sym_ext *sym_end; | |
5f7b2142 ILT |
2545 | |
2546 | /* Parse local symbols first */ | |
6c2e7392 PS |
2547 | sym_ptr = ecoff_data (cur_bfd)->external_sym + fh->isymBase; |
2548 | sym_end = sym_ptr + fh->csym; | |
2549 | while (sym_ptr < sym_end) | |
5f7b2142 | 2550 | { |
6c2e7392 PS |
2551 | SYMR sh; |
2552 | int c; | |
2553 | ||
2554 | ecoff_swap_sym_in (cur_bfd, sym_ptr, &sh); | |
2555 | c = parse_symbol (&sh, | |
2556 | (ecoff_data (cur_bfd)->external_aux | |
2557 | + fh->iauxBase), | |
2558 | sym_ptr, fh->fBigendian); | |
2559 | /* FIXME: We must swap the modified symbol back out, | |
2560 | although we would rather not. See parse_symbol. */ | |
2561 | ecoff_swap_sym_out (cur_bfd, &sh, sym_ptr); | |
2562 | sym_ptr += c; | |
7e258d18 | 2563 | } |
bd5635a1 | 2564 | |
6c2e7392 PS |
2565 | /* Linenumbers. At the end, check if we can save memory. |
2566 | parse_lines has to look ahead an arbitrary number of PDR | |
2567 | structures, so we swap them all first. */ | |
2568 | if (fh->cpd > 0) | |
5f7b2142 | 2569 | { |
6c2e7392 PS |
2570 | PDR *pr_block; |
2571 | struct cleanup *old_chain; | |
2572 | struct pdr_ext *pdr_ptr; | |
2573 | struct pdr_ext *pdr_end; | |
2574 | PDR *pdr_in; | |
2575 | PDR *pdr_in_end; | |
2576 | ||
2577 | pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR)); | |
2578 | ||
2579 | old_chain = make_cleanup (free, pr_block); | |
2580 | ||
2581 | pdr_ptr = ecoff_data (cur_bfd)->external_pdr + fh->ipdFirst; | |
2582 | pdr_end = pdr_ptr + fh->cpd; | |
2583 | pdr_in = pr_block; | |
2584 | for (; pdr_ptr < pdr_end; pdr_ptr++, pdr_in++) | |
2585 | ecoff_swap_pdr_in (cur_bfd, pdr_ptr, pdr_in); | |
2586 | ||
2587 | parse_lines (fh, pr_block, lines); | |
2588 | if (lines->nitems < fh->cline) | |
2589 | lines = shrink_linetable (lines); | |
2590 | ||
2591 | /* Fill in procedure info next. */ | |
2592 | pdr_in = pr_block; | |
2593 | pdr_in_end = pdr_in + fh->cpd; | |
2594 | for (; pdr_in < pdr_in_end; pdr_in++) | |
2595 | parse_procedure (pdr_in, 0, pr_block->adr); | |
2596 | ||
2597 | do_cleanups (old_chain); | |
817bc7b8 | 2598 | } |
ad142b8e | 2599 | } |
817bc7b8 | 2600 | |
5f7b2142 ILT |
2601 | LINETABLE (st) = lines; |
2602 | ||
2603 | /* .. and our share of externals. | |
2604 | XXX use the global list to speed up things here. how? | |
2605 | FIXME, Maybe quit once we have found the right number of ext's? */ | |
2606 | top_stack->cur_st = st; | |
2607 | top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st), | |
2608 | GLOBAL_BLOCK); | |
2609 | top_stack->blocktype = stFile; | |
6c2e7392 PS |
2610 | top_stack->maxsyms = (ecoff_data (cur_bfd)->symbolic_header.isymMax |
2611 | + ecoff_data (cur_bfd)->symbolic_header.ipdMax | |
2612 | + ecoff_data (cur_bfd)->symbolic_header.iextMax); | |
5f7b2142 ILT |
2613 | |
2614 | ext_ptr = PST_PRIVATE (pst)->extern_tab; | |
2615 | for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++) | |
6c2e7392 | 2616 | parse_external (ext_ptr, 1, fh->fBigendian); |
5f7b2142 ILT |
2617 | |
2618 | /* If there are undefined, tell the user */ | |
2619 | if (n_undef_symbols) | |
2620 | { | |
2621 | printf_filtered ("File %s contains %d unresolved references:", | |
2622 | st->filename, n_undef_symbols); | |
2623 | printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n", | |
2624 | n_undef_vars, n_undef_procs, n_undef_labels); | |
2625 | n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0; | |
bd5635a1 | 2626 | |
7e258d18 | 2627 | } |
5f7b2142 | 2628 | pop_parse_stack (); |
817bc7b8 | 2629 | |
5f7b2142 ILT |
2630 | /* Sort the symbol table now, we are done adding symbols to it.*/ |
2631 | sort_symtab_syms (st); | |
817bc7b8 | 2632 | |
5f7b2142 | 2633 | sort_blocks (st); |
7e258d18 | 2634 | } |
7e258d18 | 2635 | |
5f7b2142 ILT |
2636 | /* Now link the psymtab and the symtab. */ |
2637 | pst->symtab = st; | |
021959e2 | 2638 | |
5f7b2142 | 2639 | current_objfile = NULL; |
101f259c | 2640 | } |
bd5635a1 RP |
2641 | \f |
2642 | /* Ancillary parsing procedures. */ | |
2643 | ||
2644 | /* Lookup the type at relative index RN. Return it in TPP | |
2645 | if found and in any event come up with its name PNAME. | |
d747e0af MT |
2646 | BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian). |
2647 | Return value says how many aux symbols we ate. */ | |
bd5635a1 | 2648 | |
d747e0af | 2649 | static int |
5f7b2142 | 2650 | cross_ref (ax, tpp, type_code, pname, bigend) |
d747e0af | 2651 | union aux_ext *ax; |
7e258d18 | 2652 | struct type **tpp; |
5f7b2142 | 2653 | enum type_code type_code; /* Use to alloc new type if none is found. */ |
7e258d18 | 2654 | char **pname; |
d747e0af | 2655 | int bigend; |
bd5635a1 | 2656 | { |
5f7b2142 ILT |
2657 | RNDXR rn[1]; |
2658 | unsigned rf; | |
2659 | int result = 1; | |
bd5635a1 | 2660 | |
6c2e7392 | 2661 | ecoff_swap_rndx_in (bigend, &ax->a_rndx, rn); |
5f7b2142 ILT |
2662 | |
2663 | /* Escape index means 'the next one' */ | |
2664 | if (rn->rfd == 0xfff) | |
2665 | { | |
2666 | result++; | |
2667 | rf = AUX_GET_ISYM (bigend, ax + 1); | |
2668 | } | |
2669 | else | |
2670 | { | |
2671 | rf = rn->rfd; | |
2672 | } | |
2673 | ||
2674 | if (rf == -1) | |
2675 | { | |
2676 | /* Ooops */ | |
2677 | *pname = "<undefined>"; | |
2678 | } | |
2679 | else | |
2680 | { | |
2681 | /* | |
2682 | * Find the relative file descriptor and the symbol in it | |
2683 | */ | |
2684 | FDR *fh = get_rfd (cur_fd, rf); | |
6c2e7392 PS |
2685 | struct sym_ext *esh; |
2686 | SYMR sh; | |
5f7b2142 ILT |
2687 | struct type *t; |
2688 | ||
6c2e7392 PS |
2689 | /* If we have processed this symbol then we left a forwarding |
2690 | pointer to the corresponding GDB symbol. If not, we`ll put | |
2691 | it in a list of pending symbols, to be processed later when | |
2692 | the file will be. In any event, we collect the name for the | |
2693 | type here. Which is why we made a first pass at strings. */ | |
2694 | ||
2695 | esh = ecoff_data (cur_bfd)->external_sym + fh->isymBase + rn->index; | |
2696 | ecoff_swap_sym_in (cur_bfd, esh, &sh); | |
5f7b2142 ILT |
2697 | |
2698 | /* Careful, we might be looking at .o files */ | |
6c2e7392 PS |
2699 | if (sh.iss == 0) |
2700 | *pname = "<undefined>"; | |
2701 | else | |
2702 | *pname = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss; | |
5f7b2142 ILT |
2703 | |
2704 | /* Have we parsed it ? */ | |
6c2e7392 | 2705 | if (sh.value != 0 && sh.st == stParsed) |
5f7b2142 | 2706 | { |
6c2e7392 | 2707 | t = (struct type *) sh.value; |
5f7b2142 | 2708 | *tpp = t; |
bd5635a1 | 2709 | } |
5f7b2142 ILT |
2710 | else |
2711 | { | |
2712 | /* Avoid duplicates */ | |
6c2e7392 | 2713 | struct mips_pending *p = is_pending_symbol (fh, esh); |
5f7b2142 ILT |
2714 | if (p) |
2715 | *tpp = p->t; | |
2716 | else | |
2717 | { | |
2718 | *tpp = init_type (type_code, 0, 0, (char *) NULL, | |
2719 | (struct objfile *) NULL); | |
6c2e7392 | 2720 | add_pending (fh, esh, *tpp); |
5f7b2142 ILT |
2721 | } |
2722 | } | |
2723 | } | |
3eaebb75 | 2724 | |
5f7b2142 ILT |
2725 | /* We used one auxent normally, two if we got a "next one" rf. */ |
2726 | return result; | |
bd5635a1 RP |
2727 | } |
2728 | ||
2729 | ||
2730 | /* Quick&dirty lookup procedure, to avoid the MI ones that require | |
2731 | keeping the symtab sorted */ | |
2732 | ||
2733 | static struct symbol * | |
2734 | mylookup_symbol (name, block, namespace, class) | |
2735 | char *name; | |
2736 | register struct block *block; | |
2737 | enum namespace namespace; | |
2738 | enum address_class class; | |
2739 | { | |
5f7b2142 ILT |
2740 | register int bot, top, inc; |
2741 | register struct symbol *sym; | |
2742 | ||
2743 | bot = 0; | |
2744 | top = BLOCK_NSYMS (block); | |
2745 | inc = name[0]; | |
2746 | while (bot < top) | |
2747 | { | |
2748 | sym = BLOCK_SYM (block, bot); | |
2749 | if (SYMBOL_NAME (sym)[0] == inc | |
2750 | && SYMBOL_NAMESPACE (sym) == namespace | |
2751 | && SYMBOL_CLASS (sym) == class | |
2752 | && STREQ (SYMBOL_NAME (sym), name)) | |
2753 | return sym; | |
2754 | bot++; | |
2755 | } | |
2756 | block = BLOCK_SUPERBLOCK (block); | |
2757 | if (block) | |
2758 | return mylookup_symbol (name, block, namespace, class); | |
2759 | return 0; | |
bd5635a1 RP |
2760 | } |
2761 | ||
2762 | ||
3eaebb75 SG |
2763 | /* Add a new symbol S to a block B. |
2764 | Infrequently, we will need to reallocate the block to make it bigger. | |
2765 | We only detect this case when adding to top_stack->cur_block, since | |
2766 | that's the only time we know how big the block is. FIXME. */ | |
bd5635a1 | 2767 | |
3eaebb75 | 2768 | static void |
5f7b2142 ILT |
2769 | add_symbol (s, b) |
2770 | struct symbol *s; | |
2771 | struct block *b; | |
bd5635a1 | 2772 | { |
5f7b2142 ILT |
2773 | int nsyms = BLOCK_NSYMS (b)++; |
2774 | struct block *origb; | |
2775 | struct parse_stack *stackp; | |
2776 | ||
2777 | if (b == top_stack->cur_block && | |
2778 | nsyms >= top_stack->maxsyms) | |
2779 | { | |
2780 | complain (&block_overflow_complaint, SYMBOL_NAME (s)); | |
2781 | /* In this case shrink_block is actually grow_block, since | |
3eaebb75 | 2782 | BLOCK_NSYMS(b) is larger than its current size. */ |
5f7b2142 ILT |
2783 | origb = b; |
2784 | b = shrink_block (top_stack->cur_block, top_stack->cur_st); | |
2785 | ||
2786 | /* Now run through the stack replacing pointers to the | |
2787 | original block. shrink_block has already done this | |
2788 | for the blockvector and BLOCK_FUNCTION. */ | |
2789 | for (stackp = top_stack; stackp; stackp = stackp->next) | |
2790 | { | |
2791 | if (stackp->cur_block == origb) | |
2792 | { | |
2793 | stackp->cur_block = b; | |
2794 | stackp->maxsyms = BLOCK_NSYMS (b); | |
2795 | } | |
3eaebb75 | 2796 | } |
5f7b2142 ILT |
2797 | } |
2798 | BLOCK_SYM (b, nsyms) = s; | |
bd5635a1 RP |
2799 | } |
2800 | ||
2801 | /* Add a new block B to a symtab S */ | |
2802 | ||
3eaebb75 | 2803 | static void |
5f7b2142 ILT |
2804 | add_block (b, s) |
2805 | struct block *b; | |
2806 | struct symtab *s; | |
bd5635a1 | 2807 | { |
5f7b2142 | 2808 | struct blockvector *bv = BLOCKVECTOR (s); |
bd5635a1 | 2809 | |
5f7b2142 | 2810 | bv = (struct blockvector *) xrealloc ((PTR) bv, |
6c2e7392 PS |
2811 | (sizeof (struct blockvector) |
2812 | + BLOCKVECTOR_NBLOCKS (bv) | |
2813 | * sizeof (bv->block))); | |
5f7b2142 ILT |
2814 | if (bv != BLOCKVECTOR (s)) |
2815 | BLOCKVECTOR (s) = bv; | |
bd5635a1 | 2816 | |
5f7b2142 | 2817 | BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b; |
bd5635a1 RP |
2818 | } |
2819 | ||
2820 | /* Add a new linenumber entry (LINENO,ADR) to a linevector LT. | |
2821 | MIPS' linenumber encoding might need more than one byte | |
2822 | to describe it, LAST is used to detect these continuation lines */ | |
2823 | ||
3eaebb75 | 2824 | static int |
5f7b2142 ILT |
2825 | add_line (lt, lineno, adr, last) |
2826 | struct linetable *lt; | |
2827 | int lineno; | |
2828 | CORE_ADDR adr; | |
2829 | int last; | |
bd5635a1 | 2830 | { |
5f7b2142 ILT |
2831 | if (last == 0) |
2832 | last = -2; /* make sure we record first line */ | |
bd5635a1 | 2833 | |
5f7b2142 ILT |
2834 | if (last == lineno) /* skip continuation lines */ |
2835 | return lineno; | |
bd5635a1 | 2836 | |
5f7b2142 ILT |
2837 | lt->item[lt->nitems].line = lineno; |
2838 | lt->item[lt->nitems++].pc = adr << 2; | |
2839 | return lineno; | |
bd5635a1 | 2840 | } |
bd5635a1 | 2841 | \f |
84ffdec2 | 2842 | /* Sorting and reordering procedures */ |
bd5635a1 | 2843 | |
bd5635a1 RP |
2844 | /* Blocks with a smaller low bound should come first */ |
2845 | ||
84ffdec2 | 2846 | static int |
5f7b2142 | 2847 | compare_blocks (arg1, arg2) |
391ca579 | 2848 | const void *arg1, *arg2; |
bd5635a1 | 2849 | { |
5f7b2142 ILT |
2850 | register int addr_diff; |
2851 | struct block **b1 = (struct block **) arg1; | |
2852 | struct block **b2 = (struct block **) arg2; | |
2853 | ||
2854 | addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2))); | |
2855 | if (addr_diff == 0) | |
5f5341a7 | 2856 | return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1))); |
5f7b2142 | 2857 | return addr_diff; |
bd5635a1 RP |
2858 | } |
2859 | ||
bd5635a1 RP |
2860 | /* Sort the blocks of a symtab S. |
2861 | Reorder the blocks in the blockvector by code-address, | |
2862 | as required by some MI search routines */ | |
2863 | ||
e072c738 | 2864 | static void |
5f7b2142 ILT |
2865 | sort_blocks (s) |
2866 | struct symtab *s; | |
bd5635a1 | 2867 | { |
5f7b2142 | 2868 | struct blockvector *bv = BLOCKVECTOR (s); |
bd5635a1 | 2869 | |
5f7b2142 ILT |
2870 | if (BLOCKVECTOR_NBLOCKS (bv) <= 2) |
2871 | { | |
2872 | /* Cosmetic */ | |
2873 | if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0) | |
2874 | BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0; | |
2875 | if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0) | |
2876 | BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0; | |
2877 | return; | |
2878 | } | |
2879 | /* | |
2880 | * This is very unfortunate: normally all functions are compiled in | |
2881 | * the order they are found, but if the file is compiled -O3 things | |
2882 | * are very different. It would be nice to find a reliable test | |
2883 | * to detect -O3 images in advance. | |
2884 | */ | |
2885 | if (BLOCKVECTOR_NBLOCKS (bv) > 3) | |
2886 | qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK), | |
2887 | BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK, | |
2888 | sizeof (struct block *), | |
2889 | compare_blocks); | |
2890 | ||
2891 | { | |
2892 | register CORE_ADDR high = 0; | |
2893 | register int i, j = BLOCKVECTOR_NBLOCKS (bv); | |
2894 | ||
2895 | for (i = FIRST_LOCAL_BLOCK; i < j; i++) | |
2896 | if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i))) | |
2897 | high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)); | |
2898 | BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high; | |
2899 | } | |
2900 | ||
2901 | BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = | |
2902 | BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK)); | |
2903 | ||
2904 | BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = | |
2905 | BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); | |
2906 | BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = | |
2907 | BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); | |
bd5635a1 | 2908 | } |
bd5635a1 | 2909 | \f |
5f7b2142 | 2910 | |
bd5635a1 RP |
2911 | /* Constructor/restructor/destructor procedures */ |
2912 | ||
2913 | /* Allocate a new symtab for NAME. Needs an estimate of how many symbols | |
2914 | MAXSYMS and linenumbers MAXLINES we'll put in it */ | |
2915 | ||
4ad1963e | 2916 | static struct symtab * |
5f7b2142 ILT |
2917 | new_symtab (name, maxsyms, maxlines, objfile) |
2918 | char *name; | |
2919 | int maxsyms; | |
2920 | int maxlines; | |
2921 | struct objfile *objfile; | |
bd5635a1 | 2922 | { |
021959e2 | 2923 | struct symtab *s = allocate_symtab (name, objfile); |
bd5635a1 | 2924 | |
5f7b2142 | 2925 | LINETABLE (s) = new_linetable (maxlines); |
bd5635a1 | 2926 | |
021959e2 | 2927 | /* All symtabs must have at least two blocks */ |
5f7b2142 ILT |
2928 | BLOCKVECTOR (s) = new_bvect (2); |
2929 | BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = new_block (maxsyms); | |
2930 | BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = new_block (maxsyms); | |
2931 | BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) = | |
2932 | BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); | |
bd5635a1 | 2933 | |
021959e2 | 2934 | s->free_code = free_linetable; |
bd5635a1 | 2935 | |
021959e2 | 2936 | return (s); |
bd5635a1 RP |
2937 | } |
2938 | ||
bd5635a1 RP |
2939 | /* Allocate a new partial_symtab NAME */ |
2940 | ||
2941 | static struct partial_symtab * | |
5f7b2142 ILT |
2942 | new_psymtab (name, objfile) |
2943 | char *name; | |
2944 | struct objfile *objfile; | |
bd5635a1 | 2945 | { |
021959e2 | 2946 | struct partial_symtab *psymtab; |
817bc7b8 | 2947 | |
6c2e7392 | 2948 | psymtab = allocate_psymtab (name, objfile); |
817bc7b8 | 2949 | |
021959e2 | 2950 | /* Keep a backpointer to the file's symbols */ |
bd5635a1 | 2951 | |
5f7b2142 ILT |
2952 | psymtab->read_symtab_private = ((char *) |
2953 | obstack_alloc (&objfile->psymbol_obstack, | |
2954 | sizeof (struct symloc))); | |
6c2e7392 PS |
2955 | memset ((PTR) psymtab->read_symtab_private, 0, sizeof (struct symloc)); |
2956 | CUR_BFD (psymtab) = cur_bfd; | |
817bc7b8 | 2957 | |
021959e2 JG |
2958 | /* The way to turn this into a symtab is to call... */ |
2959 | psymtab->read_symtab = mipscoff_psymtab_to_symtab; | |
2960 | return (psymtab); | |
bd5635a1 RP |
2961 | } |
2962 | ||
2963 | ||
84ffdec2 | 2964 | /* Allocate a linetable array of the given SIZE. Since the struct |
817bc7b8 | 2965 | already includes one item, we subtract one when calculating the |
84ffdec2 | 2966 | proper size to allocate. */ |
bd5635a1 | 2967 | |
7e258d18 | 2968 | static struct linetable * |
5f7b2142 ILT |
2969 | new_linetable (size) |
2970 | int size; | |
bd5635a1 | 2971 | { |
5f7b2142 | 2972 | struct linetable *l; |
bd5635a1 | 2973 | |
5f7b2142 ILT |
2974 | size = (size - 1) * sizeof (l->item) + sizeof (struct linetable); |
2975 | l = (struct linetable *) xmalloc (size); | |
2976 | l->nitems = 0; | |
2977 | return l; | |
bd5635a1 RP |
2978 | } |
2979 | ||
2980 | /* Oops, too big. Shrink it. This was important with the 2.4 linetables, | |
84ffdec2 JG |
2981 | I am not so sure about the 3.4 ones. |
2982 | ||
2983 | Since the struct linetable already includes one item, we subtract one when | |
2984 | calculating the proper size to allocate. */ | |
bd5635a1 | 2985 | |
7e258d18 | 2986 | static struct linetable * |
5f7b2142 ILT |
2987 | shrink_linetable (lt) |
2988 | struct linetable *lt; | |
bd5635a1 | 2989 | { |
bd5635a1 | 2990 | |
5f7b2142 | 2991 | return (struct linetable *) xrealloc ((PTR) lt, |
6c2e7392 PS |
2992 | (sizeof (struct linetable) |
2993 | + ((lt->nitems - 1) | |
2994 | * sizeof (lt->item)))); | |
bd5635a1 RP |
2995 | } |
2996 | ||
2997 | /* Allocate and zero a new blockvector of NBLOCKS blocks. */ | |
2998 | ||
4ad1963e | 2999 | static struct blockvector * |
5f7b2142 ILT |
3000 | new_bvect (nblocks) |
3001 | int nblocks; | |
bd5635a1 | 3002 | { |
5f7b2142 ILT |
3003 | struct blockvector *bv; |
3004 | int size; | |
bd5635a1 | 3005 | |
5f7b2142 ILT |
3006 | size = sizeof (struct blockvector) + nblocks * sizeof (struct block *); |
3007 | bv = (struct blockvector *) xzalloc (size); | |
bd5635a1 | 3008 | |
5f7b2142 | 3009 | BLOCKVECTOR_NBLOCKS (bv) = nblocks; |
bd5635a1 | 3010 | |
5f7b2142 | 3011 | return bv; |
bd5635a1 RP |
3012 | } |
3013 | ||
3014 | /* Allocate and zero a new block of MAXSYMS symbols */ | |
3015 | ||
4ad1963e | 3016 | static struct block * |
5f7b2142 ILT |
3017 | new_block (maxsyms) |
3018 | int maxsyms; | |
bd5635a1 | 3019 | { |
5f7b2142 | 3020 | int size = sizeof (struct block) + (maxsyms - 1) * sizeof (struct symbol *); |
bd5635a1 | 3021 | |
5f7b2142 | 3022 | return (struct block *) xzalloc (size); |
bd5635a1 RP |
3023 | } |
3024 | ||
3eaebb75 SG |
3025 | /* Ooops, too big. Shrink block B in symtab S to its minimal size. |
3026 | Shrink_block can also be used by add_symbol to grow a block. */ | |
bd5635a1 RP |
3027 | |
3028 | static struct block * | |
5f7b2142 ILT |
3029 | shrink_block (b, s) |
3030 | struct block *b; | |
3031 | struct symtab *s; | |
bd5635a1 | 3032 | { |
5f7b2142 ILT |
3033 | struct block *new; |
3034 | struct blockvector *bv = BLOCKVECTOR (s); | |
3035 | int i; | |
bd5635a1 | 3036 | |
5f7b2142 | 3037 | /* Just reallocate it and fix references to the old one */ |
bd5635a1 | 3038 | |
6c2e7392 PS |
3039 | new = (struct block *) xrealloc ((PTR) b, |
3040 | (sizeof (struct block) | |
3041 | + ((BLOCK_NSYMS (b) - 1) | |
3042 | * sizeof (struct symbol *)))); | |
bd5635a1 | 3043 | |
5f7b2142 | 3044 | /* Should chase pointers to old one. Fortunately, that`s just |
bd5635a1 | 3045 | the block`s function and inferior blocks */ |
5f7b2142 ILT |
3046 | if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b) |
3047 | SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new; | |
3048 | for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++) | |
3049 | if (BLOCKVECTOR_BLOCK (bv, i) == b) | |
3050 | BLOCKVECTOR_BLOCK (bv, i) = new; | |
3051 | else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b) | |
3052 | BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = new; | |
3053 | return new; | |
bd5635a1 RP |
3054 | } |
3055 | ||
3056 | /* Create a new symbol with printname NAME */ | |
3057 | ||
4ad1963e | 3058 | static struct symbol * |
5f7b2142 ILT |
3059 | new_symbol (name) |
3060 | char *name; | |
bd5635a1 | 3061 | { |
6c2e7392 PS |
3062 | struct symbol *s = ((struct symbol *) |
3063 | obstack_alloc (¤t_objfile->symbol_obstack, | |
3064 | sizeof (struct symbol))); | |
bd5635a1 | 3065 | |
5f7b2142 ILT |
3066 | memset ((PTR) s, 0, sizeof (*s)); |
3067 | SYMBOL_NAME (s) = name; | |
3068 | return s; | |
bd5635a1 RP |
3069 | } |
3070 | ||
3071 | /* Create a new type with printname NAME */ | |
3072 | ||
4ad1963e | 3073 | static struct type * |
5f7b2142 ILT |
3074 | new_type (name) |
3075 | char *name; | |
bd5635a1 | 3076 | { |
5f7b2142 | 3077 | struct type *t; |
bd5635a1 | 3078 | |
5f7b2142 ILT |
3079 | t = alloc_type (current_objfile); |
3080 | TYPE_NAME (t) = name; | |
6c2e7392 | 3081 | TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default; |
5f7b2142 | 3082 | return t; |
bd5635a1 | 3083 | } |
bd5635a1 | 3084 | \f |
5f7b2142 | 3085 | |
bd5635a1 RP |
3086 | /* Things used for calling functions in the inferior. |
3087 | These functions are exported to our companion | |
7e258d18 | 3088 | mips-tdep.c file and are here because they play |
bd5635a1 RP |
3089 | with the symbol-table explicitly. */ |
3090 | ||
bd5635a1 RP |
3091 | /* Sigtramp: make sure we have all the necessary information |
3092 | about the signal trampoline code. Since the official code | |
3093 | from MIPS does not do so, we make up that information ourselves. | |
3094 | If they fix the library (unlikely) this code will neutralize itself. */ | |
3095 | ||
d747e0af | 3096 | static void |
5f7b2142 | 3097 | fixup_sigtramp () |
bd5635a1 | 3098 | { |
5f7b2142 ILT |
3099 | struct symbol *s; |
3100 | struct symtab *st; | |
3101 | struct block *b, *b0; | |
bd5635a1 | 3102 | |
5f7b2142 | 3103 | sigtramp_address = -1; |
bd5635a1 | 3104 | |
5f7b2142 ILT |
3105 | /* We know it is sold as sigvec */ |
3106 | s = lookup_symbol ("sigvec", 0, VAR_NAMESPACE, 0, NULL); | |
bd5635a1 | 3107 | |
5f7b2142 ILT |
3108 | /* Most programs do not play with signals */ |
3109 | if (s == 0) | |
3110 | s = lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE, 0, NULL); | |
3111 | else | |
3112 | { | |
3113 | b0 = SYMBOL_BLOCK_VALUE (s); | |
bd5635a1 | 3114 | |
5f7b2142 ILT |
3115 | /* A label of sigvec, to be more precise */ |
3116 | s = lookup_symbol ("sigtramp", b0, VAR_NAMESPACE, 0, NULL); | |
3117 | } | |
4ad1963e | 3118 | |
5f7b2142 ILT |
3119 | /* But maybe this program uses its own version of sigvec */ |
3120 | if (s == 0) | |
3121 | return; | |
bd5635a1 | 3122 | |
5f7b2142 ILT |
3123 | /* Did we or MIPSco fix the library ? */ |
3124 | if (SYMBOL_CLASS (s) == LOC_BLOCK) | |
3125 | { | |
3126 | sigtramp_address = BLOCK_START (SYMBOL_BLOCK_VALUE (s)); | |
3127 | sigtramp_end = BLOCK_END (SYMBOL_BLOCK_VALUE (s)); | |
3128 | return; | |
3129 | } | |
bd5635a1 | 3130 | |
5f7b2142 ILT |
3131 | sigtramp_address = SYMBOL_VALUE (s); |
3132 | sigtramp_end = sigtramp_address + 0x88; /* black magic */ | |
3133 | ||
3134 | /* But what symtab does it live in ? */ | |
3135 | st = find_pc_symtab (SYMBOL_VALUE (s)); | |
3136 | ||
3137 | /* | |
3138 | * Ok, there goes the fix: turn it into a procedure, with all the | |
3139 | * needed info. Note we make it a nested procedure of sigvec, | |
3140 | * which is the way the (assembly) code is actually written. | |
3141 | */ | |
3142 | SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; | |
3143 | SYMBOL_CLASS (s) = LOC_BLOCK; | |
3144 | SYMBOL_TYPE (s) = init_type (TYPE_CODE_FUNC, 4, 0, (char *) NULL, | |
3145 | (struct objfile *) NULL); | |
3146 | TYPE_TARGET_TYPE (SYMBOL_TYPE (s)) = builtin_type_void; | |
3147 | ||
3148 | /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */ | |
3149 | b = new_block (1); | |
3150 | SYMBOL_BLOCK_VALUE (s) = b; | |
3151 | BLOCK_START (b) = sigtramp_address; | |
3152 | BLOCK_END (b) = sigtramp_end; | |
3153 | BLOCK_FUNCTION (b) = s; | |
3154 | BLOCK_SUPERBLOCK (b) = BLOCK_SUPERBLOCK (b0); | |
3155 | add_block (b, st); | |
3156 | sort_blocks (st); | |
3157 | ||
3158 | /* Make a MIPS_EFI_SYMBOL_NAME entry for it */ | |
3159 | { | |
3160 | struct mips_extra_func_info *e = | |
3161 | ((struct mips_extra_func_info *) | |
3162 | xzalloc (sizeof (struct mips_extra_func_info))); | |
3163 | ||
3164 | e->numargs = 0; /* the kernel thinks otherwise */ | |
3165 | /* align_longword(sigcontext + SIGFRAME) */ | |
3166 | e->pdr.frameoffset = 0x150; | |
3167 | e->pdr.framereg = SP_REGNUM; | |
3168 | e->pdr.pcreg = 31; | |
3169 | e->pdr.regmask = -2; | |
3170 | e->pdr.regoffset = -(41 * sizeof (int)); | |
3171 | e->pdr.fregmask = -1; | |
3172 | e->pdr.fregoffset = -(37 * sizeof (int)); | |
3173 | e->pdr.isym = (long) s; | |
3174 | ||
3175 | current_objfile = st->objfile; /* Keep new_symbol happy */ | |
3176 | s = new_symbol (MIPS_EFI_SYMBOL_NAME); | |
3177 | SYMBOL_VALUE (s) = (int) e; | |
3178 | SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE; | |
3179 | SYMBOL_CLASS (s) = LOC_CONST; | |
3180 | SYMBOL_TYPE (s) = builtin_type_void; | |
3181 | current_objfile = NULL; | |
3182 | } | |
bd5635a1 | 3183 | |
5f7b2142 | 3184 | BLOCK_SYM (b, BLOCK_NSYMS (b)++) = s; |
bd5635a1 | 3185 | } |
dac4929a SG |
3186 | |
3187 | ||
3188 | /* Fake up identical offsets for all sections. */ | |
3189 | ||
3190 | struct section_offsets * | |
3191 | mipscoff_symfile_offsets (objfile, addr) | |
3192 | struct objfile *objfile; | |
3193 | CORE_ADDR addr; | |
3194 | { | |
3195 | struct section_offsets *section_offsets; | |
3196 | int i; | |
3197 | ||
5f7b2142 ILT |
3198 | section_offsets = ((struct section_offsets *) |
3199 | obstack_alloc (&objfile->psymbol_obstack, | |
3200 | (sizeof (struct section_offsets) | |
3201 | + (sizeof (section_offsets->offsets) | |
3202 | * (SECT_OFF_MAX - 1))))); | |
dac4929a SG |
3203 | |
3204 | for (i = 0; i < SECT_OFF_MAX; i++) | |
3205 | ANOFFSET (section_offsets, i) = addr; | |
3206 | ||
3207 | return section_offsets; | |
3208 | } | |
bd5635a1 RP |
3209 | \f |
3210 | /* Initialization */ | |
3211 | ||
80d68b1d FF |
3212 | static struct sym_fns ecoff_sym_fns = |
3213 | { | |
5f7b2142 ILT |
3214 | "ecoff", /* sym_name: name or name prefix of BFD target type */ |
3215 | 5, /* sym_namelen: number of significant sym_name chars */ | |
3216 | mipscoff_new_init, /* sym_new_init: init anything gbl to entire symtab */ | |
3217 | mipscoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */ | |
3218 | mipscoff_symfile_read, /* sym_read: read a symbol file into symtab */ | |
3219 | mipscoff_symfile_finish, /* sym_finish: finished with file, cleanup */ | |
3220 | mipscoff_symfile_offsets, /* sym_offsets: dummy FIXME til implem sym reloc */ | |
3221 | NULL /* next: pointer to next struct sym_fns */ | |
80d68b1d FF |
3222 | }; |
3223 | ||
bd5635a1 | 3224 | |
4ad1963e | 3225 | void |
bd5635a1 RP |
3226 | _initialize_mipsread () |
3227 | { | |
5f7b2142 ILT |
3228 | add_symtab_fns (&ecoff_sym_fns); |
3229 | ||
3230 | /* Missing basic types */ | |
3231 | ||
3232 | builtin_type_string = | |
3233 | init_type (TYPE_CODE_STRING, | |
3234 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3235 | 0, "string", | |
3236 | (struct objfile *) NULL); | |
3237 | builtin_type_complex = | |
3238 | init_type (TYPE_CODE_FLT, | |
3239 | TARGET_COMPLEX_BIT / TARGET_CHAR_BIT, | |
3240 | 0, "complex", | |
3241 | (struct objfile *) NULL); | |
3242 | builtin_type_double_complex = | |
3243 | init_type (TYPE_CODE_FLT, | |
3244 | TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT, | |
3245 | 0, "double complex", | |
3246 | (struct objfile *) NULL); | |
3247 | builtin_type_fixed_dec = | |
3248 | init_type (TYPE_CODE_INT, | |
3249 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
3250 | 0, "fixed decimal", | |
3251 | (struct objfile *) NULL); | |
3252 | builtin_type_float_dec = | |
3253 | init_type (TYPE_CODE_FLT, | |
3254 | TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
3255 | 0, "floating decimal", | |
3256 | (struct objfile *) NULL); | |
bd5635a1 | 3257 | } |