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