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