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