- int f_max;
- int maxlines;
- EXTR *ext_ptr;
-
- /* How many symbols will we need */
- /* FIXME, this does not count enum values. */
- f_max = pst->n_global_syms + pst->n_static_syms;
- if (fh == 0)
- {
- maxlines = 0;
- st = new_symtab ("unknown", f_max, 0, pst->objfile);
- }
- else
- {
- f_max += fh->csym + fh->cpd;
- maxlines = 2 * fh->cline;
- st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
- }
-
- lines = LINETABLE (st);
- pending_list = PST_PRIVATE (pst)->pending_list;
- if (pending_list == 0)
- {
- pending_list = ((struct mips_pending **)
- xzalloc (ecoff_data (cur_bfd)->symbolic_header.ifdMax
- * sizeof (struct mips_pending *)));
- PST_PRIVATE (pst)->pending_list = pending_list;
- }
-
- /* Get a new lexical context */
-
- push_parse_stack ();
- top_stack->cur_st = st;
- top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st),
- STATIC_BLOCK);
- BLOCK_START (top_stack->cur_block) = fh ? fh->adr : 0;
- BLOCK_END (top_stack->cur_block) = 0;
- top_stack->blocktype = stFile;
- top_stack->maxsyms = 2 * f_max;
- top_stack->cur_type = 0;
- top_stack->procadr = 0;
- top_stack->numargs = 0;
-
- if (fh)
- {
- struct sym_ext *sym_ptr;
- struct sym_ext *sym_end;
-
- /* Parse local symbols first */
- sym_ptr = ecoff_data (cur_bfd)->external_sym + fh->isymBase;
- sym_end = sym_ptr + fh->csym;
- while (sym_ptr < sym_end)
- {
- SYMR sh;
- int c;
-
- ecoff_swap_sym_in (cur_bfd, sym_ptr, &sh);
- c = parse_symbol (&sh,
- (ecoff_data (cur_bfd)->external_aux
- + fh->iauxBase),
- sym_ptr, fh->fBigendian);
- /* FIXME: We must swap the modified symbol back out,
- although we would rather not. See parse_symbol. */
- ecoff_swap_sym_out (cur_bfd, &sh, sym_ptr);
- sym_ptr += c;
- }
-
- /* Linenumbers. At the end, check if we can save memory.
- parse_lines has to look ahead an arbitrary number of PDR
- structures, so we swap them all first. */
- if (fh->cpd > 0)
- {
- PDR *pr_block;
- struct cleanup *old_chain;
- struct pdr_ext *pdr_ptr;
- struct pdr_ext *pdr_end;
- PDR *pdr_in;
- PDR *pdr_in_end;
-
- pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
-
- old_chain = make_cleanup (free, pr_block);
-
- pdr_ptr = ecoff_data (cur_bfd)->external_pdr + fh->ipdFirst;
- pdr_end = pdr_ptr + fh->cpd;
- pdr_in = pr_block;
- for (; pdr_ptr < pdr_end; pdr_ptr++, pdr_in++)
- ecoff_swap_pdr_in (cur_bfd, pdr_ptr, pdr_in);
-
- parse_lines (fh, pr_block, lines);
- if (lines->nitems < fh->cline)
- lines = shrink_linetable (lines);
-
- /* Fill in procedure info next. */
- pdr_in = pr_block;
- pdr_in_end = pdr_in + fh->cpd;
- for (; pdr_in < pdr_in_end; pdr_in++)
- parse_procedure (pdr_in, 0, pr_block->adr);
-
- do_cleanups (old_chain);
- }
- }
-
- LINETABLE (st) = lines;
-
- /* .. and our share of externals.
- XXX use the global list to speed up things here. how?
- FIXME, Maybe quit once we have found the right number of ext's? */
- top_stack->cur_st = st;
- top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
- GLOBAL_BLOCK);
- top_stack->blocktype = stFile;
- top_stack->maxsyms = (ecoff_data (cur_bfd)->symbolic_header.isymMax
- + ecoff_data (cur_bfd)->symbolic_header.ipdMax
- + ecoff_data (cur_bfd)->symbolic_header.iextMax);
-
- ext_ptr = PST_PRIVATE (pst)->extern_tab;
- for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
- parse_external (ext_ptr, 1, fh->fBigendian);
-
- /* If there are undefined, tell the user */
- if (n_undef_symbols)
- {
- printf_filtered ("File %s contains %d unresolved references:",
- st->filename, n_undef_symbols);
- printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
- n_undef_vars, n_undef_procs, n_undef_labels);
- n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
-
- }
- pop_parse_stack ();
-
- /* Sort the symbol table now, we are done adding symbols to it.*/
- sort_symtab_syms (st);
-
- sort_blocks (st);
- }
-
- /* Now link the psymtab and the symtab. */
- pst->symtab = st;
-
- current_objfile = NULL;
-}
-\f
-/* Ancillary parsing procedures. */
-
-/* Lookup the type at relative index RN. Return it in TPP
- if found and in any event come up with its name PNAME.
- BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
- Return value says how many aux symbols we ate. */
-
-static int
-cross_ref (ax, tpp, type_code, pname, bigend)
- union aux_ext *ax;
- struct type **tpp;
- enum type_code type_code; /* Use to alloc new type if none is found. */
- char **pname;
- int bigend;
-{
- RNDXR rn[1];
- unsigned rf;
- int result = 1;
-
- ecoff_swap_rndx_in (bigend, &ax->a_rndx, rn);
-
- /* Escape index means 'the next one' */
- if (rn->rfd == 0xfff)
- {
- result++;
- rf = AUX_GET_ISYM (bigend, ax + 1);
- }
- else
- {
- rf = rn->rfd;
- }
-
- if (rf == -1)
- {
- /* Ooops */
- *pname = "<undefined>";
- }
- else
- {
- /*
- * Find the relative file descriptor and the symbol in it
- */
- FDR *fh = get_rfd (cur_fd, rf);
- struct sym_ext *esh;
- SYMR sh;
- struct type *t;
-
- /* If we have processed this symbol then we left a forwarding
- pointer to the corresponding GDB symbol. If not, we`ll put
- it in a list of pending symbols, to be processed later when
- the file will be. In any event, we collect the name for the
- type here. Which is why we made a first pass at strings. */
-
- esh = ecoff_data (cur_bfd)->external_sym + fh->isymBase + rn->index;
- ecoff_swap_sym_in (cur_bfd, esh, &sh);
-
- /* Careful, we might be looking at .o files */
- if (sh.iss == 0)
- *pname = "<undefined>";
- else
- *pname = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
-
- /* Have we parsed it ? */
- if (sh.value != 0 && sh.st == stParsed)
- {
- t = (struct type *) sh.value;
- *tpp = t;
- }
- else
- {
- /* Avoid duplicates */
- struct mips_pending *p = is_pending_symbol (fh, esh);
- if (p)
- *tpp = p->t;
- else
- {
- *tpp = init_type (type_code, 0, 0, (char *) NULL,
- (struct objfile *) NULL);
- add_pending (fh, esh, *tpp);
- }
- }
- }
-
- /* We used one auxent normally, two if we got a "next one" rf. */
- return result;
-}
-
-
-/* Quick&dirty lookup procedure, to avoid the MI ones that require
- keeping the symtab sorted */
-
-static struct symbol *
-mylookup_symbol (name, block, namespace, class)
- char *name;
- register struct block *block;
- enum namespace namespace;
- enum address_class class;
-{
- register int bot, top, inc;
- register struct symbol *sym;
-
- bot = 0;
- top = BLOCK_NSYMS (block);
- inc = name[0];
- while (bot < top)
- {
- sym = BLOCK_SYM (block, bot);
- if (SYMBOL_NAME (sym)[0] == inc
- && SYMBOL_NAMESPACE (sym) == namespace
- && SYMBOL_CLASS (sym) == class
- && STREQ (SYMBOL_NAME (sym), name))
- return sym;
- bot++;
- }
- block = BLOCK_SUPERBLOCK (block);
- if (block)
- return mylookup_symbol (name, block, namespace, class);
- return 0;
-}
-
-
-/* Add a new symbol S to a block B.
- Infrequently, we will need to reallocate the block to make it bigger.
- We only detect this case when adding to top_stack->cur_block, since
- that's the only time we know how big the block is. FIXME. */
-
-static void
-add_symbol (s, b)
- struct symbol *s;
- struct block *b;
-{
- int nsyms = BLOCK_NSYMS (b)++;
- struct block *origb;
- struct parse_stack *stackp;
-
- if (b == top_stack->cur_block &&
- nsyms >= top_stack->maxsyms)
- {
- complain (&block_overflow_complaint, SYMBOL_NAME (s));
- /* In this case shrink_block is actually grow_block, since
- BLOCK_NSYMS(b) is larger than its current size. */
- origb = b;
- b = shrink_block (top_stack->cur_block, top_stack->cur_st);
-
- /* Now run through the stack replacing pointers to the
- original block. shrink_block has already done this
- for the blockvector and BLOCK_FUNCTION. */
- for (stackp = top_stack; stackp; stackp = stackp->next)
- {
- if (stackp->cur_block == origb)
- {
- stackp->cur_block = b;
- stackp->maxsyms = BLOCK_NSYMS (b);
- }
- }
- }
- BLOCK_SYM (b, nsyms) = s;
-}
-
-/* Add a new block B to a symtab S */
-
-static void
-add_block (b, s)
- struct block *b;
- struct symtab *s;
-{
- struct blockvector *bv = BLOCKVECTOR (s);
-
- bv = (struct blockvector *) xrealloc ((PTR) bv,
- (sizeof (struct blockvector)
- + BLOCKVECTOR_NBLOCKS (bv)
- * sizeof (bv->block)));
- if (bv != BLOCKVECTOR (s))
- BLOCKVECTOR (s) = bv;
-
- BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
-}
-
-/* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
- MIPS' linenumber encoding might need more than one byte
- to describe it, LAST is used to detect these continuation lines.
-
- Combining lines with the same line number seems like a bad idea.
- E.g: There could be a line number entry with the same line number after the
- prologue and GDB should not ignore it (this is a better way to find
- a prologue than mips_skip_prologue).
- But due to the compressed line table format there are line number entries
- for the same line which are needed to bridge the gap to the next
- line number entry. These entries have a bogus address info with them
- and we are unable to tell them from intended duplicate line number
- entries.
- This is another reason why -ggdb debugging format is preferable. */
-
-static int
-add_line (lt, lineno, adr, last)
- struct linetable *lt;
- int lineno;
- CORE_ADDR adr;
- int last;
-{
- if (last == 0)
- last = -2; /* make sure we record first line */
-
- if (last == lineno) /* skip continuation lines */
- return lineno;
-
- lt->item[lt->nitems].line = lineno;
- lt->item[lt->nitems++].pc = adr << 2;
- return lineno;
-}
-\f
-/* Sorting and reordering procedures */
-
-/* Blocks with a smaller low bound should come first */
-
-static int
-compare_blocks (arg1, arg2)
- const void *arg1, *arg2;
-{
- register int addr_diff;
- struct block **b1 = (struct block **) arg1;
- struct block **b2 = (struct block **) arg2;
-
- addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
- if (addr_diff == 0)
- return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
- return addr_diff;
-}
-
-/* Sort the blocks of a symtab S.
- Reorder the blocks in the blockvector by code-address,
- as required by some MI search routines */
-
-static void
-sort_blocks (s)
- struct symtab *s;
-{
- struct blockvector *bv = BLOCKVECTOR (s);
-
- if (BLOCKVECTOR_NBLOCKS (bv) <= 2)
- {
- /* Cosmetic */
- if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
- BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
- if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
- BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
- return;
- }
- /*
- * This is very unfortunate: normally all functions are compiled in
- * the order they are found, but if the file is compiled -O3 things
- * are very different. It would be nice to find a reliable test
- * to detect -O3 images in advance.
- */
- if (BLOCKVECTOR_NBLOCKS (bv) > 3)
- qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
- BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
- sizeof (struct block *),
- compare_blocks);
-
- {
- register CORE_ADDR high = 0;
- register int i, j = BLOCKVECTOR_NBLOCKS (bv);
-
- for (i = FIRST_LOCAL_BLOCK; i < j; i++)
- if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
- high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
- BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
- }
-
- BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
- BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
-
- BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
- BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
- BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
- BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
-}
-\f
-
-/* Constructor/restructor/destructor procedures */
-
-/* Allocate a new symtab for NAME. Needs an estimate of how many symbols
- MAXSYMS and linenumbers MAXLINES we'll put in it */
-
-static struct symtab *
-new_symtab (name, maxsyms, maxlines, objfile)
- char *name;
- int maxsyms;
- int maxlines;
- struct objfile *objfile;
-{
- struct symtab *s = allocate_symtab (name, objfile);
-
- LINETABLE (s) = new_linetable (maxlines);
-
- /* All symtabs must have at least two blocks */
- BLOCKVECTOR (s) = new_bvect (2);
- BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = new_block (maxsyms);
- BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = new_block (maxsyms);
- BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
- BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
-
- s->free_code = free_linetable;
-
- return (s);
-}
-
-/* Allocate a new partial_symtab NAME */
-
-static struct partial_symtab *
-new_psymtab (name, objfile)
- char *name;
- struct objfile *objfile;
-{
- struct partial_symtab *psymtab;
-
- psymtab = allocate_psymtab (name, objfile);
-
- /* Keep a backpointer to the file's symbols */
-
- psymtab->read_symtab_private = ((char *)
- obstack_alloc (&objfile->psymbol_obstack,
- sizeof (struct symloc)));
- memset ((PTR) psymtab->read_symtab_private, 0, sizeof (struct symloc));
- CUR_BFD (psymtab) = cur_bfd;
-
- /* The way to turn this into a symtab is to call... */
- psymtab->read_symtab = mipscoff_psymtab_to_symtab;
- return (psymtab);
-}
-
-
-/* Allocate a linetable array of the given SIZE. Since the struct
- already includes one item, we subtract one when calculating the
- proper size to allocate. */
-
-static struct linetable *
-new_linetable (size)
- int size;
-{
- struct linetable *l;
-
- size = (size - 1) * sizeof (l->item) + sizeof (struct linetable);
- l = (struct linetable *) xmalloc (size);
- l->nitems = 0;
- return l;
-}
-
-/* Oops, too big. Shrink it. This was important with the 2.4 linetables,
- I am not so sure about the 3.4 ones.
-
- Since the struct linetable already includes one item, we subtract one when
- calculating the proper size to allocate. */
-
-static struct linetable *
-shrink_linetable (lt)
- struct linetable *lt;
-{
-
- return (struct linetable *) xrealloc ((PTR) lt,
- (sizeof (struct linetable)
- + ((lt->nitems - 1)
- * sizeof (lt->item))));
-}
-
-/* Allocate and zero a new blockvector of NBLOCKS blocks. */
-
-static struct blockvector *
-new_bvect (nblocks)
- int nblocks;
-{
- struct blockvector *bv;
- int size;
-
- size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
- bv = (struct blockvector *) xzalloc (size);
-
- BLOCKVECTOR_NBLOCKS (bv) = nblocks;
-
- return bv;
-}
-
-/* Allocate and zero a new block of MAXSYMS symbols */
-
-static struct block *
-new_block (maxsyms)
- int maxsyms;
-{
- int size = sizeof (struct block) + (maxsyms - 1) * sizeof (struct symbol *);
-
- return (struct block *) xzalloc (size);
-}
-
-/* Ooops, too big. Shrink block B in symtab S to its minimal size.
- Shrink_block can also be used by add_symbol to grow a block. */
-
-static struct block *
-shrink_block (b, s)
- struct block *b;
- struct symtab *s;
-{
- struct block *new;
- struct blockvector *bv = BLOCKVECTOR (s);
- int i;
-
- /* Just reallocate it and fix references to the old one */
-
- new = (struct block *) xrealloc ((PTR) b,
- (sizeof (struct block)
- + ((BLOCK_NSYMS (b) - 1)
- * sizeof (struct symbol *))));
-
- /* Should chase pointers to old one. Fortunately, that`s just
- the block`s function and inferior blocks */
- if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b)
- SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
- for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
- if (BLOCKVECTOR_BLOCK (bv, i) == b)
- BLOCKVECTOR_BLOCK (bv, i) = new;
- else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b)
- BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = new;
- return new;
-}
-
-/* Create a new symbol with printname NAME */
-
-static struct symbol *
-new_symbol (name)
- char *name;
-{
- struct symbol *s = ((struct symbol *)
- obstack_alloc (¤t_objfile->symbol_obstack,
- sizeof (struct symbol)));
-
- memset ((PTR) s, 0, sizeof (*s));
- SYMBOL_NAME (s) = name;
- return s;