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