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