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.
6 This file is part of GDB.
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.
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.
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. */
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
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.
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.
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. */
50 #define TM_FILE_OVERRIDE
60 #include "stabsread.h"
61 #include "complaints.h"
64 #include <sys/types.h>
69 #include <sys/param.h>
74 #include "gdb-stabs.h"
76 #include "coff/mips.h" /* COFF-like aspects of ecoff files */
77 #include "coff/ecoff-ext.h" /* External forms of ecoff sym structures */
79 #include "libbfd.h" /* FIXME Secret internal BFD stuff (bfd_read) */
80 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
81 #include "aout/aout64.h"
82 #include "aout/stab_gnu.h" /* STABS information */
83 #include "expression.h"
84 #include "language.h" /* Needed inside partial-stab.h */
87 struct external_filehdr f;
88 struct external_aouthdr a;
91 /* These must match the corresponding definition in gcc/config/xm-mips.h.
92 At some point, these should probably go into a shared include file,
93 but currently gcc and gdb do not share any directories. */
95 #define CODE_MASK 0x8F300
96 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
97 #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
98 #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
99 #define STABS_SYMBOL "@stabs"
101 /* Each partial symbol table entry contains a pointer to private data for the
102 read_symtab() function to use when expanding a partial symbol table entry
103 to a full symbol table entry.
105 For mipsread this structure contains the index of the FDR that this psymtab
106 represents and a pointer to the symbol table header HDRR from the symbol
107 file that the psymtab was created from. */
109 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
110 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
111 #define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)
116 EXTR **extern_tab; /* Pointer to external symbols for this file. */
117 int extern_count; /* Size of extern_tab. */
120 /* Things we import explicitly from other modules */
122 extern int info_verbose;
124 /* Various complaints about symbol reading that don't abort the process */
126 struct complaint bad_file_number_complaint =
127 {"bad file number %d", 0, 0};
129 struct complaint index_complaint =
130 {"bad aux index at symbol %s", 0, 0};
132 struct complaint aux_index_complaint =
133 {"bad proc end in aux found from symbol %s", 0, 0};
135 struct complaint unknown_ext_complaint =
136 {"unknown external symbol %s", 0, 0};
138 struct complaint unknown_sym_complaint =
139 {"unknown local symbol %s", 0, 0};
141 struct complaint unknown_st_complaint =
142 {"with type %d", 0, 0};
144 struct complaint block_overflow_complaint =
145 {"block containing %s overfilled", 0, 0};
147 struct complaint basic_type_complaint =
148 {"cannot map MIPS basic type 0x%x", 0, 0};
150 struct complaint unknown_type_qual_complaint =
151 {"unknown type qualifier 0x%x", 0, 0};
153 struct complaint array_bitsize_complaint =
154 {"size of array target type not known, assuming %d bits", 0, 0};
156 struct complaint bad_tag_guess_complaint =
157 {"guessed tag type of %s incorrectly", 0, 0};
159 struct complaint block_member_complaint =
160 {"declaration block contains unhandled symbol type %d", 0, 0};
162 struct complaint stEnd_complaint =
163 {"stEnd with storage class %d not handled", 0, 0};
165 struct complaint unknown_mips_symtype_complaint =
166 {"unknown symbol type 0x%x", 0, 0};
168 struct complaint stab_unknown_complaint =
169 {"unknown stabs symbol %s", 0, 0};
171 struct complaint pdr_for_nonsymbol_complaint =
172 {"PDR for %s, but no symbol", 0, 0};
174 struct complaint pdr_static_symbol_complaint =
175 {"can't handle PDR for static proc at 0x%x", 0, 0};
177 /* Macros and extra defs */
179 /* Already-parsed symbols are marked specially */
181 #define stParsed stType
183 /* Puns: hard to find whether -g was used and how */
185 #define MIN_GLEVEL GLEVEL_0
186 #define compare_glevel(a,b) \
187 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
188 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
190 /* When looking at .o files, avoid tripping over zero pointers.
191 FIXME; places that use this should be fixed to convert from
192 external to internal format, rather than examining in-place. */
194 #define UNSAFE_DATA_ADDR(p) ((p) == 0)
196 /* Things that really are local to this module */
198 /* MIPS symtab header for the current file */
200 static HDRR *cur_hdr;
202 /* Pointer to current file decriptor record, and its index */
207 /* Index of current symbol */
211 /* Note how much "debuggable" this image is. We would like
212 to see at least one FDR with full symbols */
217 /* When examining .o files, report on undefined symbols */
219 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
221 /* Pseudo symbol to use when putting stabs into the symbol table. */
223 static char stabs_symbol[] = STABS_SYMBOL;
225 /* Extra builtin types */
227 struct type *builtin_type_complex;
228 struct type *builtin_type_double_complex;
229 struct type *builtin_type_fixed_dec;
230 struct type *builtin_type_float_dec;
231 struct type *builtin_type_string;
233 /* Forward declarations */
236 fixup_symtab PARAMS ((HDRR *, char *, file_ptr, bfd *));
239 read_mips_symtab PARAMS ((struct objfile *, struct section_offsets *));
242 read_the_mips_symtab PARAMS ((bfd *, CORE_ADDR *));
245 upgrade_type PARAMS ((struct type **, int, union aux_ext *, int));
248 parse_partial_symbols PARAMS ((int, struct objfile *,
249 struct section_offsets *));
252 cross_ref PARAMS ((union aux_ext *, struct type **, enum type_code, char **,
256 fixup_sigtramp PARAMS ((void));
258 static struct symbol *
259 new_symbol PARAMS ((char *));
262 new_type PARAMS ((char *));
264 static struct block *
265 new_block PARAMS ((int));
267 static struct symtab *
268 new_symtab PARAMS ((char *, int, int, struct objfile *));
270 static struct linetable *
271 new_linetable PARAMS ((int));
273 static struct blockvector *
274 new_bvect PARAMS ((int));
277 parse_type PARAMS ((union aux_ext *, int *, int));
279 static struct symbol *
280 mylookup_symbol PARAMS ((char *, struct block *, enum namespace,
281 enum address_class));
283 static struct block *
284 shrink_block PARAMS ((struct block *, struct symtab *));
287 xzalloc PARAMS ((unsigned int));
290 sort_blocks PARAMS ((struct symtab *));
293 compare_blocks PARAMS ((const void *, const void *));
295 static struct partial_symtab *
296 new_psymtab PARAMS ((char *, struct objfile *));
299 static struct partial_symtab *
300 parse_fdr PARAMS ((int, int, struct objfile *));
304 psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *));
307 add_block PARAMS ((struct block *, struct symtab *));
310 add_symbol PARAMS ((struct symbol *, struct block *));
313 add_line PARAMS ((struct linetable *, int, CORE_ADDR, int));
315 static struct linetable *
316 shrink_linetable PARAMS ((struct linetable *));
319 mips_next_symbol_text PARAMS ((void));
321 /* Things we export to other modules */
323 /* Address bounds for the signal trampoline in inferior, if any */
324 /* FIXME: Nothing really seems to use this. Why is it here? */
326 CORE_ADDR sigtramp_address, sigtramp_end;
329 mipscoff_new_init (ignore)
330 struct objfile *ignore;
335 mipscoff_symfile_init (objfile)
336 struct objfile *objfile;
338 if (objfile -> sym_private != NULL)
340 mfree (objfile -> md, objfile -> sym_private);
342 objfile -> sym_private = NULL;
346 mipscoff_symfile_read (objfile, section_offsets, mainline)
347 struct objfile *objfile;
348 struct section_offsets *section_offsets;
351 init_minimal_symbol_collection ();
352 make_cleanup (discard_minimal_symbols, 0);
354 /* Now that the executable file is positioned at symbol table,
355 process it and define symbols accordingly. */
357 read_mips_symtab(objfile, section_offsets);
359 /* Install any minimal symbols that have been collected as the current
360 minimal symbols for this objfile. */
362 install_minimal_symbols (objfile);
365 /* Perform any local cleanups required when we are done with a particular
366 objfile. I.E, we are in the process of discarding all symbol information
367 for an objfile, freeing up all memory held for it, and unlinking the
368 objfile struct from the global list of known objfiles. */
371 mipscoff_symfile_finish (objfile)
372 struct objfile *objfile;
374 if (objfile -> sym_private != NULL)
376 mfree (objfile -> md, objfile -> sym_private);
379 /* If we have a file symbol header lying around, blow it away. */
388 /* Allocate zeroed memory */
394 PTR p = xmalloc (size);
400 /* Exported procedure: Builds a symtab from the PST partial one.
401 Restores the environment in effect when PST was created, delegates
402 most of the work to an ancillary procedure, and sorts
403 and reorders the symtab list at the end */
406 mipscoff_psymtab_to_symtab(pst)
407 struct partial_symtab *pst;
414 printf_filtered("Reading in symbols for %s...", pst->filename);
417 /* Restore the header and list of pending typedefs */
418 cur_hdr = CUR_HDR(pst);
420 next_symbol_text_func = mips_next_symbol_text;
422 psymtab_to_symtab_1(pst, pst->filename);
424 /* Match with global symbols. This only needs to be done once,
425 after all of the symtabs and dependencies have been read in. */
426 scan_file_globals (pst->objfile);
429 printf_filtered("done.\n");
432 /* Exported procedure: Is PC in the signal trampoline code */
435 in_sigtramp(pc, ignore)
437 char *ignore; /* function name */
439 if (sigtramp_address == 0)
441 return (pc >= sigtramp_address && pc < sigtramp_end);
444 /* File-level interface functions */
446 /* Read the symtab information from file ABFD into memory. Also,
447 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
450 read_the_mips_symtab(abfd, end_of_text_segp)
452 CORE_ADDR *end_of_text_segp;
454 int stsize, st_hdrsize;
456 struct hdr_ext hdr_ext;
458 /* Header for executable/object file we read symbols from */
459 struct coff_exec filhdr;
462 /* We need some info from the initial headers */
463 val = bfd_seek(abfd, (file_ptr) 0, L_SET);
464 val = bfd_read((PTR)&filhdr, sizeof filhdr, 1, abfd);
466 if (end_of_text_segp)
468 bfd_h_get_32 (abfd, filhdr.a.text_start) +
469 bfd_h_get_32 (abfd, filhdr.a.tsize);
471 /* Find and read the symbol table header */
472 st_hdrsize = bfd_h_get_32 (abfd, filhdr.f.f_nsyms);
473 st_filptr = bfd_h_get_32 (abfd, filhdr.f.f_symptr);
477 bfd_seek (abfd, st_filptr, L_SET);
478 if (st_hdrsize != sizeof (hdr_ext)) { /* Profanity check */
479 error ("Wrong header size: %d, not %d", st_hdrsize,
482 if (bfd_read((PTR)&hdr_ext, st_hdrsize, 1, abfd) != st_hdrsize)
484 ecoff_swap_hdr_in (abfd, &hdr_ext, &st_hdr);
486 /* Find out how large the symbol table is */
487 stsize = (st_hdr.cbExtOffset - (st_filptr + st_hdrsize))
488 + st_hdr.iextMax * cbEXTR;
490 /* Allocate space for the symbol table. Read it in. */
491 cur_hdr = (HDRR *) xmalloc(stsize + st_hdrsize);
493 memcpy((PTR)cur_hdr, (PTR)&hdr_ext, st_hdrsize);
494 if (bfd_read((char *)cur_hdr + st_hdrsize, stsize, 1, abfd) != stsize)
497 /* Fixup file_pointers in it */
498 fixup_symtab(cur_hdr, (char *) cur_hdr + st_hdrsize,
499 st_filptr + st_hdrsize, abfd);
503 error("Short read on %s", bfd_get_filename (abfd));
507 /* Turn all file-relative pointers in the symtab described by HDR
508 into memory pointers, given that the symtab itself is located
509 at DATA in memory and F_PTR in the file.
511 Byte-swap all the data structures, in place, while we are at it --
512 except AUX entries, which we leave in their original byte order.
513 They will be swapped as they are used instead. (FIXME: we ought to
514 do all the data structures that way.) */
517 fixup_symtab (hdr, data, f_ptr, abfd)
528 struct rfd_ext *rbase;
530 /* This function depends on the external and internal forms
531 of the MIPS symbol table taking identical space. Check this
532 assumption at compile-time.
533 DO NOT DELETE THESE ENTRIES, OR COMMENT THEM OUT, JUST BECAUSE SOME
534 "LINT" OR COMPILER THINKS THEY ARE UNUSED! Thank you. */
535 static check_hdr1[1 + sizeof (struct hdr_ext) - sizeof (HDRR)] = {0};
536 static check_hdr2[1 + sizeof (HDRR) - sizeof (struct hdr_ext)] = {0};
537 static check_fdr1[1 + sizeof (struct fdr_ext) - sizeof (FDR)] = {0};
538 static check_fdr2[1 + sizeof (FDR) - sizeof (struct fdr_ext)] = {0};
539 static check_pdr1[1 + sizeof (struct pdr_ext) - sizeof (PDR)] = {0};
540 static check_pdr2[1 + sizeof (PDR) - sizeof (struct pdr_ext)] = {0};
541 static check_sym1[1 + sizeof (struct sym_ext) - sizeof (SYMR)] = {0};
542 static check_sym2[1 + sizeof (SYMR) - sizeof (struct sym_ext)] = {0};
543 static check_ext1[1 + sizeof (struct ext_ext) - sizeof (EXTR)] = {0};
544 static check_ext2[1 + sizeof (EXTR) - sizeof (struct ext_ext)] = {0};
545 static check_rfd1[1 + sizeof (struct rfd_ext) - sizeof (RFDT)] = {0};
546 static check_rfd2[1 + sizeof (RFDT) - sizeof (struct rfd_ext)] = {0};
548 /* Swap in the header record. */
549 ecoff_swap_hdr_in (abfd, hdr, hdr);
552 * These fields are useless (and empty) by now:
553 * hdr->cbDnOffset, hdr->cbOptOffset
554 * We use them for other internal purposes.
557 hdr->cbOptOffset = 0;
560 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
574 /* Fix all the RFD's. */
575 rbase = (struct rfd_ext *)(hdr->cbRfdOffset);
576 for (i = 0; i < hdr->crfd; i++) {
577 ecoff_swap_rfd_in (abfd, rbase+i, (pRFDT) rbase+i);
580 /* Fix all string pointers inside the symtab, and
581 the FDR records. Also fix other miscellany. */
583 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
584 register unsigned code_offset;
586 /* Header itself, and strings */
587 fh = (FDR *) (hdr->cbFdOffset) + f_idx;
589 /* Swap in the FDR */
590 ecoff_swap_fdr_in (abfd, fh, fh);
592 fh->issBase += hdr->cbSsOffset;
594 fh->rss = (long)fh->rss + fh->issBase;
597 fh->isymBase = (int)((SYMR*)(hdr->cbSymOffset)+fh->isymBase);
599 /* FIXME! Probably don't want to do this here! */
600 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
601 sh = (SYMR*)fh->isymBase + s_idx;
602 ecoff_swap_sym_in (abfd, sh, sh);
604 sh->iss = (long) sh->iss + fh->issBase;
610 /* cannot fix fh->ipdFirst because it is a short */
611 #define IPDFIRST(h,fh) \
612 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
614 /* Optional symbols (actually used for partial_symtabs) */
620 fh->iauxBase = hdr->cbAuxOffset + fh->iauxBase * sizeof(union aux_ext);
621 /* Relative file descriptor table */
622 fh->rfdBase = hdr->cbRfdOffset + fh->rfdBase * sizeof(RFDT);
626 fh->cbLineOffset += hdr->cbLineOffset;
628 /* Procedure symbols. (XXX This should be done later) */
629 code_offset = fh->adr;
630 for (s_idx = 0; s_idx < fh->cpd; s_idx++) {
631 unsigned name, only_ext;
633 pr = (PDR*)(IPDFIRST(hdr,fh)) + s_idx;
634 ecoff_swap_pdr_in (abfd, pr, pr);
636 /* Simple rule to find files linked "-x" */
637 only_ext = fh->rss == -1;
639 if (pr->isym == -1) {
640 /* static function */
644 name = hdr->cbExtOffset + pr->isym * sizeof(EXTR);
645 sh = &((EXTR*)name)->asym;
649 sh = (SYMR*)fh->isymBase + pr->isym;
650 /* Included code ? */
651 if (s_idx == 0 && pr->adr != 0)
652 code_offset -= pr->adr;
655 /* Turn index into a pointer */
658 /* Fix line numbers */
659 pr->cbLineOffset += fh->cbLineOffset;
661 /* Relocate address */
663 pr->adr += code_offset;
667 /* External symbols: swap in, and fix string */
668 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
669 esh = (EXTR*)(hdr->cbExtOffset) + s_idx;
670 ecoff_swap_ext_in (abfd, esh, esh);
671 esh->asym.iss = esh->asym.iss + hdr->cbSsExtOffset;
676 /* Find a file descriptor given its index RF relative to a file CF */
684 f = (FDR *) (cur_hdr->cbFdOffset) + cf;
685 /* Object files do not have the RFD table, all refs are absolute */
687 return (FDR *) (cur_hdr->cbFdOffset) + rf;
688 cf = *((pRFDT) f->rfdBase + rf);
689 return (FDR *) (cur_hdr->cbFdOffset) + cf;
692 /* Return a safer print NAME for a file descriptor */
698 if (name == (char *) -1)
699 return "<stripped file>";
700 if (UNSAFE_DATA_ADDR(name))
706 /* Read in and parse the symtab of the file OBJFILE. Symbols from
707 different sections are relocated via the SECTION_OFFSETS. */
710 read_mips_symtab (objfile, section_offsets)
711 struct objfile *objfile;
712 struct section_offsets *section_offsets;
714 CORE_ADDR end_of_text_seg;
716 read_the_mips_symtab(objfile->obfd, &end_of_text_seg);
718 parse_partial_symbols(end_of_text_seg, objfile, section_offsets);
722 * Check to make sure file was compiled with -g.
723 * If not, warn the user of this limitation.
725 if (compare_glevel(max_glevel, GLEVEL_2) < 0) {
726 if (max_gdbinfo == 0)
728 "\n%s not compiled with -g, debugging support is limited.\n",
731 "You should compile with -g2 or -g3 for best debugging support.\n");
737 /* Local utilities */
739 /* Map of FDR indexes to partial symtabs */
742 struct partial_symtab *pst; /* the psymtab proper */
743 int n_globals; /* exported globals (external symbols) */
744 int globals_offset; /* cumulative */
748 /* Utility stack, used to nest procedures and blocks properly.
749 It is a doubly linked list, to avoid too many alloc/free.
750 Since we might need it quite a few times it is NOT deallocated
753 static struct parse_stack {
754 struct parse_stack *next, *prev;
755 struct symtab *cur_st; /* Current symtab. */
756 struct block *cur_block; /* Block in it. */
757 int blocktype; /* What are we parsing. */
758 int maxsyms; /* Max symbols in this block. */
759 struct type *cur_type; /* Type we parse fields for. */
760 int cur_field; /* Field number in cur_type. */
761 int procadr; /* Start addres of this procedure */
762 int numargs; /* Its argument count */
763 } *top_stack; /* Top stack ptr */
766 /* Enter a new lexical context */
771 struct parse_stack *new;
773 /* Reuse frames if possible */
774 if (top_stack && top_stack->prev)
775 new = top_stack->prev;
777 new = (struct parse_stack *) xzalloc(sizeof(struct parse_stack));
778 /* Initialize new frame with previous content */
780 register struct parse_stack *prev = new->prev;
783 top_stack->prev = new;
785 new->next = top_stack;
790 /* Exit a lexical context */
798 top_stack = top_stack->next;
802 /* Cross-references might be to things we haven't looked at
803 yet, e.g. type references. To avoid too many type
804 duplications we keep a quick fixup table, an array
805 of lists of references indexed by file descriptor */
807 static struct mips_pending {
808 struct mips_pending *next; /* link */
809 SYMR *s; /* the symbol */
810 struct type *t; /* its partial type descriptor */
814 /* Check whether we already saw symbol SH in file FH as undefined */
816 static struct mips_pending *
817 is_pending_symbol(fh, sh)
821 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
822 register struct mips_pending *p;
824 /* Linear search is ok, list is typically no more than 10 deep */
825 for (p = pending_list[f_idx]; p; p = p->next)
831 /* Add a new undef symbol SH of type T */
834 add_pending(fh, sh, t)
839 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
840 struct mips_pending *p = is_pending_symbol(fh, sh);
842 /* Make sure we do not make duplicates */
844 p = (struct mips_pending *) xmalloc(sizeof(*p));
847 p->next = pending_list[f_idx];
848 pending_list[f_idx] = p;
850 sh->reserved = 1; /* for quick check */
853 /* Throw away undef entries when done with file index F_IDX */
854 /* FIXME -- storage leak. This is never called!!! --gnu */
862 register struct mips_pending *p, *q;
864 for (p = pending_list[f_idx]; p; p = q) {
868 pending_list[f_idx] = 0;
874 prepend_tag_kind(tag_name, type_code)
876 enum type_code type_code;
884 case TYPE_CODE_STRUCT:
887 case TYPE_CODE_UNION:
894 result = (char*)obstack_alloc (¤t_objfile->symbol_obstack,
895 strlen(prefix) + strlen(tag_name) + 1);
896 sprintf(result, "%s%s", prefix, tag_name);
901 /* Parsing Routines proper. */
903 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
904 For blocks, procedures and types we open a new lexical context.
905 This is basically just a big switch on the symbol's type.
906 Argument AX is the base pointer of aux symbols for this file (fh->iauxBase).
907 BIGEND says whether aux symbols are big-endian or little-endian.
908 Return count of SYMR's handled (normally one). */
911 parse_symbol(sh, ax, bigend)
922 /* When a symbol is cross-referenced from other files/symbols
923 we mark it explicitly */
924 int pend = (sh->reserved == 1);
925 enum address_class class;
933 case stGlobal: /* external symbol, goes into global block */
935 b = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
937 s = new_symbol((char *)sh->iss);
938 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
941 case stStatic: /* static data, goes into current block. */
943 b = top_stack->cur_block;
944 s = new_symbol((char *)sh->iss);
945 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
948 case stLocal: /* local variable, goes into current block */
949 if (sh->sc == scRegister) {
950 class = LOC_REGISTER;
952 sh->value += FP0_REGNUM-32;
955 b = top_stack->cur_block;
956 s = new_symbol((char *)sh->iss);
957 SYMBOL_VALUE(s) = sh->value;
959 data: /* Common code for symbols describing data */
960 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
961 SYMBOL_CLASS(s) = class;
964 /* Type could be missing in a number of cases */
965 if (sh->sc == scUndefined || sh->sc == scNil ||
966 sh->index == 0xfffff)
967 SYMBOL_TYPE(s) = builtin_type_int; /* undefined? */
969 SYMBOL_TYPE(s) = parse_type(ax + sh->index, 0, bigend);
970 /* Value of a data symbol is its memory address */
973 case stParam: /* arg to procedure, goes into current block */
975 top_stack->numargs++;
977 name = (char*)sh->iss;
978 /* Special GNU C++ name. */
979 if (name[0] == CPLUS_MARKER && name[1] == 't' && name[2] == 0)
980 name = "this"; /* FIXME, not alloc'd in obstack */
981 s = new_symbol(name);
983 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
984 if (sh->sc == scRegister) {
985 SYMBOL_CLASS(s) = LOC_REGPARM;
987 sh->value += FP0_REGNUM-32;
989 SYMBOL_CLASS(s) = LOC_ARG;
990 SYMBOL_VALUE(s) = sh->value;
991 SYMBOL_TYPE(s) = parse_type(ax + sh->index, 0, bigend);
992 add_symbol(s, top_stack->cur_block);
994 /* FIXME: This has not been tested. See dbxread.c */
995 /* Add the type of this parameter to the function/procedure
996 type of this block. */
997 add_param_to_type(&top_stack->cur_block->function->type,s);
1001 case stLabel: /* label, goes into current block */
1002 s = new_symbol((char *)sh->iss);
1003 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; /* so that it can be used */
1004 SYMBOL_CLASS(s) = LOC_LABEL; /* but not misused */
1005 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
1006 SYMBOL_TYPE(s) = builtin_type_int;
1007 add_symbol(s, top_stack->cur_block);
1010 case stProc: /* Procedure, usually goes into global block */
1011 case stStaticProc: /* Static procedure, goes into current block */
1012 s = new_symbol((char *)sh->iss);
1013 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1014 SYMBOL_CLASS(s) = LOC_BLOCK;
1015 /* Type of the return value */
1016 if (sh->sc == scUndefined || sh->sc == scNil)
1017 t = builtin_type_int;
1019 t = parse_type(ax + sh->index + 1, 0, bigend);
1020 b = top_stack->cur_block;
1021 if (sh->st == stProc) {
1022 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
1023 /* The next test should normally be true,
1024 but provides a hook for nested functions
1025 (which we don't want to make global). */
1026 if (b == BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK))
1027 b = BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK);
1031 /* Make a type for the procedure itself */
1033 /* FIXME: This has not been tested yet! See dbxread.c */
1034 /* Generate a template for the type of this function. The
1035 types of the arguments will be added as we read the symbol
1037 bcopy(SYMBOL_TYPE(s),lookup_function_type(t),sizeof(struct type));
1039 SYMBOL_TYPE(s) = lookup_function_type (t);
1042 /* Create and enter a new lexical context */
1043 b = new_block(top_stack->maxsyms);
1044 SYMBOL_BLOCK_VALUE(s) = b;
1045 BLOCK_FUNCTION(b) = s;
1046 BLOCK_START(b) = BLOCK_END(b) = sh->value;
1047 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1048 add_block(b, top_stack->cur_st);
1050 /* Not if we only have partial info */
1051 if (sh->sc == scUndefined || sh->sc == scNil)
1055 top_stack->cur_block = b;
1056 top_stack->blocktype = sh->st;
1057 top_stack->cur_type = SYMBOL_TYPE(s);
1058 top_stack->cur_field = -1;
1059 top_stack->procadr = sh->value;
1060 top_stack->numargs = 0;
1062 sh->value = (long) SYMBOL_TYPE(s);
1065 /* Beginning of code for structure, union, and enum definitions.
1066 They all share a common set of local variables, defined here. */
1068 enum type_code type_code;
1074 case stStruct: /* Start a block defining a struct type */
1075 type_code = TYPE_CODE_STRUCT;
1076 goto structured_common;
1078 case stUnion: /* Start a block defining a union type */
1079 type_code = TYPE_CODE_UNION;
1080 goto structured_common;
1082 case stEnum: /* Start a block defining an enum type */
1083 type_code = TYPE_CODE_ENUM;
1084 goto structured_common;
1086 case stBlock: /* Either a lexical block, or some type */
1087 if (sh->sc != scInfo)
1088 goto case_stBlock_code; /* Lexical block */
1090 type_code = TYPE_CODE_UNDEF; /* We have a type. */
1092 /* Common code for handling struct, union, enum, and/or as-yet-
1093 unknown-type blocks of info about structured data. `type_code'
1094 has been set to the proper TYPE_CODE, if we know it. */
1097 top_stack->blocktype = stBlock;
1099 s = new_symbol((char *)sh->iss);
1100 SYMBOL_NAMESPACE(s) = STRUCT_NAMESPACE;
1101 SYMBOL_CLASS(s) = LOC_TYPEDEF;
1102 SYMBOL_VALUE(s) = 0;
1103 add_symbol(s, top_stack->cur_block);
1105 /* First count the number of fields and the highest value. */
1108 for (tsym = sh+1; tsym->st != stEnd; tsym++)
1110 if (tsym->st == stMember) {
1111 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
1112 /* If the type of the member is Nil (or Void),
1113 without qualifiers, assume the tag is an
1115 if (tsym->index == indexNil)
1116 type_code = TYPE_CODE_ENUM;
1118 ecoff_swap_tir_in (bigend,
1119 &ax[tsym->index].a_ti,
1121 if ((tir.bt == btNil || tir.bt == btVoid)
1122 && tir.tq0 == tqNil)
1123 type_code = TYPE_CODE_ENUM;
1126 if (tsym->value > max_value)
1127 max_value = tsym->value;
1129 else if (tsym->st == stBlock
1130 || tsym->st == stUnion
1131 || tsym->st == stEnum
1132 || tsym->st == stStruct
1133 || tsym->st == stParsed) {
1134 if (tsym->sc == scVariant) ; /*UNIMPLEMENTED*/
1135 if (tsym->index != 0)
1136 tsym = ((SYMR*)cur_fdr->isymBase)
1139 else complain (&block_member_complaint, tsym->st);
1142 /* In an stBlock, there is no way to distinguish structs,
1143 unions, and enums at this point. This is a bug in the
1144 original design (that has been fixed with the
1145 recent addition of the stStruct, stUnion, and stEnum
1146 symbol types.) The way you can tell is if/when you
1147 see a variable or field of that type. In that case
1148 the variable's type (in the AUX table) says if the
1149 type is struct, union, or enum,
1150 and points back to the stBlock here.
1151 So you can patch the tag kind up later - but only
1152 if there actually is a variable or field of that type.
1154 So until we know for sure, we will guess at this point.
1156 If the first member has index==indexNil or a void type,
1157 assume we have an enumeration.
1158 Otherwise, if there is more than one member, and all
1159 the members have offset 0, assume we have a union.
1160 Otherwise, assume we have a struct.
1162 The heuristic could guess wrong in the case of
1163 of an enumeration with no members or a union
1164 with one (or zero) members, or when all except the
1165 last field of a struct have width zero.
1166 These are uncommon and/or illegal situations, and
1167 in any case guessing wrong probably doesn't matter much.
1169 But if we later do find out we were wrong,
1170 we fixup the tag kind. Members of an enumeration
1171 must be handled differently from struct/union fields,
1172 and that is harder to patch up, but luckily we
1173 shouldn't need to. (If there are any enumeration
1174 members, we can tell for sure it's an enum here.) */
1176 if (type_code == TYPE_CODE_UNDEF)
1177 if (nfields > 1 && max_value == 0)
1178 type_code = TYPE_CODE_UNION;
1180 type_code = TYPE_CODE_STRUCT;
1182 /* If this type was expected, use its partial definition */
1184 t = is_pending_symbol(cur_fdr, sh)->t;
1186 t = new_type(prepend_tag_kind((char *)sh->iss,
1189 TYPE_CODE(t) = type_code;
1190 TYPE_LENGTH(t) = sh->value;
1191 TYPE_NFIELDS(t) = nfields;
1192 TYPE_FIELDS(t) = f = (struct field*)
1193 TYPE_ALLOC (t, nfields * sizeof (struct field));
1195 if (type_code == TYPE_CODE_ENUM) {
1196 /* This is a non-empty enum. */
1197 for (tsym = sh + 1; tsym->st == stMember; tsym++) {
1198 struct symbol *enum_sym;
1199 f->bitpos = tsym->value;
1201 f->name = (char*)tsym->iss;
1204 enum_sym = (struct symbol *)
1205 obstack_alloc (¤t_objfile->symbol_obstack,
1206 sizeof (struct symbol));
1207 memset ((PTR)enum_sym, 0, sizeof (struct symbol));
1208 SYMBOL_NAME (enum_sym) = f->name;
1209 SYMBOL_CLASS (enum_sym) = LOC_CONST;
1210 SYMBOL_TYPE (enum_sym) = t;
1211 SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
1212 SYMBOL_VALUE (enum_sym) = tsym->value;
1213 add_symbol(enum_sym, top_stack->cur_block);
1215 /* Skip the stMembers that we've handled. */
1221 /* make this the current type */
1222 top_stack->cur_type = t;
1223 top_stack->cur_field = 0;
1224 /* Mark that symbol has a type, and say which one */
1225 sh->value = (long) t;
1228 /* End of local variables shared by struct, union, enum, and
1229 block (as yet unknown struct/union/enum) processing. */
1233 /* beginnning of (code) block. Value of symbol
1234 is the displacement from procedure start */
1236 top_stack->blocktype = stBlock;
1237 b = new_block(top_stack->maxsyms);
1238 BLOCK_START(b) = sh->value + top_stack->procadr;
1239 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1240 top_stack->cur_block = b;
1241 add_block(b, top_stack->cur_st);
1244 case stEnd: /* end (of anything) */
1245 if (sh->sc == scInfo) {
1246 /* Finished with type */
1247 top_stack->cur_type = 0;
1248 } else if (sh->sc == scText &&
1249 (top_stack->blocktype == stProc ||
1250 top_stack->blocktype == stStaticProc)) {
1251 /* Finished with procedure */
1252 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
1253 struct mips_extra_func_info *e;
1257 BLOCK_END(top_stack->cur_block) += sh->value; /* size */
1259 /* Make up special symbol to contain procedure specific
1261 s = new_symbol(MIPS_EFI_SYMBOL_NAME);
1262 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
1263 SYMBOL_CLASS(s) = LOC_CONST;
1264 SYMBOL_TYPE(s) = builtin_type_void;
1265 e = (struct mips_extra_func_info *)
1266 obstack_alloc (¤t_objfile->symbol_obstack,
1267 sizeof (struct mips_extra_func_info));
1268 SYMBOL_VALUE(s) = (int)e;
1269 e->numargs = top_stack->numargs;
1270 add_symbol(s, top_stack->cur_block);
1272 /* Reallocate symbols, saving memory */
1273 b = shrink_block(top_stack->cur_block, top_stack->cur_st);
1275 /* f77 emits proc-level with address bounds==[0,0],
1276 So look for such child blocks, and patch them. */
1277 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) {
1278 struct block *b_bad = BLOCKVECTOR_BLOCK(bv,i);
1279 if (BLOCK_SUPERBLOCK(b_bad) == b
1280 && BLOCK_START(b_bad) == top_stack->procadr
1281 && BLOCK_END(b_bad) == top_stack->procadr) {
1282 BLOCK_START(b_bad) = BLOCK_START(b);
1283 BLOCK_END(b_bad) = BLOCK_END(b);
1286 } else if (sh->sc == scText && top_stack->blocktype == stBlock) {
1287 /* End of (code) block. The value of the symbol
1288 is the displacement from the procedure`s start
1289 address of the end of this block. */
1290 BLOCK_END(top_stack->cur_block) = sh->value + top_stack->procadr;
1291 shrink_block(top_stack->cur_block, top_stack->cur_st);
1292 } else if (sh->sc == scText && top_stack->blocktype == stFile) {
1293 /* End of file. Pop parse stack and ignore. Higher
1294 level code deals with this. */
1296 } else complain (&stEnd_complaint, sh->sc);
1298 pop_parse_stack(); /* restore previous lexical context */
1301 case stMember: /* member of struct or union */
1302 f = &TYPE_FIELDS(top_stack->cur_type)[top_stack->cur_field++];
1303 f->name = (char*)sh->iss;
1304 f->bitpos = sh->value;
1306 f->type = parse_type(ax + sh->index, &f->bitsize, bigend);
1309 case stTypedef: /* type definition */
1310 s = new_symbol((char *)sh->iss);
1311 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1312 SYMBOL_CLASS(s) = LOC_TYPEDEF;
1313 SYMBOL_BLOCK_VALUE(s) = top_stack->cur_block;
1314 add_symbol(s, top_stack->cur_block);
1315 SYMBOL_TYPE(s) = parse_type(ax + sh->index, 0, bigend);
1316 sh->value = (long) SYMBOL_TYPE(s);
1319 case stFile: /* file name */
1321 top_stack->blocktype = sh->st;
1324 /* I`ve never seen these for C */
1326 break; /* register relocation */
1328 break; /* forwarding address */
1330 break; /* constant */
1332 complain(&unknown_mips_symtype_complaint, sh->st);
1339 /* Parse the type information provided in the raw AX entries for
1340 the symbol SH. Return the bitfield size in BS, in case.
1341 We must byte-swap the AX entries before we use them; BIGEND says whether
1342 they are big-endian or little-endian (from fh->fBigendian). */
1344 static struct type *
1345 parse_type(ax, bs, bigend)
1350 /* Null entries in this map are treated specially */
1351 static struct type **map_bt[] =
1353 &builtin_type_void, /* btNil */
1355 &builtin_type_char, /* btChar */
1356 &builtin_type_unsigned_char, /* btUChar */
1357 &builtin_type_short, /* btShort */
1358 &builtin_type_unsigned_short, /* btUShort */
1359 &builtin_type_int, /* btInt */
1360 &builtin_type_unsigned_int, /* btUInt */
1361 &builtin_type_long, /* btLong */
1362 &builtin_type_unsigned_long, /* btULong */
1363 &builtin_type_float, /* btFloat */
1364 &builtin_type_double, /* btDouble */
1371 &builtin_type_complex, /* btComplex */
1372 &builtin_type_double_complex, /* btDComplex */
1374 &builtin_type_fixed_dec, /* btFixedDec */
1375 &builtin_type_float_dec, /* btFloatDec */
1376 &builtin_type_string, /* btString */
1379 &builtin_type_void, /* btVoid */
1380 &builtin_type_long_long, /* btLongLong */
1381 &builtin_type_unsigned_long_long,/* btULongLong */
1385 struct type *tp = 0;
1388 enum type_code type_code;
1390 /* Use aux as a type information record, map its basic type. */
1392 ecoff_swap_tir_in (bigend, &tax->a_ti, t);
1393 if (t->bt > (sizeof (map_bt)/sizeof (*map_bt))) {
1394 complain (&basic_type_complaint, t->bt);
1395 return builtin_type_int;
1397 if (map_bt[t->bt]) {
1398 tp = *map_bt[t->bt];
1402 /* Cannot use builtin types -- build our own */
1405 tp = lookup_pointer_type (builtin_type_void);
1409 type_code = TYPE_CODE_STRUCT;
1413 type_code = TYPE_CODE_UNION;
1417 type_code = TYPE_CODE_ENUM;
1421 type_code = TYPE_CODE_RANGE;
1425 type_code = TYPE_CODE_SET;
1430 complain (&basic_type_complaint, t->bt);
1431 return builtin_type_int;
1435 /* Skip over any further type qualifiers (FIXME). */
1437 /* This is the way it would work if the compiler worked */
1441 ecoff_swap_tir_in (bigend, ax, t1);
1442 } while (t1->continued);
1445 /* Move on to next aux */
1449 *bs = AUX_GET_WIDTH (bigend, ax);
1453 /* All these types really point to some (common) MIPS type
1454 definition, and only the type-qualifiers fully identify
1455 them. We'll make the same effort at sharing. */
1456 if (t->bt == btIndirect ||
1457 t->bt == btStruct ||
1460 t->bt == btTypedef ||
1463 char name[256], *pn;
1465 /* Try to cross reference this type */
1466 ax += cross_ref(ax, &tp, type_code, &pn, bigend);
1467 /* reading .o file ? */
1468 if (UNSAFE_DATA_ADDR(tp))
1469 tp = init_type(type_code, 0, 0, (char *) NULL,
1470 (struct objfile *) NULL);
1471 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1472 sprintf(name, fmt, pn);
1474 /* Usually, TYPE_CODE(tp) is already type_code. The main
1475 exception is if we guessed wrong re struct/union/enum. */
1476 if (TYPE_CODE(tp) != type_code) {
1477 complain (&bad_tag_guess_complaint, name);
1478 TYPE_CODE(tp) = type_code;
1480 if (TYPE_NAME(tp) == NULL || strcmp(TYPE_NAME(tp), name) != 0)
1481 TYPE_NAME(tp) = obsavestring(name, strlen(name),
1482 ¤t_objfile -> type_obstack);
1485 /* Deal with range types */
1486 if (t->bt == btRange) {
1487 TYPE_NFIELDS (tp) = 2;
1488 TYPE_FIELDS (tp) = (struct field *)
1489 TYPE_ALLOC (tp, 2 * sizeof (struct field));
1490 TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
1491 ¤t_objfile -> type_obstack);
1492 TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
1494 TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
1495 ¤t_objfile -> type_obstack);
1496 TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
1500 /* Parse all the type qualifiers now. If there are more
1501 than 6 the game will continue in the next aux */
1503 #define PARSE_TQ(tq) \
1504 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1506 again: PARSE_TQ(tq0);
1516 ecoff_swap_tir_in (bigend, &tax->a_ti, t);
1522 /* Make up a complex type from a basic one. Type is passed by
1523 reference in TPP and side-effected as necessary. The type
1524 qualifier TQ says how to handle the aux symbols at AX for
1525 the symbol SX we are currently analyzing. BIGEND says whether
1526 aux symbols are big-endian or little-endian.
1527 Returns the number of aux symbols we parsed. */
1530 upgrade_type(tpp, tq, ax, bigend)
1539 /* Used in array processing */
1548 t = lookup_pointer_type (*tpp);
1553 t = lookup_function_type (*tpp);
1558 /* We should probably try to use create_array_type here. FIXME! */
1560 t = init_type(TYPE_CODE_ARRAY, 0, 0, (char *) NULL,
1561 (struct objfile *) NULL);
1562 TYPE_TARGET_TYPE(t) = *tpp;
1564 /* Determine and record the domain type (type of index) */
1565 ecoff_swap_rndx_in (bigend, ax, &rndx);
1570 rf = AUX_GET_ISYM (bigend, ax);
1573 fh = get_rfd(cur_fd, rf);
1575 /* Fields are kept in an array */
1576 /* FIXME - Memory leak! */
1577 if (TYPE_NFIELDS(t))
1578 TYPE_FIELDS(t) = (struct field*)
1579 xrealloc((PTR) TYPE_FIELDS(t),
1580 (TYPE_NFIELDS(t)+1) * sizeof(struct field));
1582 TYPE_FIELDS(t) = (struct field*)
1583 xzalloc(sizeof(struct field));
1584 f = &(TYPE_FIELD(t,TYPE_NFIELDS(t)));
1586 memset((PTR)f, 0, sizeof(struct field));
1588 /* XXX */ f->type = parse_type(id + (union aux_ext *)fh->iauxBase,
1589 &f->bitsize, bigend);
1592 lower = AUX_GET_DNLOW (bigend, ax);
1594 upper = AUX_GET_DNHIGH (bigend, ax);
1596 rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */
1598 /* Check whether supplied array element bit size matches
1599 the known size of the element type. If this complaint
1600 ends up not happening, we can remove this code. It's
1601 here because we aren't sure we understand this *&%&$
1603 id = TYPE_LENGTH(TYPE_TARGET_TYPE(t)) << 3; /* bitsize */
1605 /* Most likely an undefined type */
1607 TYPE_LENGTH(TYPE_TARGET_TYPE(t)) = id >> 3;
1610 complain (&array_bitsize_complaint, rf);
1612 TYPE_LENGTH(t) = (upper < 0) ? 0 :
1613 (upper - lower + 1) * (rf >> 3);
1618 /* Volatile -- currently ignored */
1622 /* Const -- currently ignored */
1626 complain (&unknown_type_qual_complaint, tq);
1632 /* Parse a procedure descriptor record PR. Note that the procedure
1633 is parsed _after_ the local symbols, now we just insert the extra
1634 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has already
1635 been placed in the procedure's main block. Note also that images that
1636 have been partially stripped (ld -x) have been deprived
1637 of local symbols, and we have to cope with them here.
1638 The procedure's code ends at BOUND */
1641 parse_procedure (pr, bound, have_stabs)
1646 struct symbol *s, *i;
1647 SYMR *sh = (SYMR*)pr->isym;
1649 struct mips_extra_func_info *e;
1652 /* Static procedure at address pr->adr. Sigh. */
1653 if (sh == (SYMR*)-1) {
1654 complain (&pdr_static_symbol_complaint, pr->adr);
1657 sh_name = (char*)sh->iss;
1659 s = lookup_symbol(sh_name, NULL, VAR_NAMESPACE, 0, NULL);
1661 s = mylookup_symbol(sh_name, top_stack->cur_block,
1662 VAR_NAMESPACE, LOC_BLOCK);
1665 b = SYMBOL_BLOCK_VALUE(s);
1667 complain (&pdr_for_nonsymbol_complaint, sh_name);
1671 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1672 s = new_symbol(sh_name);
1673 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1674 SYMBOL_CLASS(s) = LOC_BLOCK;
1675 /* Donno its type, hope int is ok */
1676 SYMBOL_TYPE(s) = lookup_function_type (builtin_type_int);
1677 add_symbol(s, top_stack->cur_block);
1678 /* Wont have symbols for this one */
1680 SYMBOL_BLOCK_VALUE(s) = b;
1681 BLOCK_FUNCTION(b) = s;
1682 BLOCK_START(b) = pr->adr;
1683 BLOCK_END(b) = bound;
1684 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1685 add_block(b, top_stack->cur_st);
1689 i = mylookup_symbol(MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, LOC_CONST);
1693 e = (struct mips_extra_func_info *)SYMBOL_VALUE(i);
1695 e->pdr.isym = (long)s;
1699 /* Parse the external symbol ES. Just call parse_symbol() after
1700 making sure we know where the aux are for it. For procedures,
1701 parsing of the PDRs has already provided all the needed
1702 information, we only parse them if SKIP_PROCEDURES is false,
1703 and only if this causes no symbol duplication.
1704 BIGEND says whether aux entries are big-endian or little-endian.
1706 This routine clobbers top_stack->cur_block and ->cur_st. */
1709 parse_external(es, skip_procedures, bigend)
1711 int skip_procedures;
1716 if (es->ifd != ifdNil) {
1718 cur_fdr = (FDR*)(cur_hdr->cbFdOffset) + cur_fd;
1719 ax = (union aux_ext *)cur_fdr->iauxBase;
1721 cur_fdr = (FDR*)(cur_hdr->cbFdOffset);
1725 /* Reading .o files */
1726 if (es->asym.sc == scUndefined || es->asym.sc == scNil) {
1728 switch (es->asym.st) {
1730 case stProc: what = "procedure"; n_undef_procs++; break;
1731 case stGlobal: what = "variable"; n_undef_vars++; break;
1732 case stLabel: what = "label"; n_undef_labels++; break;
1733 default : what = "symbol"; break;
1736 /* FIXME: Turn this into a complaint? */
1738 printf_filtered("Warning: %s `%s' is undefined (in %s)\n",
1739 what, es->asym.iss, fdr_name((char *)cur_fdr->rss));
1743 switch (es->asym.st) {
1745 /* If we have full symbols we do not need more */
1746 if (skip_procedures)
1748 if (mylookup_symbol ((char *)es->asym.iss, top_stack->cur_block,
1749 VAR_NAMESPACE, LOC_BLOCK))
1755 * Note that the case of a symbol with indexNil
1756 * must be handled anyways by parse_symbol().
1758 parse_symbol(&es->asym, ax, bigend);
1765 /* Parse the line number info for file descriptor FH into
1766 GDB's linetable LT. MIPS' encoding requires a little bit
1767 of magic to get things out. Note also that MIPS' line
1768 numbers can go back and forth, apparently we can live
1769 with that and do not need to reorder our linetables */
1774 struct linetable *lt;
1776 unsigned char *base = (unsigned char*)fh->cbLineOffset;
1778 int delta, count, lineno = 0;
1784 /* Scan by procedure descriptors */
1786 for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) {
1789 /* No code for this one */
1790 if (pr->iline == ilineNil ||
1791 pr->lnLow == -1 || pr->lnHigh == -1)
1794 * Aurgh! To know where to stop expanding we
1797 for (l = 1; l < (fh->cpd - j); l++)
1798 if (pr[l].iline != -1)
1800 if (l == (fh->cpd - j))
1805 * When procedures are moved around the linenumbers
1806 * are attributed to the next procedure up
1808 if (pr->iline >= halt) continue;
1810 base = (unsigned char*)pr->cbLineOffset;
1811 l = pr->adr >> 2; /* in words */
1812 halt += (pr->adr >> 2) - pr->iline;
1813 for (lineno = pr->lnLow; l < halt;) {
1814 count = *base & 0x0f;
1815 delta = *base++ >> 4;
1819 delta = (base[0] << 8) | base[1];
1820 if (delta >= 0x8000)
1824 lineno += delta;/* first delta is 0 */
1825 k = add_line(lt, lineno, l, k);
1831 /* Master parsing procedure for first-pass reading of file symbols
1832 into a partial_symtab.
1834 Parses the symtab described by the global symbolic header CUR_HDR.
1835 END_OF_TEXT_SEG gives the address just after the text segment for
1836 the symtab we are reading. */
1839 parse_partial_symbols (end_of_text_seg, objfile, section_offsets)
1840 int end_of_text_seg;
1841 struct objfile *objfile;
1842 struct section_offsets *section_offsets;
1845 HDRR *hdr = cur_hdr;
1846 /* Running pointers */
1850 struct partial_symtab *pst;
1852 int past_first_source_file = 0;
1854 /* List of current psymtab's include files */
1855 char **psymtab_include_list;
1856 int includes_allocated;
1859 struct pst_map * fdr_to_pst;
1860 /* Index within current psymtab dependency list */
1861 struct partial_symtab **dependency_list;
1862 int dependencies_used, dependencies_allocated;
1863 struct cleanup *old_chain;
1865 extern_tab = (EXTR**)obstack_alloc (&objfile->psymbol_obstack,
1866 sizeof(EXTR *) * hdr->iextMax);
1868 includes_allocated = 30;
1870 psymtab_include_list = (char **) alloca (includes_allocated *
1872 next_symbol_text_func = mips_next_symbol_text;
1874 dependencies_allocated = 30;
1875 dependencies_used = 0;
1877 (struct partial_symtab **) alloca (dependencies_allocated *
1878 sizeof (struct partial_symtab *));
1880 last_source_file = NULL;
1885 * Only parse the Local and External symbols, and the Relative FDR.
1886 * Fixup enough of the loader symtab to be able to use it.
1887 * Allocate space only for the file's portions we need to
1892 max_glevel = MIN_GLEVEL;
1894 /* Allocate the map FDR -> PST.
1895 Minor hack: -O3 images might claim some global data belongs
1896 to FDR -1. We`ll go along with that */
1897 fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
1898 old_chain = make_cleanup (free, fdr_to_pst);
1901 struct partial_symtab * pst = new_psymtab("", objfile);
1902 fdr_to_pst[-1].pst = pst;
1906 /* Pass 1 over external syms: Presize and partition the list */
1907 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1908 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1909 fdr_to_pst[esh->ifd].n_globals++;
1912 /* Pass 1.5 over files: partition out global symbol space */
1914 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {
1915 fdr_to_pst[f_idx].globals_offset = s_idx;
1916 s_idx += fdr_to_pst[f_idx].n_globals;
1917 fdr_to_pst[f_idx].n_globals = 0;
1920 /* Pass 2 over external syms: fill in external symbols */
1921 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1922 enum minimal_symbol_type ms_type = mst_text;
1923 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1925 extern_tab[fdr_to_pst[esh->ifd].globals_offset
1926 + fdr_to_pst[esh->ifd].n_globals++] = esh;
1928 if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)
1931 switch (esh->asym.st) {
1940 ms_type = mst_unknown;
1941 complain (&unknown_ext_complaint, esh->asym.iss);
1943 prim_record_minimal_symbol ((char *)esh->asym.iss,
1948 /* Pass 3 over files, over local syms: fill in static symbols */
1949 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1950 struct partial_symtab *save_pst;
1953 cur_fdr = fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
1955 if (fh->csym == 0) {
1956 fdr_to_pst[f_idx].pst = NULL;
1959 pst = start_psymtab_common (objfile, section_offsets, (char*)fh->rss,
1960 fh->cpd ? fh->adr : 0,
1961 objfile->global_psymbols.next,
1962 objfile->static_psymbols.next);
1963 pst->read_symtab_private = (char *)
1964 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
1967 /* Make everything point to everything. */
1968 FDR_IDX(pst) = f_idx;
1969 fdr_to_pst[f_idx].pst = pst;
1970 fh->ioptBase = (int)pst;
1972 CUR_HDR(pst) = cur_hdr;
1974 /* The way to turn this into a symtab is to call... */
1975 pst->read_symtab = mipscoff_psymtab_to_symtab;
1977 pst->texthigh = pst->textlow;
1979 /* For stabs-in-ecoff files, the second symbol must be @stab.
1980 This symbol is emitted by mips-tfile to signal
1981 that the current object file uses encapsulated stabs
1982 instead of mips ecoff for local symbols.
1983 (It is the second symbol because the first symbol is
1984 the stFile used to signal the start of a file). */
1986 && strcmp((char *)(((SYMR *)fh->isymBase)[1].iss),
1987 stabs_symbol) == 0) {
1988 processing_gcc_compilation = 2;
1989 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) {
1992 sh = cur_sdx + (SYMR *) fh->isymBase;
1993 type_code = MIPS_UNMARK_STAB(sh->index);
1994 if (!MIPS_IS_STAB(sh)) {
1995 if (sh->st == stProc || sh->st == stStaticProc) {
1996 long procaddr = sh->value;
1997 sh = AUX_GET_ISYM (fh->fBigendian,
1998 sh->index + (union aux_ext *)(fh->iauxBase))
1999 + (SYMR *) fh->isymBase - 1;
2000 if (sh->st == stEnd) {
2001 long high = procaddr + sh->value;
2002 if (high > pst->texthigh)
2003 pst->texthigh = high;
2008 #define SET_NAMESTRING() namestring = (char*)sh->iss
2009 #define CUR_SYMBOL_TYPE type_code
2010 #define CUR_SYMBOL_VALUE sh->value
2011 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
2013 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
2014 #define HANDLE_RBRAC(val) \
2015 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2016 #include "partial-stab.h"
2020 processing_gcc_compilation = 0;
2021 for (cur_sdx = 0; cur_sdx < fh->csym; ) {
2023 enum address_class class;
2024 sh = cur_sdx + (SYMR *) fh->isymBase;
2026 if (MIPS_IS_STAB(sh)) {
2031 if (sh->sc == scUndefined || sh->sc == scNil ||
2032 sh->index == 0xfffff) {
2033 /* FIXME, premature? */
2038 name = (char *)(sh->iss);
2045 case stProc: /* Asm labels apparently */
2046 case stStaticProc: /* Function */
2047 ADD_PSYMBOL_TO_LIST(name, strlen(name),
2048 VAR_NAMESPACE, LOC_BLOCK,
2049 objfile->static_psymbols, sh->value);
2050 /* Skip over procedure to next one. */
2051 if (sh->index >= hdr->iauxMax)
2053 /* Should not happen, but does when cross-compiling
2054 with the MIPS compiler. FIXME -- pull later. */
2055 complain (&index_complaint, name);
2056 new_sdx = cur_sdx+1; /* Don't skip at all */
2059 new_sdx = AUX_GET_ISYM (fh->fBigendian,
2060 sh->index + (union aux_ext *)fh->iauxBase);
2061 procaddr = sh->value;
2063 if (new_sdx <= cur_sdx)
2065 /* This should not happen either... FIXME. */
2066 complain (&aux_index_complaint, name);
2067 new_sdx = cur_sdx + 1; /* Don't skip backward */
2071 sh = cur_sdx + (SYMR *) fh->isymBase - 1;
2072 if (sh->st != stEnd)
2074 high = procaddr + sh->value;
2075 if (high > pst->texthigh)
2076 pst->texthigh = high;
2079 case stStatic: /* Variable */
2083 case stTypedef: /* Typedef */
2084 class = LOC_TYPEDEF;
2087 case stConstant: /* Constant decl */
2094 case stBlock: /* { }, str, un, enum*/
2095 if (sh->sc == scInfo) {
2096 ADD_PSYMBOL_TO_LIST(name, strlen(name),
2097 STRUCT_NAMESPACE, LOC_TYPEDEF,
2098 objfile->static_psymbols, sh->value);
2100 /* Skip over the block */
2101 cur_sdx = sh->index;
2104 case stFile: /* File headers */
2105 case stLabel: /* Labels */
2106 case stEnd: /* Ends of files */
2109 case stLocal: /* Local variables */
2110 /* Normally these are skipped because we skip over
2111 all blocks we see. However, these can occur
2112 as visible symbols in a .h file that contains code. */
2116 /* Both complaints are valid: one gives symbol name,
2117 the other the offending symbol type. */
2118 complain (&unknown_sym_complaint, sh->iss);
2119 complain (&unknown_st_complaint, sh->st);
2123 /* Use this gdb symbol */
2124 ADD_PSYMBOL_TO_LIST(name, strlen(name),
2125 VAR_NAMESPACE, class,
2126 objfile->static_psymbols, sh->value);
2128 cur_sdx++; /* Go to next file symbol */
2131 /* Now do enter the external symbols. */
2132 ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
2133 cur_sdx = fdr_to_pst[f_idx].n_globals;
2134 PST_PRIVATE(save_pst)->extern_count = cur_sdx;
2135 PST_PRIVATE(save_pst)->extern_tab = ext_ptr;
2136 for (; --cur_sdx >= 0; ext_ptr++) {
2137 register struct partial_symbol *psym;
2138 enum address_class class;
2140 if ((*ext_ptr)->ifd != f_idx)
2142 sh = &(*ext_ptr)->asym;
2151 complain (&unknown_ext_complaint, sh->iss);
2152 /* Fall through, pretend it's global. */
2157 if (objfile->global_psymbols.next >=
2158 objfile->global_psymbols.list + objfile->global_psymbols.size)
2159 extend_psymbol_list (&objfile->global_psymbols, objfile);
2160 psym = objfile->global_psymbols.next++;
2161 SYMBOL_NAME (psym) = (char*)sh->iss;
2162 SYMBOL_NAMESPACE (psym) = VAR_NAMESPACE;
2163 SYMBOL_CLASS (psym) = class;
2164 SYMBOL_VALUE_ADDRESS (psym) = (CORE_ADDR)sh->value;
2168 end_psymtab (save_pst, psymtab_include_list, includes_used,
2169 -1, save_pst->texthigh,
2170 dependency_list, dependencies_used);
2171 if (objfile -> ei.entry_point >= save_pst->textlow &&
2172 objfile -> ei.entry_point < save_pst->texthigh)
2174 objfile -> ei.entry_file_lowpc = save_pst->textlow;
2175 objfile -> ei.entry_file_highpc = save_pst->texthigh;
2179 /* Mark the last code address, and remember it for later */
2180 hdr->cbDnOffset = end_of_text_seg;
2182 /* Now scan the FDRs for dependencies */
2183 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
2185 fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
2186 pst = fdr_to_pst[f_idx].pst;
2188 /* This should catch stabs-in-ecoff. */
2192 if (fh->cpd == 0) { /* If there are no functions defined here ... */
2193 /* ...then presumably a .h file: drop reverse depends .h->.c */
2194 for (; s_id0 < fh->crfd; s_id0++) {
2195 RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
2197 s_id0++; /* Skip self-dependency */
2202 pst->number_of_dependencies = fh->crfd - s_id0;
2203 pst->dependencies = (struct partial_symtab **)
2204 obstack_alloc (&objfile->psymbol_obstack,
2205 pst->number_of_dependencies *
2206 sizeof (struct partial_symtab *));
2207 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
2208 RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
2209 if (*rh < 0 || *rh >= hdr->ifdMax)
2210 complain(&bad_file_number_complaint, *rh);
2212 pst->dependencies[s_idx-s_id0] = fdr_to_pst[*rh].pst;
2215 do_cleanups (old_chain);
2220 /* Do the initial analisys of the F_IDX-th file descriptor.
2221 Allocates a partial symtab for it, and builds the list
2222 of dependent files by recursion. LEV says at which level
2223 of recursion we are called (to pretty up debug traces) */
2225 static struct partial_symtab *
2226 parse_fdr(f_idx, lev, objfile)
2229 struct objfile *objfile;
2232 register struct partial_symtab *pst;
2235 fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx;
2237 /* Use this to indicate into which symtab this file was parsed */
2239 return (struct partial_symtab *) fh->ioptBase;
2241 /* Debuggability level */
2242 if (compare_glevel(max_glevel, fh->glevel) < 0)
2243 max_glevel = fh->glevel;
2245 /* Make a new partial_symtab */
2246 pst = new_psymtab(fh->rss, objfile);
2251 pst->textlow = fh->adr;
2252 pst->texthigh = fh->cpd; /* To be fixed later */
2255 /* Make everything point to everything. */
2256 FDR_IDX(pst) = f_idx;
2257 fdr_to_pst[f_idx].pst = pst;
2258 fh->ioptBase = (int)pst;
2260 /* Analyze its dependencies */
2265 if (fh->cpd == 0) { /* If there are no functions defined here ... */
2266 /* ...then presumably a .h file: drop reverse depends .h->.c */
2267 for (; s_id0 < fh->crfd; s_id0++) {
2268 RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
2270 s_id0++; /* Skip self-dependency */
2275 pst->number_of_dependencies = fh->crfd - s_id0;
2276 pst->dependencies = (struct partial_symtab **)
2277 obstack_alloc (&objfile->psymbol_obstack,
2278 pst->number_of_dependencies *
2279 sizeof (struct partial_symtab *));
2280 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
2281 RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
2283 pst->dependencies[s_idx-s_id0] = parse_fdr(*rh, lev+1, objfile);
2291 mips_next_symbol_text ()
2294 return (char*)((SYMR *)cur_fdr->isymBase)[cur_sdx].iss;
2297 /* Ancillary function to psymtab_to_symtab(). Does all the work
2298 for turning the partial symtab PST into a symtab, recurring
2299 first on all dependent psymtabs. The argument FILENAME is
2300 only passed so we can see in debug stack traces what file
2303 This function has a split personality, based on whether the
2304 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
2305 The flow of control and even the memory allocation differs. FIXME. */
2308 psymtab_to_symtab_1(pst, filename)
2309 struct partial_symtab *pst;
2315 struct linetable *lines;
2322 /* Read in all partial symbtabs on which this one is dependent.
2323 NOTE that we do have circular dependencies, sigh. We solved
2324 that by setting pst->readin before this point. */
2326 for (i = 0; i < pst->number_of_dependencies; i++)
2327 if (!pst->dependencies[i]->readin) {
2328 /* Inform about additional files to be read in. */
2331 fputs_filtered (" ", stdout);
2333 fputs_filtered ("and ", stdout);
2335 printf_filtered ("%s...",
2336 pst->dependencies[i]->filename);
2337 wrap_here (""); /* Flush output */
2340 /* We only pass the filename for debug purposes */
2341 psymtab_to_symtab_1(pst->dependencies[i],
2342 pst->dependencies[i]->filename);
2345 /* Now read the symbols for this symtab */
2347 current_objfile = pst->objfile;
2348 cur_fd = FDR_IDX(pst);
2349 fh = (cur_fd == -1) ? 0 : (FDR *) (cur_hdr->cbFdOffset) + FDR_IDX(pst);
2352 /* BOUND is the highest core address of this file's procedures */
2353 bound = (cur_fd == cur_hdr->ifdMax - 1) ?
2354 cur_hdr->cbDnOffset :
2357 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2358 if (fh && fh->csym >= 2
2359 && strcmp((char *)(((SYMR *)fh->isymBase)[1].iss), stabs_symbol)
2363 * This symbol table contains stabs-in-ecoff entries.
2368 /* We indicate that this is a GCC compilation so that certain features
2369 will be enabled in stabsread/dbxread. */
2370 processing_gcc_compilation = 2;
2371 /* Parse local symbols first */
2373 if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr */
2375 current_objfile = NULL;
2378 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) {
2379 register SYMR *sh = cur_sdx + (SYMR *) fh->isymBase;
2380 char *name = (char*)sh->iss;
2381 CORE_ADDR valu = sh->value;
2382 if (MIPS_IS_STAB(sh)) {
2383 int type_code = MIPS_UNMARK_STAB(sh->index);
2384 process_one_symbol (type_code, 0, valu, name,
2385 pst->section_offsets, pst->objfile);
2386 if (type_code == N_FUN) {
2387 /* Make up special symbol to contain
2388 procedure specific info */
2389 struct mips_extra_func_info *e =
2390 (struct mips_extra_func_info *)
2391 obstack_alloc(¤t_objfile->symbol_obstack,
2392 sizeof(struct mips_extra_func_info));
2393 struct symbol *s = new_symbol(MIPS_EFI_SYMBOL_NAME);
2394 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
2395 SYMBOL_CLASS(s) = LOC_CONST;
2396 SYMBOL_TYPE(s) = builtin_type_void;
2397 SYMBOL_VALUE(s) = (int)e;
2398 add_symbol_to_list (s, &local_symbols);
2401 else if (sh->st == stLabel && sh->index != indexNil) {
2402 /* Handle encoded stab line number. */
2403 record_line (current_subfile, sh->index, valu);
2405 else complain (&stab_unknown_complaint, sh->iss);
2407 st = end_symtab (pst->texthigh, 0, 0, pst->objfile);
2410 /* Sort the symbol table now, we are done adding symbols to it.
2411 We must do this before parse_procedure calls lookup_symbol. */
2412 sort_symtab_syms(st);
2414 /* This may not be necessary for stabs symtabs. FIXME. */
2417 /* Fill in procedure info next. We need to look-ahead to
2418 find out where each procedure's code ends. */
2420 for (i = 0; i <= fh->cpd-1; i++) {
2421 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + i;
2422 parse_procedure (pr, i < fh->cpd-1 ? pr[1].adr : bound, 1);
2427 * This symbol table contains ordinary ecoff entries.
2430 /* FIXME: doesn't use pst->section_offsets. */
2436 processing_gcc_compilation = 0;
2438 /* How many symbols will we need */
2439 /* FIXME, this does not count enum values. */
2440 f_max = pst->n_global_syms + pst->n_static_syms;
2443 st = new_symtab ("unknown", f_max, 0, pst->objfile);
2445 f_max += fh->csym + fh->cpd;
2446 maxlines = 2 * fh->cline;
2447 st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
2450 lines = LINETABLE(st);
2451 pending_list = (struct mips_pending **) cur_hdr->cbOptOffset;
2452 if (pending_list == 0) {
2453 pending_list = (struct mips_pending **)
2454 xzalloc(cur_hdr->ifdMax * sizeof(struct mips_pending *));
2455 cur_hdr->cbOptOffset = (int)pending_list;
2458 /* Get a new lexical context */
2461 top_stack->cur_st = st;
2462 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(st),
2464 BLOCK_START(top_stack->cur_block) = fh ? fh->adr : 0;
2465 BLOCK_END(top_stack->cur_block) = 0;
2466 top_stack->blocktype = stFile;
2467 top_stack->maxsyms = 2*f_max;
2468 top_stack->cur_type = 0;
2469 top_stack->procadr = 0;
2470 top_stack->numargs = 0;
2476 /* Parse local symbols first */
2478 for (cur_sdx = 0; cur_sdx < fh->csym; ) {
2479 sh = (SYMR *) (fh->isymBase) + cur_sdx;
2480 cur_sdx += parse_symbol(sh, (union aux_ext *)fh->iauxBase,
2484 /* Linenumbers. At the end, check if we can save memory */
2486 parse_lines(fh, lines);
2487 if (lines->nitems < fh->cline)
2488 lines = shrink_linetable(lines);
2490 /* Fill in procedure info next. We need to look-ahead to
2491 find out where each procedure's code ends. */
2493 for (i = 0; i <= fh->cpd-1; i++) {
2494 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + i;
2495 parse_procedure(pr, i < fh->cpd-1 ? pr[1].adr : bound, 0);
2499 LINETABLE(st) = lines;
2501 /* .. and our share of externals.
2502 XXX use the global list to speed up things here. how?
2503 FIXME, Maybe quit once we have found the right number of ext's? */
2504 top_stack->cur_st = st;
2505 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
2507 top_stack->blocktype = stFile;
2508 top_stack->maxsyms =
2509 cur_hdr->isymMax + cur_hdr->ipdMax + cur_hdr->iextMax;
2511 ext_ptr = PST_PRIVATE(pst)->extern_tab;
2512 for (i = PST_PRIVATE(pst)->extern_count; --i >= 0; ext_ptr++)
2513 parse_external(*ext_ptr, 1, fh->fBigendian);
2515 /* If there are undefined, tell the user */
2516 if (n_undef_symbols) {
2517 printf_filtered("File %s contains %d unresolved references:",
2518 st->filename, n_undef_symbols);
2519 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2520 n_undef_vars, n_undef_procs, n_undef_labels);
2521 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
2526 /* Sort the symbol table now, we are done adding symbols to it.*/
2527 sort_symtab_syms(st);
2532 /* Now link the psymtab and the symtab. */
2535 current_objfile = NULL;
2538 /* Ancillary parsing procedures. */
2540 /* Lookup the type at relative index RN. Return it in TPP
2541 if found and in any event come up with its name PNAME.
2542 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2543 Return value says how many aux symbols we ate. */
2546 cross_ref(ax, tpp, type_code, pname, bigend)
2549 enum type_code type_code; /* Use to alloc new type if none is found. */
2557 ecoff_swap_rndx_in (bigend, ax, rn);
2559 /* Escape index means 'the next one' */
2560 if (rn->rfd == 0xfff) {
2562 rf = AUX_GET_ISYM (bigend, ax + 1);
2569 *pname = "<undefined>";
2572 * Find the relative file descriptor and the symbol in it
2574 FDR *fh = get_rfd(cur_fd, rf);
2579 * If we have processed this symbol then we left a forwarding
2580 * pointer to the corresponding GDB symbol. If not, we`ll put
2581 * it in a list of pending symbols, to be processed later when
2582 * the file f will be. In any event, we collect the name for
2583 * the type here. Which is why we made a first pass at
2586 sh = (SYMR *) (fh->isymBase) + rn->index;
2588 /* Careful, we might be looking at .o files */
2589 *pname = (UNSAFE_DATA_ADDR(sh->iss)) ? "<undefined>" :
2592 /* Have we parsed it ? */
2593 if ((!UNSAFE_DATA_ADDR(sh->value)) && (sh->st == stParsed)) {
2594 t = (struct type *) sh->value;
2597 /* Avoid duplicates */
2598 struct mips_pending *p = is_pending_symbol(fh, sh);
2602 *tpp = init_type(type_code, 0, 0, (char *) NULL,
2603 (struct objfile *) NULL);
2604 add_pending(fh, sh, *tpp);
2609 /* We used one auxent normally, two if we got a "next one" rf. */
2614 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2615 keeping the symtab sorted */
2617 static struct symbol *
2618 mylookup_symbol (name, block, namespace, class)
2620 register struct block *block;
2621 enum namespace namespace;
2622 enum address_class class;
2624 register int bot, top, inc;
2625 register struct symbol *sym;
2628 top = BLOCK_NSYMS(block);
2631 sym = BLOCK_SYM(block, bot);
2632 if (SYMBOL_NAME(sym)[0] == inc
2633 && SYMBOL_NAMESPACE(sym) == namespace
2634 && SYMBOL_CLASS(sym) == class
2635 && !strcmp(SYMBOL_NAME(sym), name))
2639 block = BLOCK_SUPERBLOCK (block);
2641 return mylookup_symbol (name, block, namespace, class);
2646 /* Add a new symbol S to a block B.
2647 Infrequently, we will need to reallocate the block to make it bigger.
2648 We only detect this case when adding to top_stack->cur_block, since
2649 that's the only time we know how big the block is. FIXME. */
2656 int nsyms = BLOCK_NSYMS(b)++;
2657 struct block *origb;
2658 struct parse_stack *stackp;
2660 if (b == top_stack->cur_block &&
2661 nsyms >= top_stack->maxsyms) {
2662 complain (&block_overflow_complaint, s->name);
2663 /* In this case shrink_block is actually grow_block, since
2664 BLOCK_NSYMS(b) is larger than its current size. */
2666 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
2668 /* Now run through the stack replacing pointers to the
2669 original block. shrink_block has already done this
2670 for the blockvector and BLOCK_FUNCTION. */
2671 for (stackp = top_stack; stackp; stackp = stackp->next) {
2672 if (stackp->cur_block == origb) {
2673 stackp->cur_block = b;
2674 stackp->maxsyms = BLOCK_NSYMS (b);
2678 BLOCK_SYM(b,nsyms) = s;
2681 /* Add a new block B to a symtab S */
2688 struct blockvector *bv = BLOCKVECTOR(s);
2690 bv = (struct blockvector *)xrealloc((PTR) bv,
2691 sizeof(struct blockvector) +
2692 BLOCKVECTOR_NBLOCKS(bv)
2693 * sizeof(bv->block));
2694 if (bv != BLOCKVECTOR(s))
2695 BLOCKVECTOR(s) = bv;
2697 BLOCKVECTOR_BLOCK(bv, BLOCKVECTOR_NBLOCKS(bv)++) = b;
2700 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2701 MIPS' linenumber encoding might need more than one byte
2702 to describe it, LAST is used to detect these continuation lines */
2705 add_line(lt, lineno, adr, last)
2706 struct linetable *lt;
2712 last = -2; /* make sure we record first line */
2714 if (last == lineno) /* skip continuation lines */
2717 lt->item[lt->nitems].line = lineno;
2718 lt->item[lt->nitems++].pc = adr << 2;
2722 /* Sorting and reordering procedures */
2724 /* Blocks with a smaller low bound should come first */
2727 compare_blocks(arg1, arg2)
2728 const void *arg1, *arg2;
2730 register int addr_diff;
2731 struct block **b1 = (struct block **) arg1;
2732 struct block **b2 = (struct block **) arg2;
2734 addr_diff = (BLOCK_START((*b1))) - (BLOCK_START((*b2)));
2736 return (BLOCK_END((*b1))) - (BLOCK_END((*b2)));
2740 /* Sort the blocks of a symtab S.
2741 Reorder the blocks in the blockvector by code-address,
2742 as required by some MI search routines */
2748 struct blockvector *bv = BLOCKVECTOR(s);
2750 if (BLOCKVECTOR_NBLOCKS(bv) <= 2) {
2752 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) == 0)
2753 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = 0;
2754 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) == 0)
2755 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = 0;
2759 * This is very unfortunate: normally all functions are compiled in
2760 * the order they are found, but if the file is compiled -O3 things
2761 * are very different. It would be nice to find a reliable test
2762 * to detect -O3 images in advance.
2764 if (BLOCKVECTOR_NBLOCKS(bv) > 3)
2765 qsort(&BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK),
2766 BLOCKVECTOR_NBLOCKS(bv) - FIRST_LOCAL_BLOCK,
2767 sizeof(struct block *),
2771 register CORE_ADDR high = 0;
2772 register int i, j = BLOCKVECTOR_NBLOCKS(bv);
2774 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
2775 if (high < BLOCK_END(BLOCKVECTOR_BLOCK(bv,i)))
2776 high = BLOCK_END(BLOCKVECTOR_BLOCK(bv,i));
2777 BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = high;
2780 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) =
2781 BLOCK_START(BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK));
2783 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2784 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2785 BLOCK_END (BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2786 BLOCK_END (BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2790 /* Constructor/restructor/destructor procedures */
2792 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2793 MAXSYMS and linenumbers MAXLINES we'll put in it */
2795 static struct symtab *
2796 new_symtab(name, maxsyms, maxlines, objfile)
2800 struct objfile *objfile;
2802 struct symtab *s = allocate_symtab (name, objfile);
2804 LINETABLE(s) = new_linetable(maxlines);
2806 /* All symtabs must have at least two blocks */
2807 BLOCKVECTOR(s) = new_bvect(2);
2808 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK) = new_block(maxsyms);
2809 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), STATIC_BLOCK) = new_block(maxsyms);
2810 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s),STATIC_BLOCK)) =
2811 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK);
2813 s->free_code = free_linetable;
2818 /* Allocate a new partial_symtab NAME */
2820 static struct partial_symtab *
2821 new_psymtab(name, objfile)
2823 struct objfile *objfile;
2825 struct partial_symtab *psymtab;
2827 /* FIXME -- why (char *) -1 rather than NULL? */
2828 psymtab = allocate_psymtab (name == (char *) -1 ? "<no name>" : name,
2831 /* Keep a backpointer to the file's symbols */
2833 psymtab -> read_symtab_private = (char *)
2834 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
2835 CUR_HDR(psymtab) = cur_hdr;
2837 /* The way to turn this into a symtab is to call... */
2838 psymtab->read_symtab = mipscoff_psymtab_to_symtab;
2843 /* Allocate a linetable array of the given SIZE. Since the struct
2844 already includes one item, we subtract one when calculating the
2845 proper size to allocate. */
2847 static struct linetable *
2851 struct linetable *l;
2853 size = (size-1) * sizeof(l->item) + sizeof(struct linetable);
2854 l = (struct linetable *)xmalloc(size);
2859 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2860 I am not so sure about the 3.4 ones.
2862 Since the struct linetable already includes one item, we subtract one when
2863 calculating the proper size to allocate. */
2865 static struct linetable *
2866 shrink_linetable(lt)
2867 struct linetable * lt;
2870 return (struct linetable *) xrealloc ((PTR)lt,
2871 sizeof(struct linetable)
2872 + (lt->nitems - 1) * sizeof(lt->item));
2875 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2877 static struct blockvector *
2881 struct blockvector *bv;
2884 size = sizeof(struct blockvector) + nblocks * sizeof(struct block*);
2885 bv = (struct blockvector *) xzalloc(size);
2887 BLOCKVECTOR_NBLOCKS(bv) = nblocks;
2892 /* Allocate and zero a new block of MAXSYMS symbols */
2894 static struct block *
2898 int size = sizeof(struct block) + (maxsyms-1) * sizeof(struct symbol *);
2900 return (struct block *)xzalloc (size);
2903 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2904 Shrink_block can also be used by add_symbol to grow a block. */
2906 static struct block *
2912 struct blockvector *bv = BLOCKVECTOR(s);
2915 /* Just reallocate it and fix references to the old one */
2917 new = (struct block *) xrealloc ((PTR)b, sizeof(struct block) +
2918 (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *));
2920 /* Should chase pointers to old one. Fortunately, that`s just
2921 the block`s function and inferior blocks */
2922 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b)
2923 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2924 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2925 if (BLOCKVECTOR_BLOCK(bv,i) == b)
2926 BLOCKVECTOR_BLOCK(bv,i) = new;
2927 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) == b)
2928 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) = new;
2932 /* Create a new symbol with printname NAME */
2934 static struct symbol *
2938 struct symbol *s = (struct symbol *)
2939 obstack_alloc (¤t_objfile->symbol_obstack, sizeof (struct symbol));
2941 memset ((PTR)s, 0, sizeof (*s));
2942 SYMBOL_NAME(s) = name;
2946 /* Create a new type with printname NAME */
2948 static struct type *
2954 t = alloc_type (current_objfile);
2955 TYPE_NAME(t) = name;
2956 TYPE_CPLUS_SPECIFIC(t) = (struct cplus_struct_type *)
2957 &cplus_struct_default;
2962 /* Things used for calling functions in the inferior.
2963 These functions are exported to our companion
2964 mips-tdep.c file and are here because they play
2965 with the symbol-table explicitly. */
2967 /* Sigtramp: make sure we have all the necessary information
2968 about the signal trampoline code. Since the official code
2969 from MIPS does not do so, we make up that information ourselves.
2970 If they fix the library (unlikely) this code will neutralize itself. */
2977 struct block *b, *b0;
2979 sigtramp_address = -1;
2981 /* We know it is sold as sigvec */
2982 s = lookup_symbol("sigvec", 0, VAR_NAMESPACE, 0, NULL);
2984 /* Most programs do not play with signals */
2986 s = lookup_symbol("_sigtramp", 0, VAR_NAMESPACE, 0, NULL);
2989 b0 = SYMBOL_BLOCK_VALUE(s);
2991 /* A label of sigvec, to be more precise */
2992 s = lookup_symbol("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
2995 /* But maybe this program uses its own version of sigvec */
2999 /* Did we or MIPSco fix the library ? */
3000 if (SYMBOL_CLASS(s) == LOC_BLOCK)
3002 sigtramp_address = BLOCK_START(SYMBOL_BLOCK_VALUE(s));
3003 sigtramp_end = BLOCK_END(SYMBOL_BLOCK_VALUE(s));
3007 sigtramp_address = SYMBOL_VALUE(s);
3008 sigtramp_end = sigtramp_address + 0x88; /* black magic */
3010 /* But what symtab does it live in ? */
3011 st = find_pc_symtab(SYMBOL_VALUE(s));
3014 * Ok, there goes the fix: turn it into a procedure, with all the
3015 * needed info. Note we make it a nested procedure of sigvec,
3016 * which is the way the (assembly) code is actually written.
3018 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
3019 SYMBOL_CLASS(s) = LOC_BLOCK;
3020 SYMBOL_TYPE(s) = init_type(TYPE_CODE_FUNC, 4, 0, (char *) NULL,
3021 (struct objfile *) NULL);
3022 TYPE_TARGET_TYPE(SYMBOL_TYPE(s)) = builtin_type_void;
3024 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
3026 SYMBOL_BLOCK_VALUE(s) = b;
3027 BLOCK_START(b) = sigtramp_address;
3028 BLOCK_END(b) = sigtramp_end;
3029 BLOCK_FUNCTION(b) = s;
3030 BLOCK_SUPERBLOCK(b) = BLOCK_SUPERBLOCK(b0);
3034 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
3036 struct mips_extra_func_info *e =
3037 (struct mips_extra_func_info *)
3038 xzalloc(sizeof(struct mips_extra_func_info));
3040 e->numargs = 0; /* the kernel thinks otherwise */
3041 /* align_longword(sigcontext + SIGFRAME) */
3042 e->pdr.frameoffset = 0x150;
3043 e->pdr.framereg = SP_REGNUM;
3045 e->pdr.regmask = -2;
3046 e->pdr.regoffset = -(41 * sizeof(int));
3047 e->pdr.fregmask = -1;
3048 e->pdr.fregoffset = -(37 * sizeof(int));
3049 e->pdr.isym = (long)s;
3051 current_objfile = st->objfile; /* Keep new_symbol happy */
3052 s = new_symbol(MIPS_EFI_SYMBOL_NAME);
3053 SYMBOL_VALUE(s) = (int) e;
3054 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
3055 SYMBOL_CLASS(s) = LOC_CONST;
3056 SYMBOL_TYPE(s) = builtin_type_void;
3057 current_objfile = NULL;
3060 BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s;
3064 /* Fake up identical offsets for all sections. */
3066 struct section_offsets *
3067 mipscoff_symfile_offsets (objfile, addr)
3068 struct objfile *objfile;
3071 struct section_offsets *section_offsets;
3074 section_offsets = (struct section_offsets *)
3075 obstack_alloc (&objfile -> psymbol_obstack,
3076 sizeof (struct section_offsets) +
3077 sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
3079 for (i = 0; i < SECT_OFF_MAX; i++)
3080 ANOFFSET (section_offsets, i) = addr;
3082 return section_offsets;
3085 /* Initialization */
3087 static struct sym_fns ecoff_sym_fns =
3089 "ecoff", /* sym_name: name or name prefix of BFD target type */
3090 5, /* sym_namelen: number of significant sym_name chars */
3091 mipscoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
3092 mipscoff_symfile_init,/* sym_init: read initial info, setup for sym_read() */
3093 mipscoff_symfile_read,/* sym_read: read a symbol file into symtab */
3094 mipscoff_symfile_finish,/* sym_finish: finished with file, cleanup */
3095 mipscoff_symfile_offsets,/* sym_offsets: dummy FIXME til implem sym reloc */
3096 NULL /* next: pointer to next struct sym_fns */
3101 _initialize_mipsread ()
3103 add_symtab_fns (&ecoff_sym_fns);
3105 /* Missing basic types */
3107 builtin_type_string =
3108 init_type(TYPE_CODE_PASCAL_ARRAY,
3109 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3111 (struct objfile *) NULL);
3112 builtin_type_complex =
3113 init_type(TYPE_CODE_FLT,
3114 TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
3116 (struct objfile *) NULL);
3117 builtin_type_double_complex =
3118 init_type(TYPE_CODE_FLT,
3119 TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
3120 0, "double complex",
3121 (struct objfile *) NULL);
3122 builtin_type_fixed_dec =
3123 init_type(TYPE_CODE_INT,
3124 TARGET_INT_BIT / TARGET_CHAR_BIT,
3126 (struct objfile *) NULL);
3127 builtin_type_float_dec =
3128 init_type(TYPE_CODE_FLT,
3129 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3130 0, "floating decimal",
3131 (struct objfile *) NULL);