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