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