1 /* Read a symbol table in MIPS' format (Third-Eye).
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
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"
63 #include <sys/types.h>
68 #include <sys/param.h>
73 #include "gdb-stabs.h"
75 #include "coff/mips.h" /* COFF-like aspects of ecoff files */
76 #include "coff/ecoff-ext.h" /* External forms of ecoff sym structures */
78 #include "libbfd.h" /* FIXME Secret internal BFD stuff (bfd_read) */
79 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
80 #include "aout/aout64.h"
81 #include "aout/stab_gnu.h" /* STABS information */
82 #include "expression.h"
83 #include "language.h" /* Needed inside partial-stab.h */
86 struct external_filehdr f;
87 struct external_aouthdr a;
90 /* These must match the corresponding definition in gcc/config/xm-mips.h.
91 At some point, these should probably go into a shared include file,
92 but currently gcc and gdb do not share any directories. */
94 #define CODE_MASK 0x8F300
95 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
96 #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
97 #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
98 #define STABS_SYMBOL "@stabs"
100 /* Each partial symbol table entry contains a pointer to private data for the
101 read_symtab() function to use when expanding a partial symbol table entry
102 to a full symbol table entry.
104 For mipsread this structure contains the index of the FDR that this psymtab
105 represents and a pointer to the symbol table header HDRR from the symbol
106 file that the psymtab was created from. */
108 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
109 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
110 #define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)
115 EXTR **extern_tab; /* Pointer to external symbols for this file. */
116 int extern_count; /* Size of extern_tab. */
119 /* Things we import explicitly from other modules */
121 extern int info_verbose;
123 /* Various complaints about symbol reading that don't abort the process */
125 struct complaint bad_file_number_complaint =
126 {"bad file number %d", 0, 0};
128 struct complaint index_complaint =
129 {"bad aux index at symbol %s", 0, 0};
131 struct complaint aux_index_complaint =
132 {"bad proc end in aux found from symbol %s", 0, 0};
134 struct complaint unknown_ext_complaint =
135 {"unknown external symbol %s", 0, 0};
137 struct complaint unknown_sym_complaint =
138 {"unknown local symbol %s", 0, 0};
140 struct complaint unknown_st_complaint =
141 {"with type %d", 0, 0};
143 struct complaint block_overflow_complaint =
144 {"block containing %s overfilled", 0, 0};
146 struct complaint basic_type_complaint =
147 {"cannot map MIPS basic type 0x%x", 0, 0};
149 struct complaint unknown_type_qual_complaint =
150 {"unknown type qualifier 0x%x", 0, 0};
152 struct complaint array_bitsize_complaint =
153 {"size of array target type not known, assuming %d bits", 0, 0};
155 struct complaint bad_tag_guess_complaint =
156 {"guessed tag type of %s incorrectly", 0, 0};
158 struct complaint block_member_complaint =
159 {"declaration block contains unhandled symbol type %d", 0, 0};
161 struct complaint stEnd_complaint =
162 {"stEnd with storage class %d not handled", 0, 0};
164 struct complaint unknown_mips_symtype_complaint =
165 {"unknown symbol type 0x%x", 0, 0};
167 struct complaint stab_unknown_complaint =
168 {"unknown stabs symbol %s", 0, 0};
170 struct complaint pdr_for_nonsymbol_complaint =
171 {"PDR for %s, but no symbol", 0, 0};
173 struct complaint pdr_static_symbol_complaint =
174 {"can't handle PDR for static proc at 0x%x", 0, 0};
176 /* Macros and extra defs */
178 /* Already-parsed symbols are marked specially */
180 #define stParsed stType
182 /* Puns: hard to find whether -g was used and how */
184 #define MIN_GLEVEL GLEVEL_0
185 #define compare_glevel(a,b) \
186 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
187 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
189 /* When looking at .o files, avoid tripping over zero pointers.
190 FIXME; places that use this should be fixed to convert from
191 external to internal format, rather than examining in-place. */
193 #define UNSAFE_DATA_ADDR(p) ((p) == 0)
195 /* Things that really are local to this module */
197 /* MIPS symtab header for the current file */
199 static HDRR *cur_hdr;
201 /* Pointer to current file decriptor record, and its index */
206 /* Index of current symbol */
210 /* Note how much "debuggable" this image is. We would like
211 to see at least one FDR with full symbols */
216 /* When examining .o files, report on undefined symbols */
218 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
220 /* Pseudo symbol to use when putting stabs into the symbol table. */
222 static char stabs_symbol[] = STABS_SYMBOL;
224 /* Extra builtin types */
226 struct type *builtin_type_complex;
227 struct type *builtin_type_double_complex;
228 struct type *builtin_type_fixed_dec;
229 struct type *builtin_type_float_dec;
230 struct type *builtin_type_string;
232 /* Forward declarations */
235 fixup_symtab PARAMS ((HDRR *, char *, file_ptr, bfd *));
238 read_mips_symtab PARAMS ((struct objfile *, struct section_offsets *));
241 read_the_mips_symtab PARAMS ((bfd *, CORE_ADDR *));
244 upgrade_type PARAMS ((struct type **, int, union aux_ext *, int));
247 parse_partial_symbols PARAMS ((int, struct objfile *,
248 struct section_offsets *));
251 cross_ref PARAMS ((union aux_ext *, struct type **, enum type_code, char **,
255 fixup_sigtramp PARAMS ((void));
257 static struct symbol *
258 new_symbol PARAMS ((char *));
261 new_type PARAMS ((char *));
263 static struct block *
264 new_block PARAMS ((int));
266 static struct symtab *
267 new_symtab PARAMS ((char *, int, int, struct objfile *));
269 static struct linetable *
270 new_linetable PARAMS ((int));
272 static struct blockvector *
273 new_bvect PARAMS ((int));
276 parse_type PARAMS ((union aux_ext *, int *, int));
278 static struct symbol *
279 mylookup_symbol PARAMS ((char *, struct block *, enum namespace,
280 enum address_class));
282 static struct block *
283 shrink_block PARAMS ((struct block *, struct symtab *));
286 xzalloc PARAMS ((unsigned int));
289 sort_blocks PARAMS ((struct symtab *));
292 compare_blocks PARAMS ((const void *, const void *));
294 static struct partial_symtab *
295 new_psymtab PARAMS ((char *, struct objfile *));
298 static struct partial_symtab *
299 parse_fdr PARAMS ((int, int, struct objfile *));
303 psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *));
306 add_block PARAMS ((struct block *, struct symtab *));
309 add_symbol PARAMS ((struct symbol *, struct block *));
312 add_line PARAMS ((struct linetable *, int, CORE_ADDR, int));
314 static struct linetable *
315 shrink_linetable PARAMS ((struct linetable *));
318 mips_next_symbol_text PARAMS ((void));
320 /* Things we export to other modules */
322 /* Address bounds for the signal trampoline in inferior, if any */
323 /* FIXME: Nothing really seems to use this. Why is it here? */
325 CORE_ADDR sigtramp_address, sigtramp_end;
328 mipscoff_new_init (ignore)
329 struct objfile *ignore;
334 mipscoff_symfile_init (objfile)
335 struct objfile *objfile;
337 if (objfile -> sym_private != NULL)
339 mfree (objfile -> md, objfile -> sym_private);
341 objfile -> sym_private = NULL;
345 mipscoff_symfile_read (objfile, section_offsets, mainline)
346 struct objfile *objfile;
347 struct section_offsets *section_offsets;
350 init_minimal_symbol_collection ();
351 make_cleanup (discard_minimal_symbols, 0);
353 /* Now that the executable file is positioned at symbol table,
354 process it and define symbols accordingly. */
356 read_mips_symtab(objfile, section_offsets);
358 /* Install any minimal symbols that have been collected as the current
359 minimal symbols for this objfile. */
361 install_minimal_symbols (objfile);
364 /* Perform any local cleanups required when we are done with a particular
365 objfile. I.E, we are in the process of discarding all symbol information
366 for an objfile, freeing up all memory held for it, and unlinking the
367 objfile struct from the global list of known objfiles. */
370 mipscoff_symfile_finish (objfile)
371 struct objfile *objfile;
373 if (objfile -> sym_private != NULL)
375 mfree (objfile -> md, objfile -> sym_private);
378 /* If we have a file symbol header lying around, blow it away. */
387 /* Allocate zeroed memory */
393 PTR p = xmalloc (size);
399 /* Exported procedure: Builds a symtab from the PST partial one.
400 Restores the environment in effect when PST was created, delegates
401 most of the work to an ancillary procedure, and sorts
402 and reorders the symtab list at the end */
405 mipscoff_psymtab_to_symtab(pst)
406 struct partial_symtab *pst;
413 printf_filtered("Reading in symbols for %s...", pst->filename);
416 /* Restore the header and list of pending typedefs */
417 cur_hdr = CUR_HDR(pst);
419 next_symbol_text_func = mips_next_symbol_text;
421 psymtab_to_symtab_1(pst, pst->filename);
423 /* Match with global symbols. This only needs to be done once,
424 after all of the symtabs and dependencies have been read in. */
425 scan_file_globals (pst->objfile);
428 printf_filtered("done.\n");
431 /* Exported procedure: Is PC in the signal trampoline code */
434 in_sigtramp(pc, ignore)
436 char *ignore; /* function name */
438 if (sigtramp_address == 0)
440 return (pc >= sigtramp_address && pc < sigtramp_end);
443 /* File-level interface functions */
445 /* Read the symtab information from file ABFD into memory. Also,
446 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
449 read_the_mips_symtab(abfd, end_of_text_segp)
451 CORE_ADDR *end_of_text_segp;
453 int stsize, st_hdrsize;
455 struct hdr_ext hdr_ext;
457 /* Header for executable/object file we read symbols from */
458 struct coff_exec filhdr;
461 /* We need some info from the initial headers */
462 val = bfd_seek(abfd, (file_ptr) 0, L_SET);
463 val = bfd_read((PTR)&filhdr, sizeof filhdr, 1, abfd);
465 if (end_of_text_segp)
467 bfd_h_get_32 (abfd, filhdr.a.text_start) +
468 bfd_h_get_32 (abfd, filhdr.a.tsize);
470 /* Find and read the symbol table header */
471 st_hdrsize = bfd_h_get_32 (abfd, filhdr.f.f_nsyms);
472 st_filptr = bfd_h_get_32 (abfd, filhdr.f.f_symptr);
476 bfd_seek (abfd, st_filptr, L_SET);
477 if (st_hdrsize != sizeof (hdr_ext)) { /* Profanity check */
478 error ("Wrong header size: %d, not %d", st_hdrsize,
481 if (bfd_read((PTR)&hdr_ext, st_hdrsize, 1, abfd) != st_hdrsize)
483 ecoff_swap_hdr_in (abfd, &hdr_ext, &st_hdr);
485 /* Find out how large the symbol table is */
486 stsize = (st_hdr.cbExtOffset - (st_filptr + st_hdrsize))
487 + st_hdr.iextMax * cbEXTR;
489 /* Allocate space for the symbol table. Read it in. */
490 cur_hdr = (HDRR *) xmalloc(stsize + st_hdrsize);
492 memcpy((PTR)cur_hdr, (PTR)&hdr_ext, st_hdrsize);
493 if (bfd_read((char *)cur_hdr + st_hdrsize, stsize, 1, abfd) != stsize)
496 /* Fixup file_pointers in it */
497 fixup_symtab(cur_hdr, (char *) cur_hdr + st_hdrsize,
498 st_filptr + st_hdrsize, abfd);
502 error("Short read on %s", bfd_get_filename (abfd));
506 /* Turn all file-relative pointers in the symtab described by HDR
507 into memory pointers, given that the symtab itself is located
508 at DATA in memory and F_PTR in the file.
510 Byte-swap all the data structures, in place, while we are at it --
511 except AUX entries, which we leave in their original byte order.
512 They will be swapped as they are used instead. (FIXME: we ought to
513 do all the data structures that way.) */
516 fixup_symtab (hdr, data, f_ptr, abfd)
527 struct rfd_ext *rbase;
529 /* This function depends on the external and internal forms
530 of the MIPS symbol table taking identical space. Check this
531 assumption at compile-time.
532 DO NOT DELETE THESE ENTRIES, OR COMMENT THEM OUT, JUST BECAUSE SOME
533 "LINT" OR COMPILER THINKS THEY ARE UNUSED! Thank you. */
534 static check_hdr1[1 + sizeof (struct hdr_ext) - sizeof (HDRR)] = {0};
535 static check_hdr2[1 + sizeof (HDRR) - sizeof (struct hdr_ext)] = {0};
536 static check_fdr1[1 + sizeof (struct fdr_ext) - sizeof (FDR)] = {0};
537 static check_fdr2[1 + sizeof (FDR) - sizeof (struct fdr_ext)] = {0};
538 static check_pdr1[1 + sizeof (struct pdr_ext) - sizeof (PDR)] = {0};
539 static check_pdr2[1 + sizeof (PDR) - sizeof (struct pdr_ext)] = {0};
540 static check_sym1[1 + sizeof (struct sym_ext) - sizeof (SYMR)] = {0};
541 static check_sym2[1 + sizeof (SYMR) - sizeof (struct sym_ext)] = {0};
542 static check_ext1[1 + sizeof (struct ext_ext) - sizeof (EXTR)] = {0};
543 static check_ext2[1 + sizeof (EXTR) - sizeof (struct ext_ext)] = {0};
544 static check_rfd1[1 + sizeof (struct rfd_ext) - sizeof (RFDT)] = {0};
545 static check_rfd2[1 + sizeof (RFDT) - sizeof (struct rfd_ext)] = {0};
547 /* Swap in the header record. */
548 ecoff_swap_hdr_in (abfd, hdr, hdr);
551 * These fields are useless (and empty) by now:
552 * hdr->cbDnOffset, hdr->cbOptOffset
553 * We use them for other internal purposes.
556 hdr->cbOptOffset = 0;
559 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
573 /* Fix all the RFD's. */
574 rbase = (struct rfd_ext *)(hdr->cbRfdOffset);
575 for (i = 0; i < hdr->crfd; i++) {
576 ecoff_swap_rfd_in (abfd, rbase+i, (pRFDT) rbase+i);
579 /* Fix all string pointers inside the symtab, and
580 the FDR records. Also fix other miscellany. */
582 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
583 register unsigned code_offset;
585 /* Header itself, and strings */
586 fh = (FDR *) (hdr->cbFdOffset) + f_idx;
588 /* Swap in the FDR */
589 ecoff_swap_fdr_in (abfd, fh, fh);
591 fh->issBase += hdr->cbSsOffset;
593 fh->rss = (long)fh->rss + fh->issBase;
596 fh->isymBase = (int)((SYMR*)(hdr->cbSymOffset)+fh->isymBase);
598 /* FIXME! Probably don't want to do this here! */
599 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
600 sh = (SYMR*)fh->isymBase + s_idx;
601 ecoff_swap_sym_in (abfd, sh, sh);
603 sh->iss = (long) sh->iss + fh->issBase;
609 /* cannot fix fh->ipdFirst because it is a short */
610 #define IPDFIRST(h,fh) \
611 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
613 /* Optional symbols (actually used for partial_symtabs) */
619 fh->iauxBase = hdr->cbAuxOffset + fh->iauxBase * sizeof(union aux_ext);
620 /* Relative file descriptor table */
621 fh->rfdBase = hdr->cbRfdOffset + fh->rfdBase * sizeof(RFDT);
625 fh->cbLineOffset += hdr->cbLineOffset;
627 /* Procedure symbols. (XXX This should be done later) */
628 code_offset = fh->adr;
629 for (s_idx = 0; s_idx < fh->cpd; s_idx++) {
630 unsigned name, only_ext;
632 pr = (PDR*)(IPDFIRST(hdr,fh)) + s_idx;
633 ecoff_swap_pdr_in (abfd, pr, pr);
635 /* Simple rule to find files linked "-x" */
636 only_ext = fh->rss == -1;
638 if (pr->isym == -1) {
639 /* static function */
643 name = hdr->cbExtOffset + pr->isym * sizeof(EXTR);
644 sh = &((EXTR*)name)->asym;
648 sh = (SYMR*)fh->isymBase + pr->isym;
649 /* Included code ? */
650 if (s_idx == 0 && pr->adr != 0)
651 code_offset -= pr->adr;
654 /* Turn index into a pointer */
657 /* Fix line numbers */
658 pr->cbLineOffset += fh->cbLineOffset;
660 /* Relocate address */
662 pr->adr += code_offset;
666 /* External symbols: swap in, and fix string */
667 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
668 esh = (EXTR*)(hdr->cbExtOffset) + s_idx;
669 ecoff_swap_ext_in (abfd, esh, esh);
670 esh->asym.iss = esh->asym.iss + hdr->cbSsExtOffset;
675 /* Find a file descriptor given its index RF relative to a file CF */
683 f = (FDR *) (cur_hdr->cbFdOffset) + cf;
684 /* Object files do not have the RFD table, all refs are absolute */
686 return (FDR *) (cur_hdr->cbFdOffset) + rf;
687 cf = *((pRFDT) f->rfdBase + rf);
688 return (FDR *) (cur_hdr->cbFdOffset) + cf;
691 /* Return a safer print NAME for a file descriptor */
697 if (name == (char *) -1)
698 return "<stripped file>";
699 if (UNSAFE_DATA_ADDR(name))
705 /* Read in and parse the symtab of the file OBJFILE. Symbols from
706 different sections are relocated via the SECTION_OFFSETS. */
709 read_mips_symtab (objfile, section_offsets)
710 struct objfile *objfile;
711 struct section_offsets *section_offsets;
713 CORE_ADDR end_of_text_seg;
715 read_the_mips_symtab(objfile->obfd, &end_of_text_seg);
717 parse_partial_symbols(end_of_text_seg, objfile, section_offsets);
721 * Check to make sure file was compiled with -g.
722 * If not, warn the user of this limitation.
724 if (compare_glevel(max_glevel, GLEVEL_2) < 0) {
725 if (max_gdbinfo == 0)
727 "\n%s not compiled with -g, debugging support is limited.\n",
730 "You should compile with -g2 or -g3 for best debugging support.\n");
736 /* Local utilities */
738 /* Map of FDR indexes to partial symtabs */
741 struct partial_symtab *pst; /* the psymtab proper */
742 int n_globals; /* exported globals (external symbols) */
743 int globals_offset; /* cumulative */
747 /* Utility stack, used to nest procedures and blocks properly.
748 It is a doubly linked list, to avoid too many alloc/free.
749 Since we might need it quite a few times it is NOT deallocated
752 static struct parse_stack {
753 struct parse_stack *next, *prev;
754 struct symtab *cur_st; /* Current symtab. */
755 struct block *cur_block; /* Block in it. */
756 int blocktype; /* What are we parsing. */
757 int maxsyms; /* Max symbols in this block. */
758 struct type *cur_type; /* Type we parse fields for. */
759 int cur_field; /* Field number in cur_type. */
760 int procadr; /* Start addres of this procedure */
761 int numargs; /* Its argument count */
762 } *top_stack; /* Top stack ptr */
765 /* Enter a new lexical context */
770 struct parse_stack *new;
772 /* Reuse frames if possible */
773 if (top_stack && top_stack->prev)
774 new = top_stack->prev;
776 new = (struct parse_stack *) xzalloc(sizeof(struct parse_stack));
777 /* Initialize new frame with previous content */
779 register struct parse_stack *prev = new->prev;
782 top_stack->prev = new;
784 new->next = top_stack;
789 /* Exit a lexical context */
797 top_stack = top_stack->next;
801 /* Cross-references might be to things we haven't looked at
802 yet, e.g. type references. To avoid too many type
803 duplications we keep a quick fixup table, an array
804 of lists of references indexed by file descriptor */
806 static struct mips_pending {
807 struct mips_pending *next; /* link */
808 SYMR *s; /* the symbol */
809 struct type *t; /* its partial type descriptor */
813 /* Check whether we already saw symbol SH in file FH as undefined */
815 static struct mips_pending *
816 is_pending_symbol(fh, sh)
820 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
821 register struct mips_pending *p;
823 /* Linear search is ok, list is typically no more than 10 deep */
824 for (p = pending_list[f_idx]; p; p = p->next)
830 /* Add a new undef symbol SH of type T */
833 add_pending(fh, sh, t)
838 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
839 struct mips_pending *p = is_pending_symbol(fh, sh);
841 /* Make sure we do not make duplicates */
843 p = (struct mips_pending *) xmalloc(sizeof(*p));
846 p->next = pending_list[f_idx];
847 pending_list[f_idx] = p;
849 sh->reserved = 1; /* for quick check */
852 /* Throw away undef entries when done with file index F_IDX */
853 /* FIXME -- storage leak. This is never called!!! --gnu */
861 register struct mips_pending *p, *q;
863 for (p = pending_list[f_idx]; p; p = q) {
867 pending_list[f_idx] = 0;
873 prepend_tag_kind(tag_name, type_code)
875 enum type_code type_code;
883 case TYPE_CODE_STRUCT:
886 case TYPE_CODE_UNION:
893 result = (char*)obstack_alloc (¤t_objfile->symbol_obstack,
894 strlen(prefix) + strlen(tag_name) + 1);
895 sprintf(result, "%s%s", prefix, tag_name);
900 /* Parsing Routines proper. */
902 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
903 For blocks, procedures and types we open a new lexical context.
904 This is basically just a big switch on the symbol's type.
905 Argument AX is the base pointer of aux symbols for this file (fh->iauxBase).
906 BIGEND says whether aux symbols are big-endian or little-endian.
907 Return count of SYMR's handled (normally one). */
910 parse_symbol(sh, ax, bigend)
921 /* When a symbol is cross-referenced from other files/symbols
922 we mark it explicitly */
923 int pend = (sh->reserved == 1);
924 enum address_class class;
932 case stGlobal: /* external symbol, goes into global block */
934 b = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
936 s = new_symbol((char *)sh->iss);
937 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
940 case stStatic: /* static data, goes into current block. */
942 b = top_stack->cur_block;
943 s = new_symbol((char *)sh->iss);
944 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
947 case stLocal: /* local variable, goes into current block */
948 if (sh->sc == scRegister) {
949 class = LOC_REGISTER;
951 sh->value += FP0_REGNUM-32;
954 b = top_stack->cur_block;
955 s = new_symbol((char *)sh->iss);
956 SYMBOL_VALUE(s) = sh->value;
958 data: /* Common code for symbols describing data */
959 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
960 SYMBOL_CLASS(s) = class;
963 /* Type could be missing in a number of cases */
964 if (sh->sc == scUndefined || sh->sc == scNil ||
965 sh->index == 0xfffff)
966 SYMBOL_TYPE(s) = builtin_type_int; /* undefined? */
968 SYMBOL_TYPE(s) = parse_type(ax + sh->index, 0, bigend);
969 /* Value of a data symbol is its memory address */
972 case stParam: /* arg to procedure, goes into current block */
974 top_stack->numargs++;
976 name = (char*)sh->iss;
977 /* Special GNU C++ name. */
978 if (name[0] == CPLUS_MARKER && name[1] == 't' && name[2] == 0)
979 name = "this"; /* FIXME, not alloc'd in obstack */
980 s = new_symbol(name);
982 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
983 if (sh->sc == scRegister) {
984 SYMBOL_CLASS(s) = LOC_REGPARM;
986 sh->value += FP0_REGNUM-32;
988 SYMBOL_CLASS(s) = LOC_ARG;
989 SYMBOL_VALUE(s) = sh->value;
990 SYMBOL_TYPE(s) = parse_type(ax + sh->index, 0, bigend);
991 add_symbol(s, top_stack->cur_block);
993 /* FIXME: This has not been tested. See dbxread.c */
994 /* Add the type of this parameter to the function/procedure
995 type of this block. */
996 add_param_to_type(&top_stack->cur_block->function->type,s);
1000 case stLabel: /* label, goes into current block */
1001 s = new_symbol((char *)sh->iss);
1002 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; /* so that it can be used */
1003 SYMBOL_CLASS(s) = LOC_LABEL; /* but not misused */
1004 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
1005 SYMBOL_TYPE(s) = builtin_type_int;
1006 add_symbol(s, top_stack->cur_block);
1009 case stProc: /* Procedure, usually goes into global block */
1010 case stStaticProc: /* Static procedure, goes into current block */
1011 s = new_symbol((char *)sh->iss);
1012 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1013 SYMBOL_CLASS(s) = LOC_BLOCK;
1014 /* Type of the return value */
1015 if (sh->sc == scUndefined || sh->sc == scNil)
1016 t = builtin_type_int;
1018 t = parse_type(ax + sh->index + 1, 0, bigend);
1019 b = top_stack->cur_block;
1020 if (sh->st == stProc) {
1021 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
1022 /* The next test should normally be true,
1023 but provides a hook for nested functions
1024 (which we don't want to make global). */
1025 if (b == BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK))
1026 b = BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK);
1030 /* Make a type for the procedure itself */
1032 /* FIXME: This has not been tested yet! See dbxread.c */
1033 /* Generate a template for the type of this function. The
1034 types of the arguments will be added as we read the symbol
1036 bcopy(SYMBOL_TYPE(s),lookup_function_type(t),sizeof(struct type));
1038 SYMBOL_TYPE(s) = lookup_function_type (t);
1041 /* Create and enter a new lexical context */
1042 b = new_block(top_stack->maxsyms);
1043 SYMBOL_BLOCK_VALUE(s) = b;
1044 BLOCK_FUNCTION(b) = s;
1045 BLOCK_START(b) = BLOCK_END(b) = sh->value;
1046 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1047 add_block(b, top_stack->cur_st);
1049 /* Not if we only have partial info */
1050 if (sh->sc == scUndefined || sh->sc == scNil)
1054 top_stack->cur_block = b;
1055 top_stack->blocktype = sh->st;
1056 top_stack->cur_type = SYMBOL_TYPE(s);
1057 top_stack->cur_field = -1;
1058 top_stack->procadr = sh->value;
1059 top_stack->numargs = 0;
1061 sh->value = (long) SYMBOL_TYPE(s);
1064 /* Beginning of code for structure, union, and enum definitions.
1065 They all share a common set of local variables, defined here. */
1067 enum type_code type_code;
1073 case stStruct: /* Start a block defining a struct type */
1074 type_code = TYPE_CODE_STRUCT;
1075 goto structured_common;
1077 case stUnion: /* Start a block defining a union type */
1078 type_code = TYPE_CODE_UNION;
1079 goto structured_common;
1081 case stEnum: /* Start a block defining an enum type */
1082 type_code = TYPE_CODE_ENUM;
1083 goto structured_common;
1085 case stBlock: /* Either a lexical block, or some type */
1086 if (sh->sc != scInfo)
1087 goto case_stBlock_code; /* Lexical block */
1089 type_code = TYPE_CODE_UNDEF; /* We have a type. */
1091 /* Common code for handling struct, union, enum, and/or as-yet-
1092 unknown-type blocks of info about structured data. `type_code'
1093 has been set to the proper TYPE_CODE, if we know it. */
1096 top_stack->blocktype = stBlock;
1098 s = new_symbol((char *)sh->iss);
1099 SYMBOL_NAMESPACE(s) = STRUCT_NAMESPACE;
1100 SYMBOL_CLASS(s) = LOC_TYPEDEF;
1101 SYMBOL_VALUE(s) = 0;
1102 add_symbol(s, top_stack->cur_block);
1104 /* First count the number of fields and the highest value. */
1107 for (tsym = sh+1; tsym->st != stEnd; tsym++)
1109 if (tsym->st == stMember) {
1110 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
1111 /* If the type of the member is Nil (or Void),
1112 without qualifiers, assume the tag is an
1114 if (tsym->index == indexNil)
1115 type_code = TYPE_CODE_ENUM;
1117 ecoff_swap_tir_in (bigend,
1118 &ax[tsym->index].a_ti,
1120 if ((tir.bt == btNil || tir.bt == btVoid)
1121 && tir.tq0 == tqNil)
1122 type_code = TYPE_CODE_ENUM;
1125 if (tsym->value > max_value)
1126 max_value = tsym->value;
1128 else if (tsym->st == stBlock
1129 || tsym->st == stUnion
1130 || tsym->st == stEnum
1131 || tsym->st == stStruct
1132 || tsym->st == stParsed) {
1133 if (tsym->sc == scVariant) ; /*UNIMPLEMENTED*/
1134 if (tsym->index != 0)
1135 tsym = ((SYMR*)cur_fdr->isymBase)
1138 else complain (&block_member_complaint, (char *)tsym->st);
1141 /* In an stBlock, there is no way to distinguish structs,
1142 unions, and enums at this point. This is a bug in the
1143 original design (that has been fixed with the
1144 recent addition of the stStruct, stUnion, and stEnum
1145 symbol types.) The way you can tell is if/when you
1146 see a variable or field of that type. In that case
1147 the variable's type (in the AUX table) says if the
1148 type is struct, union, or enum,
1149 and points back to the stBlock here.
1150 So you can patch the tag kind up later - but only
1151 if there actually is a variable or field of that type.
1153 So until we know for sure, we will guess at this point.
1155 If the first member has index==indexNil or a void type,
1156 assume we have an enumeration.
1157 Otherwise, if there is more than one member, and all
1158 the members have offset 0, assume we have a union.
1159 Otherwise, assume we have a struct.
1161 The heuristic could guess wrong in the case of
1162 of an enumeration with no members or a union
1163 with one (or zero) members, or when all except the
1164 last field of a struct have width zero.
1165 These are uncommon and/or illegal situations, and
1166 in any case guessing wrong probably doesn't matter much.
1168 But if we later do find out we were wrong,
1169 we fixup the tag kind. Members of an enumeration
1170 must be handled differently from struct/union fields,
1171 and that is harder to patch up, but luckily we
1172 shouldn't need to. (If there are any enumeration
1173 members, we can tell for sure it's an enum here.) */
1175 if (type_code == TYPE_CODE_UNDEF)
1176 if (nfields > 1 && max_value == 0)
1177 type_code = TYPE_CODE_UNION;
1179 type_code = TYPE_CODE_STRUCT;
1181 /* If this type was expected, use its partial definition */
1183 t = is_pending_symbol(cur_fdr, sh)->t;
1185 t = new_type(prepend_tag_kind((char *)sh->iss,
1188 TYPE_CODE(t) = type_code;
1189 TYPE_LENGTH(t) = sh->value;
1190 TYPE_NFIELDS(t) = nfields;
1191 TYPE_FIELDS(t) = f = (struct field*)
1192 TYPE_ALLOC (t, nfields * sizeof (struct field));
1194 if (type_code == TYPE_CODE_ENUM) {
1195 /* This is a non-empty enum. */
1196 for (tsym = sh + 1; tsym->st == stMember; tsym++) {
1197 struct symbol *enum_sym;
1198 f->bitpos = tsym->value;
1200 f->name = (char*)tsym->iss;
1203 enum_sym = (struct symbol *)
1204 obstack_alloc (¤t_objfile->symbol_obstack,
1205 sizeof (struct symbol));
1206 memset ((PTR)enum_sym, 0, sizeof (struct symbol));
1207 SYMBOL_NAME (enum_sym) = f->name;
1208 SYMBOL_CLASS (enum_sym) = LOC_CONST;
1209 SYMBOL_TYPE (enum_sym) = t;
1210 SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
1211 SYMBOL_VALUE (enum_sym) = tsym->value;
1212 add_symbol(enum_sym, top_stack->cur_block);
1214 /* Skip the stMembers that we've handled. */
1220 /* make this the current type */
1221 top_stack->cur_type = t;
1222 top_stack->cur_field = 0;
1223 /* Mark that symbol has a type, and say which one */
1224 sh->value = (long) t;
1227 /* End of local variables shared by struct, union, enum, and
1228 block (as yet unknown struct/union/enum) processing. */
1232 /* beginnning of (code) block. Value of symbol
1233 is the displacement from procedure start */
1235 top_stack->blocktype = stBlock;
1236 b = new_block(top_stack->maxsyms);
1237 BLOCK_START(b) = sh->value + top_stack->procadr;
1238 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1239 top_stack->cur_block = b;
1240 add_block(b, top_stack->cur_st);
1243 case stEnd: /* end (of anything) */
1244 if (sh->sc == scInfo) {
1245 /* Finished with type */
1246 top_stack->cur_type = 0;
1247 } else if (sh->sc == scText &&
1248 (top_stack->blocktype == stProc ||
1249 top_stack->blocktype == stStaticProc)) {
1250 /* Finished with procedure */
1251 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
1252 struct mips_extra_func_info *e;
1256 BLOCK_END(top_stack->cur_block) += sh->value; /* size */
1258 /* Make up special symbol to contain procedure specific
1260 s = new_symbol(MIPS_EFI_SYMBOL_NAME);
1261 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
1262 SYMBOL_CLASS(s) = LOC_CONST;
1263 SYMBOL_TYPE(s) = builtin_type_void;
1264 e = (struct mips_extra_func_info *)
1265 obstack_alloc (¤t_objfile->symbol_obstack,
1266 sizeof (struct mips_extra_func_info));
1267 SYMBOL_VALUE(s) = (int)e;
1268 e->numargs = top_stack->numargs;
1269 add_symbol(s, top_stack->cur_block);
1271 /* Reallocate symbols, saving memory */
1272 b = shrink_block(top_stack->cur_block, top_stack->cur_st);
1274 /* f77 emits proc-level with address bounds==[0,0],
1275 So look for such child blocks, and patch them. */
1276 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) {
1277 struct block *b_bad = BLOCKVECTOR_BLOCK(bv,i);
1278 if (BLOCK_SUPERBLOCK(b_bad) == b
1279 && BLOCK_START(b_bad) == top_stack->procadr
1280 && BLOCK_END(b_bad) == top_stack->procadr) {
1281 BLOCK_START(b_bad) = BLOCK_START(b);
1282 BLOCK_END(b_bad) = BLOCK_END(b);
1285 } else if (sh->sc == scText && top_stack->blocktype == stBlock) {
1286 /* End of (code) block. The value of the symbol
1287 is the displacement from the procedure`s start
1288 address of the end of this block. */
1289 BLOCK_END(top_stack->cur_block) = sh->value + top_stack->procadr;
1290 shrink_block(top_stack->cur_block, top_stack->cur_st);
1291 } else if (sh->sc == scText && top_stack->blocktype == stFile) {
1292 /* End of file. Pop parse stack and ignore. Higher
1293 level code deals with this. */
1295 } else complain (&stEnd_complaint, (char *)sh->sc);
1297 pop_parse_stack(); /* restore previous lexical context */
1300 case stMember: /* member of struct or union */
1301 f = &TYPE_FIELDS(top_stack->cur_type)[top_stack->cur_field++];
1302 f->name = (char*)sh->iss;
1303 f->bitpos = sh->value;
1305 f->type = parse_type(ax + sh->index, &f->bitsize, bigend);
1308 case stTypedef: /* type definition */
1309 s = new_symbol((char *)sh->iss);
1310 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1311 SYMBOL_CLASS(s) = LOC_TYPEDEF;
1312 SYMBOL_BLOCK_VALUE(s) = top_stack->cur_block;
1313 add_symbol(s, top_stack->cur_block);
1314 SYMBOL_TYPE(s) = parse_type(ax + sh->index, 0, bigend);
1315 sh->value = (long) SYMBOL_TYPE(s);
1318 case stFile: /* file name */
1320 top_stack->blocktype = sh->st;
1323 /* I`ve never seen these for C */
1325 break; /* register relocation */
1327 break; /* forwarding address */
1329 break; /* constant */
1331 complain(&unknown_mips_symtype_complaint, (char *)sh->st);
1338 /* Parse the type information provided in the raw AX entries for
1339 the symbol SH. Return the bitfield size in BS, in case.
1340 We must byte-swap the AX entries before we use them; BIGEND says whether
1341 they are big-endian or little-endian (from fh->fBigendian). */
1343 static struct type *
1344 parse_type(ax, bs, bigend)
1349 /* Null entries in this map are treated specially */
1350 static struct type **map_bt[] =
1352 &builtin_type_void, /* btNil */
1354 &builtin_type_char, /* btChar */
1355 &builtin_type_unsigned_char, /* btUChar */
1356 &builtin_type_short, /* btShort */
1357 &builtin_type_unsigned_short, /* btUShort */
1358 &builtin_type_int, /* btInt */
1359 &builtin_type_unsigned_int, /* btUInt */
1360 &builtin_type_long, /* btLong */
1361 &builtin_type_unsigned_long, /* btULong */
1362 &builtin_type_float, /* btFloat */
1363 &builtin_type_double, /* btDouble */
1370 &builtin_type_complex, /* btComplex */
1371 &builtin_type_double_complex, /* btDComplex */
1373 &builtin_type_fixed_dec, /* btFixedDec */
1374 &builtin_type_float_dec, /* btFloatDec */
1375 &builtin_type_string, /* btString */
1378 &builtin_type_void, /* btVoid */
1379 &builtin_type_long_long, /* btLongLong */
1380 &builtin_type_unsigned_long_long,/* btULongLong */
1384 struct type *tp = 0;
1387 enum type_code type_code;
1389 /* Use aux as a type information record, map its basic type. */
1391 ecoff_swap_tir_in (bigend, &tax->a_ti, t);
1392 if (t->bt > (sizeof (map_bt)/sizeof (*map_bt))) {
1393 complain (&basic_type_complaint, (char *)t->bt);
1394 return builtin_type_int;
1396 if (map_bt[t->bt]) {
1397 tp = *map_bt[t->bt];
1401 /* Cannot use builtin types -- build our own */
1404 tp = lookup_pointer_type (builtin_type_void);
1408 type_code = TYPE_CODE_STRUCT;
1412 type_code = TYPE_CODE_UNION;
1416 type_code = TYPE_CODE_ENUM;
1420 type_code = TYPE_CODE_RANGE;
1424 type_code = TYPE_CODE_SET;
1429 complain (&basic_type_complaint, (char *)t->bt);
1430 return builtin_type_int;
1434 /* Skip over any further type qualifiers (FIXME). */
1436 /* This is the way it would work if the compiler worked */
1440 ecoff_swap_tir_in (bigend, ax, t1);
1441 } while (t1->continued);
1444 /* Move on to next aux */
1448 *bs = AUX_GET_WIDTH (bigend, ax);
1452 /* All these types really point to some (common) MIPS type
1453 definition, and only the type-qualifiers fully identify
1454 them. We'll make the same effort at sharing. */
1455 if (t->bt == btIndirect ||
1456 t->bt == btStruct ||
1459 t->bt == btTypedef ||
1462 char name[256], *pn;
1464 /* Try to cross reference this type */
1465 ax += cross_ref(ax, &tp, type_code, &pn, bigend);
1466 /* reading .o file ? */
1467 if (UNSAFE_DATA_ADDR(tp))
1468 tp = init_type(type_code, 0, 0, (char *) NULL,
1469 (struct objfile *) NULL);
1470 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1471 sprintf(name, fmt, pn);
1473 /* Usually, TYPE_CODE(tp) is already type_code. The main
1474 exception is if we guessed wrong re struct/union/enum. */
1475 if (TYPE_CODE(tp) != type_code) {
1476 complain (&bad_tag_guess_complaint, name);
1477 TYPE_CODE(tp) = type_code;
1479 if (TYPE_NAME(tp) == NULL || strcmp(TYPE_NAME(tp), name) != 0)
1480 TYPE_NAME(tp) = obsavestring(name, strlen(name),
1481 ¤t_objfile -> type_obstack);
1484 /* Deal with range types */
1485 if (t->bt == btRange) {
1486 TYPE_NFIELDS (tp) = 2;
1487 TYPE_FIELDS (tp) = (struct field *)
1488 TYPE_ALLOC (tp, 2 * sizeof (struct field));
1489 TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
1490 ¤t_objfile -> type_obstack);
1491 TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
1493 TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
1494 ¤t_objfile -> type_obstack);
1495 TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
1499 /* Parse all the type qualifiers now. If there are more
1500 than 6 the game will continue in the next aux */
1502 #define PARSE_TQ(tq) \
1503 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1505 again: PARSE_TQ(tq0);
1515 ecoff_swap_tir_in (bigend, &tax->a_ti, t);
1521 /* Make up a complex type from a basic one. Type is passed by
1522 reference in TPP and side-effected as necessary. The type
1523 qualifier TQ says how to handle the aux symbols at AX for
1524 the symbol SX we are currently analyzing. BIGEND says whether
1525 aux symbols are big-endian or little-endian.
1526 Returns the number of aux symbols we parsed. */
1529 upgrade_type(tpp, tq, ax, bigend)
1538 /* Used in array processing */
1547 t = lookup_pointer_type (*tpp);
1552 t = lookup_function_type (*tpp);
1557 /* We should probably try to use create_array_type here. FIXME! */
1559 t = init_type(TYPE_CODE_ARRAY, 0, 0, (char *) NULL,
1560 (struct objfile *) NULL);
1561 TYPE_TARGET_TYPE(t) = *tpp;
1563 /* Determine and record the domain type (type of index) */
1564 ecoff_swap_rndx_in (bigend, ax, &rndx);
1569 rf = AUX_GET_ISYM (bigend, ax);
1572 fh = get_rfd(cur_fd, rf);
1574 /* Fields are kept in an array */
1575 /* FIXME - Memory leak! */
1576 if (TYPE_NFIELDS(t))
1577 TYPE_FIELDS(t) = (struct field*)
1578 xrealloc((PTR) TYPE_FIELDS(t),
1579 (TYPE_NFIELDS(t)+1) * sizeof(struct field));
1581 TYPE_FIELDS(t) = (struct field*)
1582 xzalloc(sizeof(struct field));
1583 f = &(TYPE_FIELD(t,TYPE_NFIELDS(t)));
1585 memset((PTR)f, 0, sizeof(struct field));
1587 /* XXX */ f->type = parse_type(id + (union aux_ext *)fh->iauxBase,
1588 &f->bitsize, bigend);
1591 lower = AUX_GET_DNLOW (bigend, ax);
1593 upper = AUX_GET_DNHIGH (bigend, ax);
1595 rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */
1597 /* Check whether supplied array element bit size matches
1598 the known size of the element type. If this complaint
1599 ends up not happening, we can remove this code. It's
1600 here because we aren't sure we understand this *&%&$
1602 id = TYPE_LENGTH(TYPE_TARGET_TYPE(t)) << 3; /* bitsize */
1604 /* Most likely an undefined type */
1606 TYPE_LENGTH(TYPE_TARGET_TYPE(t)) = id >> 3;
1609 complain (&array_bitsize_complaint, (char *)rf);
1611 TYPE_LENGTH(t) = (upper < 0) ? 0 :
1612 (upper - lower + 1) * (rf >> 3);
1617 /* Volatile -- currently ignored */
1621 /* Const -- currently ignored */
1625 complain (&unknown_type_qual_complaint, (char *)tq);
1631 /* Parse a procedure descriptor record PR. Note that the procedure
1632 is parsed _after_ the local symbols, now we just insert the extra
1633 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has already
1634 been placed in the procedure's main block. Note also that images that
1635 have been partially stripped (ld -x) have been deprived
1636 of local symbols, and we have to cope with them here.
1637 The procedure's code ends at BOUND */
1640 parse_procedure (pr, bound, have_stabs)
1645 struct symbol *s, *i;
1646 SYMR *sh = (SYMR*)pr->isym;
1648 struct mips_extra_func_info *e;
1651 /* Static procedure at address pr->adr. Sigh. */
1652 if (sh == (SYMR*)-1) {
1653 complain (&pdr_static_symbol_complaint, (char *)pr->adr);
1656 sh_name = (char*)sh->iss;
1658 s = lookup_symbol(sh_name, NULL, VAR_NAMESPACE, 0, NULL);
1660 s = mylookup_symbol(sh_name, top_stack->cur_block,
1661 VAR_NAMESPACE, LOC_BLOCK);
1664 b = SYMBOL_BLOCK_VALUE(s);
1666 complain (&pdr_for_nonsymbol_complaint, sh_name);
1670 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1671 s = new_symbol(sh_name);
1672 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1673 SYMBOL_CLASS(s) = LOC_BLOCK;
1674 /* Donno its type, hope int is ok */
1675 SYMBOL_TYPE(s) = lookup_function_type (builtin_type_int);
1676 add_symbol(s, top_stack->cur_block);
1677 /* Wont have symbols for this one */
1679 SYMBOL_BLOCK_VALUE(s) = b;
1680 BLOCK_FUNCTION(b) = s;
1681 BLOCK_START(b) = pr->adr;
1682 BLOCK_END(b) = bound;
1683 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1684 add_block(b, top_stack->cur_st);
1688 i = mylookup_symbol(MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, LOC_CONST);
1692 e = (struct mips_extra_func_info *)SYMBOL_VALUE(i);
1694 e->pdr.isym = (long)s;
1698 /* Parse the external symbol ES. Just call parse_symbol() after
1699 making sure we know where the aux are for it. For procedures,
1700 parsing of the PDRs has already provided all the needed
1701 information, we only parse them if SKIP_PROCEDURES is false,
1702 and only if this causes no symbol duplication.
1703 BIGEND says whether aux entries are big-endian or little-endian.
1705 This routine clobbers top_stack->cur_block and ->cur_st. */
1708 parse_external(es, skip_procedures, bigend)
1710 int skip_procedures;
1715 if (es->ifd != ifdNil) {
1717 cur_fdr = (FDR*)(cur_hdr->cbFdOffset) + cur_fd;
1718 ax = (union aux_ext *)cur_fdr->iauxBase;
1720 cur_fdr = (FDR*)(cur_hdr->cbFdOffset);
1724 /* Reading .o files */
1725 if (es->asym.sc == scUndefined || es->asym.sc == scNil) {
1727 switch (es->asym.st) {
1729 case stProc: what = "procedure"; n_undef_procs++; break;
1730 case stGlobal: what = "variable"; n_undef_vars++; break;
1731 case stLabel: what = "label"; n_undef_labels++; break;
1732 default : what = "symbol"; break;
1735 /* FIXME: Turn this into a complaint? */
1737 printf_filtered("Warning: %s `%s' is undefined (in %s)\n",
1738 what, es->asym.iss, fdr_name((char *)cur_fdr->rss));
1742 switch (es->asym.st) {
1744 /* If we have full symbols we do not need more */
1745 if (skip_procedures)
1747 if (mylookup_symbol ((char *)es->asym.iss, top_stack->cur_block,
1748 VAR_NAMESPACE, LOC_BLOCK))
1754 * Note that the case of a symbol with indexNil
1755 * must be handled anyways by parse_symbol().
1757 parse_symbol(&es->asym, ax, bigend);
1764 /* Parse the line number info for file descriptor FH into
1765 GDB's linetable LT. MIPS' encoding requires a little bit
1766 of magic to get things out. Note also that MIPS' line
1767 numbers can go back and forth, apparently we can live
1768 with that and do not need to reorder our linetables */
1773 struct linetable *lt;
1775 unsigned char *base = (unsigned char*)fh->cbLineOffset;
1777 int delta, count, lineno = 0;
1783 /* Scan by procedure descriptors */
1785 for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) {
1788 /* No code for this one */
1789 if (pr->iline == ilineNil ||
1790 pr->lnLow == -1 || pr->lnHigh == -1)
1793 * Aurgh! To know where to stop expanding we
1796 for (l = 1; l < (fh->cpd - j); l++)
1797 if (pr[l].iline != -1)
1799 if (l == (fh->cpd - j))
1804 * When procedures are moved around the linenumbers
1805 * are attributed to the next procedure up
1807 if (pr->iline >= halt) continue;
1809 base = (unsigned char*)pr->cbLineOffset;
1810 l = pr->adr >> 2; /* in words */
1811 halt += (pr->adr >> 2) - pr->iline;
1812 for (lineno = pr->lnLow; l < halt;) {
1813 count = *base & 0x0f;
1814 delta = *base++ >> 4;
1818 delta = (base[0] << 8) | base[1];
1819 if (delta >= 0x8000)
1823 lineno += delta;/* first delta is 0 */
1824 k = add_line(lt, lineno, l, k);
1830 /* Master parsing procedure for first-pass reading of file symbols
1831 into a partial_symtab.
1833 Parses the symtab described by the global symbolic header CUR_HDR.
1834 END_OF_TEXT_SEG gives the address just after the text segment for
1835 the symtab we are reading. */
1838 parse_partial_symbols (end_of_text_seg, objfile, section_offsets)
1839 int end_of_text_seg;
1840 struct objfile *objfile;
1841 struct section_offsets *section_offsets;
1844 HDRR *hdr = cur_hdr;
1845 /* Running pointers */
1849 struct partial_symtab *pst;
1851 int past_first_source_file = 0;
1853 /* List of current psymtab's include files */
1854 char **psymtab_include_list;
1855 int includes_allocated;
1858 struct pst_map * fdr_to_pst;
1859 /* Index within current psymtab dependency list */
1860 struct partial_symtab **dependency_list;
1861 int dependencies_used, dependencies_allocated;
1862 struct cleanup *old_chain;
1864 extern_tab = (EXTR**)obstack_alloc (&objfile->psymbol_obstack,
1865 sizeof(EXTR *) * hdr->iextMax);
1867 includes_allocated = 30;
1869 psymtab_include_list = (char **) alloca (includes_allocated *
1871 next_symbol_text_func = mips_next_symbol_text;
1873 dependencies_allocated = 30;
1874 dependencies_used = 0;
1876 (struct partial_symtab **) alloca (dependencies_allocated *
1877 sizeof (struct partial_symtab *));
1879 last_source_file = NULL;
1884 * Only parse the Local and External symbols, and the Relative FDR.
1885 * Fixup enough of the loader symtab to be able to use it.
1886 * Allocate space only for the file's portions we need to
1891 max_glevel = MIN_GLEVEL;
1893 /* Allocate the map FDR -> PST.
1894 Minor hack: -O3 images might claim some global data belongs
1895 to FDR -1. We`ll go along with that */
1896 fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
1897 old_chain = make_cleanup (free, fdr_to_pst);
1900 struct partial_symtab * pst = new_psymtab("", objfile);
1901 fdr_to_pst[-1].pst = pst;
1905 /* Pass 1 over external syms: Presize and partition the list */
1906 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1907 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1908 fdr_to_pst[esh->ifd].n_globals++;
1911 /* Pass 1.5 over files: partition out global symbol space */
1913 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {
1914 fdr_to_pst[f_idx].globals_offset = s_idx;
1915 s_idx += fdr_to_pst[f_idx].n_globals;
1916 fdr_to_pst[f_idx].n_globals = 0;
1919 /* Pass 2 over external syms: fill in external symbols */
1920 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1921 enum minimal_symbol_type ms_type = mst_text;
1922 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1924 extern_tab[fdr_to_pst[esh->ifd].globals_offset
1925 + fdr_to_pst[esh->ifd].n_globals++] = esh;
1927 if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)
1930 switch (esh->asym.st) {
1939 ms_type = mst_unknown;
1940 complain (&unknown_ext_complaint, (char *)esh->asym.iss);
1942 prim_record_minimal_symbol ((char *)esh->asym.iss,
1947 /* Pass 3 over files, over local syms: fill in static symbols */
1948 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1949 struct partial_symtab *save_pst;
1952 cur_fdr = fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
1954 if (fh->csym == 0) {
1955 fdr_to_pst[f_idx].pst = NULL;
1958 pst = start_psymtab_common (objfile, section_offsets, (char*)fh->rss,
1959 fh->cpd ? fh->adr : 0,
1960 objfile->global_psymbols.next,
1961 objfile->static_psymbols.next);
1962 pst->read_symtab_private = (char *)
1963 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
1966 /* Make everything point to everything. */
1967 FDR_IDX(pst) = f_idx;
1968 fdr_to_pst[f_idx].pst = pst;
1969 fh->ioptBase = (int)pst;
1971 CUR_HDR(pst) = cur_hdr;
1973 /* The way to turn this into a symtab is to call... */
1974 pst->read_symtab = mipscoff_psymtab_to_symtab;
1976 pst->texthigh = pst->textlow;
1978 /* For stabs-in-ecoff files, the second symbol must be @stab.
1979 This symbol is emitted by mips-tfile to signal
1980 that the current object file uses encapsulated stabs
1981 instead of mips ecoff for local symbols.
1982 (It is the second symbol because the first symbol is
1983 the stFile used to signal the start of a file). */
1985 && strcmp((char *)(((SYMR *)fh->isymBase)[1].iss),
1986 stabs_symbol) == 0) {
1987 processing_gcc_compilation = 2;
1988 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) {
1991 sh = cur_sdx + (SYMR *) fh->isymBase;
1992 type_code = MIPS_UNMARK_STAB(sh->index);
1993 if (!MIPS_IS_STAB(sh)) {
1994 if (sh->st == stProc || sh->st == stStaticProc) {
1995 long procaddr = sh->value;
1996 sh = AUX_GET_ISYM (fh->fBigendian,
1997 sh->index + (union aux_ext *)(fh->iauxBase))
1998 + (SYMR *) fh->isymBase - 1;
1999 if (sh->st == stEnd) {
2000 long high = procaddr + sh->value;
2001 if (high > pst->texthigh)
2002 pst->texthigh = high;
2007 #define SET_NAMESTRING() namestring = (char*)sh->iss
2008 #define CUR_SYMBOL_TYPE type_code
2009 #define CUR_SYMBOL_VALUE sh->value
2010 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
2012 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
2013 #define HANDLE_RBRAC(val) \
2014 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2015 #include "partial-stab.h"
2019 processing_gcc_compilation = 0;
2020 for (cur_sdx = 0; cur_sdx < fh->csym; ) {
2022 enum address_class class;
2023 sh = cur_sdx + (SYMR *) fh->isymBase;
2025 if (MIPS_IS_STAB(sh)) {
2030 if (sh->sc == scUndefined || sh->sc == scNil ||
2031 sh->index == 0xfffff) {
2032 /* FIXME, premature? */
2037 name = (char *)(sh->iss);
2044 case stProc: /* Asm labels apparently */
2045 case stStaticProc: /* Function */
2046 ADD_PSYMBOL_TO_LIST(name, strlen(name),
2047 VAR_NAMESPACE, LOC_BLOCK,
2048 objfile->static_psymbols, sh->value);
2049 /* Skip over procedure to next one. */
2050 if (sh->index >= hdr->iauxMax)
2052 /* Should not happen, but does when cross-compiling
2053 with the MIPS compiler. FIXME -- pull later. */
2054 complain (&index_complaint, name);
2055 new_sdx = cur_sdx+1; /* Don't skip at all */
2058 new_sdx = AUX_GET_ISYM (fh->fBigendian,
2059 sh->index + (union aux_ext *)fh->iauxBase);
2060 procaddr = sh->value;
2062 if (new_sdx <= cur_sdx)
2064 /* This should not happen either... FIXME. */
2065 complain (&aux_index_complaint, name);
2066 new_sdx = cur_sdx + 1; /* Don't skip backward */
2070 sh = cur_sdx + (SYMR *) fh->isymBase - 1;
2071 if (sh->st != stEnd)
2073 high = procaddr + sh->value;
2074 if (high > pst->texthigh)
2075 pst->texthigh = high;
2078 case stStatic: /* Variable */
2082 case stTypedef: /* Typedef */
2083 class = LOC_TYPEDEF;
2086 case stConstant: /* Constant decl */
2093 case stBlock: /* { }, str, un, enum*/
2094 if (sh->sc == scInfo) {
2095 ADD_PSYMBOL_TO_LIST(name, strlen(name),
2096 STRUCT_NAMESPACE, LOC_TYPEDEF,
2097 objfile->static_psymbols, sh->value);
2099 /* Skip over the block */
2100 cur_sdx = sh->index;
2103 case stFile: /* File headers */
2104 case stLabel: /* Labels */
2105 case stEnd: /* Ends of files */
2108 case stLocal: /* Local variables */
2109 /* Normally these are skipped because we skip over
2110 all blocks we see. However, these can occur
2111 as visible symbols in a .h file that contains code. */
2115 /* Both complaints are valid: one gives symbol name,
2116 the other the offending symbol type. */
2117 complain (&unknown_sym_complaint, (char *)sh->iss);
2118 complain (&unknown_st_complaint, (char *)sh->st);
2122 /* Use this gdb symbol */
2123 ADD_PSYMBOL_TO_LIST(name, strlen(name),
2124 VAR_NAMESPACE, class,
2125 objfile->static_psymbols, sh->value);
2127 cur_sdx++; /* Go to next file symbol */
2130 /* Now do enter the external symbols. */
2131 ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
2132 cur_sdx = fdr_to_pst[f_idx].n_globals;
2133 PST_PRIVATE(save_pst)->extern_count = cur_sdx;
2134 PST_PRIVATE(save_pst)->extern_tab = ext_ptr;
2135 for (; --cur_sdx >= 0; ext_ptr++) {
2136 register struct partial_symbol *psym;
2137 enum address_class class;
2139 if ((*ext_ptr)->ifd != f_idx)
2141 sh = &(*ext_ptr)->asym;
2150 complain (&unknown_ext_complaint, (char *)sh->iss);
2151 /* Fall through, pretend it's global. */
2156 if (objfile->global_psymbols.next >=
2157 objfile->global_psymbols.list + objfile->global_psymbols.size)
2158 extend_psymbol_list (&objfile->global_psymbols, objfile);
2159 psym = objfile->global_psymbols.next++;
2160 SYMBOL_NAME (psym) = (char*)sh->iss;
2161 SYMBOL_NAMESPACE (psym) = VAR_NAMESPACE;
2162 SYMBOL_CLASS (psym) = class;
2163 SYMBOL_VALUE_ADDRESS (psym) = (CORE_ADDR)sh->value;
2167 end_psymtab (save_pst, psymtab_include_list, includes_used,
2168 -1, save_pst->texthigh,
2169 dependency_list, dependencies_used);
2170 if (objfile -> ei.entry_point >= save_pst->textlow &&
2171 objfile -> ei.entry_point < save_pst->texthigh)
2173 objfile -> ei.entry_file_lowpc = save_pst->textlow;
2174 objfile -> ei.entry_file_highpc = save_pst->texthigh;
2178 /* Mark the last code address, and remember it for later */
2179 hdr->cbDnOffset = end_of_text_seg;
2181 /* Now scan the FDRs for dependencies */
2182 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
2184 fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
2185 pst = fdr_to_pst[f_idx].pst;
2187 /* This should catch stabs-in-ecoff. */
2191 if (fh->cpd == 0) { /* If there are no functions defined here ... */
2192 /* ...then presumably a .h file: drop reverse depends .h->.c */
2193 for (; s_id0 < fh->crfd; s_id0++) {
2194 RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
2196 s_id0++; /* Skip self-dependency */
2201 pst->number_of_dependencies = fh->crfd - s_id0;
2202 pst->dependencies = (struct partial_symtab **)
2203 obstack_alloc (&objfile->psymbol_obstack,
2204 pst->number_of_dependencies *
2205 sizeof (struct partial_symtab *));
2206 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
2207 RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
2208 if (*rh < 0 || *rh >= hdr->ifdMax)
2209 complain(&bad_file_number_complaint, (char *)*rh);
2211 pst->dependencies[s_idx-s_id0] = fdr_to_pst[*rh].pst;
2214 do_cleanups (old_chain);
2219 /* Do the initial analisys of the F_IDX-th file descriptor.
2220 Allocates a partial symtab for it, and builds the list
2221 of dependent files by recursion. LEV says at which level
2222 of recursion we are called (to pretty up debug traces) */
2224 static struct partial_symtab *
2225 parse_fdr(f_idx, lev, objfile)
2228 struct objfile *objfile;
2231 register struct partial_symtab *pst;
2234 fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx;
2236 /* Use this to indicate into which symtab this file was parsed */
2238 return (struct partial_symtab *) fh->ioptBase;
2240 /* Debuggability level */
2241 if (compare_glevel(max_glevel, fh->glevel) < 0)
2242 max_glevel = fh->glevel;
2244 /* Make a new partial_symtab */
2245 pst = new_psymtab(fh->rss, objfile);
2250 pst->textlow = fh->adr;
2251 pst->texthigh = fh->cpd; /* To be fixed later */
2254 /* Make everything point to everything. */
2255 FDR_IDX(pst) = f_idx;
2256 fdr_to_pst[f_idx].pst = pst;
2257 fh->ioptBase = (int)pst;
2259 /* Analyze its dependencies */
2264 if (fh->cpd == 0) { /* If there are no functions defined here ... */
2265 /* ...then presumably a .h file: drop reverse depends .h->.c */
2266 for (; s_id0 < fh->crfd; s_id0++) {
2267 RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
2269 s_id0++; /* Skip self-dependency */
2274 pst->number_of_dependencies = fh->crfd - s_id0;
2275 pst->dependencies = (struct partial_symtab **)
2276 obstack_alloc (&objfile->psymbol_obstack,
2277 pst->number_of_dependencies *
2278 sizeof (struct partial_symtab *));
2279 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
2280 RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
2282 pst->dependencies[s_idx-s_id0] = parse_fdr(*rh, lev+1, objfile);
2290 mips_next_symbol_text ()
2293 return (char*)((SYMR *)cur_fdr->isymBase)[cur_sdx].iss;
2296 /* Ancillary function to psymtab_to_symtab(). Does all the work
2297 for turning the partial symtab PST into a symtab, recurring
2298 first on all dependent psymtabs. The argument FILENAME is
2299 only passed so we can see in debug stack traces what file
2302 This function has a split personality, based on whether the
2303 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
2304 The flow of control and even the memory allocation differs. FIXME. */
2307 psymtab_to_symtab_1(pst, filename)
2308 struct partial_symtab *pst;
2314 struct linetable *lines;
2321 /* Read in all partial symbtabs on which this one is dependent.
2322 NOTE that we do have circular dependencies, sigh. We solved
2323 that by setting pst->readin before this point. */
2325 for (i = 0; i < pst->number_of_dependencies; i++)
2326 if (!pst->dependencies[i]->readin) {
2327 /* Inform about additional files to be read in. */
2330 fputs_filtered (" ", stdout);
2332 fputs_filtered ("and ", stdout);
2334 printf_filtered ("%s...",
2335 pst->dependencies[i]->filename);
2336 wrap_here (""); /* Flush output */
2339 /* We only pass the filename for debug purposes */
2340 psymtab_to_symtab_1(pst->dependencies[i],
2341 pst->dependencies[i]->filename);
2344 /* Now read the symbols for this symtab */
2346 current_objfile = pst->objfile;
2347 cur_fd = FDR_IDX(pst);
2348 fh = (cur_fd == -1) ? 0 : (FDR *) (cur_hdr->cbFdOffset) + FDR_IDX(pst);
2351 /* BOUND is the highest core address of this file's procedures */
2352 bound = (cur_fd == cur_hdr->ifdMax - 1) ?
2353 cur_hdr->cbDnOffset :
2356 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2357 if (fh && fh->csym >= 2
2358 && strcmp((char *)(((SYMR *)fh->isymBase)[1].iss), stabs_symbol)
2362 * This symbol table contains stabs-in-ecoff entries.
2367 /* We indicate that this is a GCC compilation so that certain features
2368 will be enabled in stabsread/dbxread. */
2369 processing_gcc_compilation = 2;
2370 /* Parse local symbols first */
2372 if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr */
2374 current_objfile = NULL;
2377 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) {
2378 register SYMR *sh = cur_sdx + (SYMR *) fh->isymBase;
2379 char *name = (char*)sh->iss;
2380 CORE_ADDR valu = sh->value;
2381 if (MIPS_IS_STAB(sh)) {
2382 int type_code = MIPS_UNMARK_STAB(sh->index);
2383 process_one_symbol (type_code, 0, valu, name,
2384 pst->section_offsets, pst->objfile);
2385 if (type_code == N_FUN) {
2386 /* Make up special symbol to contain
2387 procedure specific info */
2388 struct mips_extra_func_info *e =
2389 (struct mips_extra_func_info *)
2390 obstack_alloc(¤t_objfile->symbol_obstack,
2391 sizeof(struct mips_extra_func_info));
2392 struct symbol *s = new_symbol(MIPS_EFI_SYMBOL_NAME);
2393 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
2394 SYMBOL_CLASS(s) = LOC_CONST;
2395 SYMBOL_TYPE(s) = builtin_type_void;
2396 SYMBOL_VALUE(s) = (int)e;
2397 add_symbol_to_list (s, &local_symbols);
2400 else if (sh->st == stLabel && sh->index != indexNil) {
2401 /* Handle encoded stab line number. */
2402 record_line (current_subfile, sh->index, valu);
2404 else complain (&stab_unknown_complaint, (char *)sh->iss);
2406 st = end_symtab (pst->texthigh, 0, 0, pst->objfile);
2409 /* Sort the symbol table now, we are done adding symbols to it.
2410 We must do this before parse_procedure calls lookup_symbol. */
2411 sort_symtab_syms(st);
2413 /* This may not be necessary for stabs symtabs. FIXME. */
2416 /* Fill in procedure info next. We need to look-ahead to
2417 find out where each procedure's code ends. */
2419 for (i = 0; i <= fh->cpd-1; i++) {
2420 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + i;
2421 parse_procedure (pr, i < fh->cpd-1 ? pr[1].adr : bound, 1);
2426 * This symbol table contains ordinary ecoff entries.
2429 /* FIXME: doesn't use pst->section_offsets. */
2435 processing_gcc_compilation = 0;
2437 /* How many symbols will we need */
2438 /* FIXME, this does not count enum values. */
2439 f_max = pst->n_global_syms + pst->n_static_syms;
2442 st = new_symtab ("unknown", f_max, 0, pst->objfile);
2444 f_max += fh->csym + fh->cpd;
2445 maxlines = 2 * fh->cline;
2446 st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
2449 lines = LINETABLE(st);
2450 pending_list = (struct mips_pending **) cur_hdr->cbOptOffset;
2451 if (pending_list == 0) {
2452 pending_list = (struct mips_pending **)
2453 xzalloc(cur_hdr->ifdMax * sizeof(struct mips_pending *));
2454 cur_hdr->cbOptOffset = (int)pending_list;
2457 /* Get a new lexical context */
2460 top_stack->cur_st = st;
2461 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(st),
2463 BLOCK_START(top_stack->cur_block) = fh ? fh->adr : 0;
2464 BLOCK_END(top_stack->cur_block) = 0;
2465 top_stack->blocktype = stFile;
2466 top_stack->maxsyms = 2*f_max;
2467 top_stack->cur_type = 0;
2468 top_stack->procadr = 0;
2469 top_stack->numargs = 0;
2475 /* Parse local symbols first */
2477 for (cur_sdx = 0; cur_sdx < fh->csym; ) {
2478 sh = (SYMR *) (fh->isymBase) + cur_sdx;
2479 cur_sdx += parse_symbol(sh, (union aux_ext *)fh->iauxBase,
2483 /* Linenumbers. At the end, check if we can save memory */
2485 parse_lines(fh, lines);
2486 if (lines->nitems < fh->cline)
2487 lines = shrink_linetable(lines);
2489 /* Fill in procedure info next. We need to look-ahead to
2490 find out where each procedure's code ends. */
2492 for (i = 0; i <= fh->cpd-1; i++) {
2493 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + i;
2494 parse_procedure(pr, i < fh->cpd-1 ? pr[1].adr : bound, 0);
2498 LINETABLE(st) = lines;
2500 /* .. and our share of externals.
2501 XXX use the global list to speed up things here. how?
2502 FIXME, Maybe quit once we have found the right number of ext's? */
2503 top_stack->cur_st = st;
2504 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
2506 top_stack->blocktype = stFile;
2507 top_stack->maxsyms =
2508 cur_hdr->isymMax + cur_hdr->ipdMax + cur_hdr->iextMax;
2510 ext_ptr = PST_PRIVATE(pst)->extern_tab;
2511 for (i = PST_PRIVATE(pst)->extern_count; --i >= 0; ext_ptr++)
2512 parse_external(*ext_ptr, 1, fh->fBigendian);
2514 /* If there are undefined, tell the user */
2515 if (n_undef_symbols) {
2516 printf_filtered("File %s contains %d unresolved references:",
2517 st->filename, n_undef_symbols);
2518 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2519 n_undef_vars, n_undef_procs, n_undef_labels);
2520 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
2525 /* Sort the symbol table now, we are done adding symbols to it.*/
2526 sort_symtab_syms(st);
2531 /* Now link the psymtab and the symtab. */
2534 current_objfile = NULL;
2537 /* Ancillary parsing procedures. */
2539 /* Lookup the type at relative index RN. Return it in TPP
2540 if found and in any event come up with its name PNAME.
2541 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2542 Return value says how many aux symbols we ate. */
2545 cross_ref(ax, tpp, type_code, pname, bigend)
2548 enum type_code type_code; /* Use to alloc new type if none is found. */
2556 ecoff_swap_rndx_in (bigend, ax, rn);
2558 /* Escape index means 'the next one' */
2559 if (rn->rfd == 0xfff) {
2561 rf = AUX_GET_ISYM (bigend, ax + 1);
2568 *pname = "<undefined>";
2571 * Find the relative file descriptor and the symbol in it
2573 FDR *fh = get_rfd(cur_fd, rf);
2578 * If we have processed this symbol then we left a forwarding
2579 * pointer to the corresponding GDB symbol. If not, we`ll put
2580 * it in a list of pending symbols, to be processed later when
2581 * the file f will be. In any event, we collect the name for
2582 * the type here. Which is why we made a first pass at
2585 sh = (SYMR *) (fh->isymBase) + rn->index;
2587 /* Careful, we might be looking at .o files */
2588 *pname = (UNSAFE_DATA_ADDR(sh->iss)) ? "<undefined>" :
2591 /* Have we parsed it ? */
2592 if ((!UNSAFE_DATA_ADDR(sh->value)) && (sh->st == stParsed)) {
2593 t = (struct type *) sh->value;
2596 /* Avoid duplicates */
2597 struct mips_pending *p = is_pending_symbol(fh, sh);
2601 *tpp = init_type(type_code, 0, 0, (char *) NULL,
2602 (struct objfile *) NULL);
2603 add_pending(fh, sh, *tpp);
2608 /* We used one auxent normally, two if we got a "next one" rf. */
2613 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2614 keeping the symtab sorted */
2616 static struct symbol *
2617 mylookup_symbol (name, block, namespace, class)
2619 register struct block *block;
2620 enum namespace namespace;
2621 enum address_class class;
2623 register int bot, top, inc;
2624 register struct symbol *sym;
2627 top = BLOCK_NSYMS(block);
2630 sym = BLOCK_SYM(block, bot);
2631 if (SYMBOL_NAME(sym)[0] == inc
2632 && SYMBOL_NAMESPACE(sym) == namespace
2633 && SYMBOL_CLASS(sym) == class
2634 && !strcmp(SYMBOL_NAME(sym), name))
2638 block = BLOCK_SUPERBLOCK (block);
2640 return mylookup_symbol (name, block, namespace, class);
2645 /* Add a new symbol S to a block B.
2646 Infrequently, we will need to reallocate the block to make it bigger.
2647 We only detect this case when adding to top_stack->cur_block, since
2648 that's the only time we know how big the block is. FIXME. */
2655 int nsyms = BLOCK_NSYMS(b)++;
2656 struct block *origb;
2657 struct parse_stack *stackp;
2659 if (b == top_stack->cur_block &&
2660 nsyms >= top_stack->maxsyms) {
2661 complain (&block_overflow_complaint, s->name);
2662 /* In this case shrink_block is actually grow_block, since
2663 BLOCK_NSYMS(b) is larger than its current size. */
2665 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
2667 /* Now run through the stack replacing pointers to the
2668 original block. shrink_block has already done this
2669 for the blockvector and BLOCK_FUNCTION. */
2670 for (stackp = top_stack; stackp; stackp = stackp->next) {
2671 if (stackp->cur_block == origb) {
2672 stackp->cur_block = b;
2673 stackp->maxsyms = BLOCK_NSYMS (b);
2677 BLOCK_SYM(b,nsyms) = s;
2680 /* Add a new block B to a symtab S */
2687 struct blockvector *bv = BLOCKVECTOR(s);
2689 bv = (struct blockvector *)xrealloc((PTR) bv,
2690 sizeof(struct blockvector) +
2691 BLOCKVECTOR_NBLOCKS(bv)
2692 * sizeof(bv->block));
2693 if (bv != BLOCKVECTOR(s))
2694 BLOCKVECTOR(s) = bv;
2696 BLOCKVECTOR_BLOCK(bv, BLOCKVECTOR_NBLOCKS(bv)++) = b;
2699 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2700 MIPS' linenumber encoding might need more than one byte
2701 to describe it, LAST is used to detect these continuation lines */
2704 add_line(lt, lineno, adr, last)
2705 struct linetable *lt;
2711 last = -2; /* make sure we record first line */
2713 if (last == lineno) /* skip continuation lines */
2716 lt->item[lt->nitems].line = lineno;
2717 lt->item[lt->nitems++].pc = adr << 2;
2721 /* Sorting and reordering procedures */
2723 /* Blocks with a smaller low bound should come first */
2726 compare_blocks(arg1, arg2)
2727 const void *arg1, *arg2;
2729 register int addr_diff;
2730 struct block **b1 = (struct block **) arg1;
2731 struct block **b2 = (struct block **) arg2;
2733 addr_diff = (BLOCK_START((*b1))) - (BLOCK_START((*b2)));
2735 return (BLOCK_END((*b1))) - (BLOCK_END((*b2)));
2739 /* Sort the blocks of a symtab S.
2740 Reorder the blocks in the blockvector by code-address,
2741 as required by some MI search routines */
2747 struct blockvector *bv = BLOCKVECTOR(s);
2749 if (BLOCKVECTOR_NBLOCKS(bv) <= 2) {
2751 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) == 0)
2752 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = 0;
2753 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) == 0)
2754 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = 0;
2758 * This is very unfortunate: normally all functions are compiled in
2759 * the order they are found, but if the file is compiled -O3 things
2760 * are very different. It would be nice to find a reliable test
2761 * to detect -O3 images in advance.
2763 if (BLOCKVECTOR_NBLOCKS(bv) > 3)
2764 qsort(&BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK),
2765 BLOCKVECTOR_NBLOCKS(bv) - FIRST_LOCAL_BLOCK,
2766 sizeof(struct block *),
2770 register CORE_ADDR high = 0;
2771 register int i, j = BLOCKVECTOR_NBLOCKS(bv);
2773 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
2774 if (high < BLOCK_END(BLOCKVECTOR_BLOCK(bv,i)))
2775 high = BLOCK_END(BLOCKVECTOR_BLOCK(bv,i));
2776 BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = high;
2779 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) =
2780 BLOCK_START(BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK));
2782 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2783 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2784 BLOCK_END (BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2785 BLOCK_END (BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2789 /* Constructor/restructor/destructor procedures */
2791 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2792 MAXSYMS and linenumbers MAXLINES we'll put in it */
2794 static struct symtab *
2795 new_symtab(name, maxsyms, maxlines, objfile)
2799 struct objfile *objfile;
2801 struct symtab *s = allocate_symtab (name, objfile);
2803 LINETABLE(s) = new_linetable(maxlines);
2805 /* All symtabs must have at least two blocks */
2806 BLOCKVECTOR(s) = new_bvect(2);
2807 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK) = new_block(maxsyms);
2808 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), STATIC_BLOCK) = new_block(maxsyms);
2809 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s),STATIC_BLOCK)) =
2810 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK);
2812 s->free_code = free_linetable;
2817 /* Allocate a new partial_symtab NAME */
2819 static struct partial_symtab *
2820 new_psymtab(name, objfile)
2822 struct objfile *objfile;
2824 struct partial_symtab *psymtab;
2826 /* FIXME -- why (char *) -1 rather than NULL? */
2827 psymtab = allocate_psymtab (name == (char *) -1 ? "<no name>" : name,
2830 /* Keep a backpointer to the file's symbols */
2832 psymtab -> read_symtab_private = (char *)
2833 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
2834 CUR_HDR(psymtab) = cur_hdr;
2836 /* The way to turn this into a symtab is to call... */
2837 psymtab->read_symtab = mipscoff_psymtab_to_symtab;
2842 /* Allocate a linetable array of the given SIZE. Since the struct
2843 already includes one item, we subtract one when calculating the
2844 proper size to allocate. */
2846 static struct linetable *
2850 struct linetable *l;
2852 size = (size-1) * sizeof(l->item) + sizeof(struct linetable);
2853 l = (struct linetable *)xmalloc(size);
2858 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2859 I am not so sure about the 3.4 ones.
2861 Since the struct linetable already includes one item, we subtract one when
2862 calculating the proper size to allocate. */
2864 static struct linetable *
2865 shrink_linetable(lt)
2866 struct linetable * lt;
2869 return (struct linetable *) xrealloc ((PTR)lt,
2870 sizeof(struct linetable)
2871 + (lt->nitems - 1) * sizeof(lt->item));
2874 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2876 static struct blockvector *
2880 struct blockvector *bv;
2883 size = sizeof(struct blockvector) + nblocks * sizeof(struct block*);
2884 bv = (struct blockvector *) xzalloc(size);
2886 BLOCKVECTOR_NBLOCKS(bv) = nblocks;
2891 /* Allocate and zero a new block of MAXSYMS symbols */
2893 static struct block *
2897 int size = sizeof(struct block) + (maxsyms-1) * sizeof(struct symbol *);
2899 return (struct block *)xzalloc (size);
2902 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2903 Shrink_block can also be used by add_symbol to grow a block. */
2905 static struct block *
2911 struct blockvector *bv = BLOCKVECTOR(s);
2914 /* Just reallocate it and fix references to the old one */
2916 new = (struct block *) xrealloc ((PTR)b, sizeof(struct block) +
2917 (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *));
2919 /* Should chase pointers to old one. Fortunately, that`s just
2920 the block`s function and inferior blocks */
2921 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b)
2922 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2923 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2924 if (BLOCKVECTOR_BLOCK(bv,i) == b)
2925 BLOCKVECTOR_BLOCK(bv,i) = new;
2926 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) == b)
2927 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) = new;
2931 /* Create a new symbol with printname NAME */
2933 static struct symbol *
2937 struct symbol *s = (struct symbol *)
2938 obstack_alloc (¤t_objfile->symbol_obstack, sizeof (struct symbol));
2940 memset ((PTR)s, 0, sizeof (*s));
2941 SYMBOL_NAME(s) = name;
2945 /* Create a new type with printname NAME */
2947 static struct type *
2953 t = alloc_type (current_objfile);
2954 TYPE_NAME(t) = name;
2955 TYPE_CPLUS_SPECIFIC(t) = (struct cplus_struct_type *)
2956 &cplus_struct_default;
2961 /* Things used for calling functions in the inferior.
2962 These functions are exported to our companion
2963 mips-tdep.c file and are here because they play
2964 with the symbol-table explicitly. */
2966 /* Sigtramp: make sure we have all the necessary information
2967 about the signal trampoline code. Since the official code
2968 from MIPS does not do so, we make up that information ourselves.
2969 If they fix the library (unlikely) this code will neutralize itself. */
2976 struct block *b, *b0;
2978 sigtramp_address = -1;
2980 /* We know it is sold as sigvec */
2981 s = lookup_symbol("sigvec", 0, VAR_NAMESPACE, 0, NULL);
2983 /* Most programs do not play with signals */
2985 s = lookup_symbol("_sigtramp", 0, VAR_NAMESPACE, 0, NULL);
2988 b0 = SYMBOL_BLOCK_VALUE(s);
2990 /* A label of sigvec, to be more precise */
2991 s = lookup_symbol("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
2994 /* But maybe this program uses its own version of sigvec */
2998 /* Did we or MIPSco fix the library ? */
2999 if (SYMBOL_CLASS(s) == LOC_BLOCK)
3001 sigtramp_address = BLOCK_START(SYMBOL_BLOCK_VALUE(s));
3002 sigtramp_end = BLOCK_END(SYMBOL_BLOCK_VALUE(s));
3006 sigtramp_address = SYMBOL_VALUE(s);
3007 sigtramp_end = sigtramp_address + 0x88; /* black magic */
3009 /* But what symtab does it live in ? */
3010 st = find_pc_symtab(SYMBOL_VALUE(s));
3013 * Ok, there goes the fix: turn it into a procedure, with all the
3014 * needed info. Note we make it a nested procedure of sigvec,
3015 * which is the way the (assembly) code is actually written.
3017 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
3018 SYMBOL_CLASS(s) = LOC_BLOCK;
3019 SYMBOL_TYPE(s) = init_type(TYPE_CODE_FUNC, 4, 0, (char *) NULL,
3020 (struct objfile *) NULL);
3021 TYPE_TARGET_TYPE(SYMBOL_TYPE(s)) = builtin_type_void;
3023 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
3025 SYMBOL_BLOCK_VALUE(s) = b;
3026 BLOCK_START(b) = sigtramp_address;
3027 BLOCK_END(b) = sigtramp_end;
3028 BLOCK_FUNCTION(b) = s;
3029 BLOCK_SUPERBLOCK(b) = BLOCK_SUPERBLOCK(b0);
3033 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
3035 struct mips_extra_func_info *e =
3036 (struct mips_extra_func_info *)
3037 xzalloc(sizeof(struct mips_extra_func_info));
3039 e->numargs = 0; /* the kernel thinks otherwise */
3040 /* align_longword(sigcontext + SIGFRAME) */
3041 e->pdr.frameoffset = 0x150;
3042 e->pdr.framereg = SP_REGNUM;
3044 e->pdr.regmask = -2;
3045 e->pdr.regoffset = -(41 * sizeof(int));
3046 e->pdr.fregmask = -1;
3047 e->pdr.fregoffset = -(37 * sizeof(int));
3048 e->pdr.isym = (long)s;
3050 current_objfile = st->objfile; /* Keep new_symbol happy */
3051 s = new_symbol(MIPS_EFI_SYMBOL_NAME);
3052 SYMBOL_VALUE(s) = (int) e;
3053 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
3054 SYMBOL_CLASS(s) = LOC_CONST;
3055 SYMBOL_TYPE(s) = builtin_type_void;
3056 current_objfile = NULL;
3059 BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s;
3063 /* Fake up identical offsets for all sections. */
3065 struct section_offsets *
3066 mipscoff_symfile_offsets (objfile, addr)
3067 struct objfile *objfile;
3070 struct section_offsets *section_offsets;
3073 section_offsets = (struct section_offsets *)
3074 obstack_alloc (&objfile -> psymbol_obstack,
3075 sizeof (struct section_offsets) +
3076 sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
3078 for (i = 0; i < SECT_OFF_MAX; i++)
3079 ANOFFSET (section_offsets, i) = addr;
3081 return section_offsets;
3084 /* Initialization */
3086 static struct sym_fns ecoff_sym_fns =
3088 "ecoff", /* sym_name: name or name prefix of BFD target type */
3089 5, /* sym_namelen: number of significant sym_name chars */
3090 mipscoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
3091 mipscoff_symfile_init,/* sym_init: read initial info, setup for sym_read() */
3092 mipscoff_symfile_read,/* sym_read: read a symbol file into symtab */
3093 mipscoff_symfile_finish,/* sym_finish: finished with file, cleanup */
3094 mipscoff_symfile_offsets,/* sym_offsets: dummy FIXME til implem sym reloc */
3095 NULL /* next: pointer to next struct sym_fns */
3100 _initialize_mipsread ()
3102 add_symtab_fns (&ecoff_sym_fns);
3104 /* Missing basic types */
3106 builtin_type_string =
3107 init_type(TYPE_CODE_PASCAL_ARRAY,
3108 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3110 (struct objfile *) NULL);
3111 builtin_type_complex =
3112 init_type(TYPE_CODE_FLT,
3113 TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
3115 (struct objfile *) NULL);
3116 builtin_type_double_complex =
3117 init_type(TYPE_CODE_FLT,
3118 TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
3119 0, "double complex",
3120 (struct objfile *) NULL);
3121 builtin_type_fixed_dec =
3122 init_type(TYPE_CODE_INT,
3123 TARGET_INT_BIT / TARGET_CHAR_BIT,
3125 (struct objfile *) NULL);
3126 builtin_type_float_dec =
3127 init_type(TYPE_CODE_FLT,
3128 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3129 0, "floating decimal",
3130 (struct objfile *) NULL);