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