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