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