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