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