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