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