Update/correct copyright notices.
[platform/upstream/binutils.git] / gdb / mdebugread.c
1 /* Read a symbol table in ECOFF format (Third-Eye).
2    Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
3    1997, 1998, 1999, 2000, 2001
4    Free Software Foundation, Inc.
5    Original version contributed by Alessandro Forin (af@cs.cmu.edu) at
6    CMU.  Major work by Per Bothner, John Gilmore and Ian Lance Taylor
7    at Cygnus Support.
8
9    This file is part of GDB.
10
11    This program is free software; you can redistribute it and/or modify
12    it under the terms of the GNU General Public License as published by
13    the Free Software Foundation; either version 2 of the License, or
14    (at your option) any later version.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 59 Temple Place - Suite 330,
24    Boston, MA 02111-1307, USA.  */
25
26 /* This module provides the function mdebug_build_psymtabs.  It reads
27    ECOFF debugging information into partial symbol tables.  The
28    debugging information is read from two structures.  A struct
29    ecoff_debug_swap includes the sizes of each ECOFF structure and
30    swapping routines; these are fixed for a particular target.  A
31    struct ecoff_debug_info points to the debugging information for a
32    particular object file.
33
34    ECOFF symbol tables are mostly written in the byte order of the
35    target machine.  However, one section of the table (the auxiliary
36    symbol information) is written in the host byte order.  There is a
37    bit in the other symbol info which describes which host byte order
38    was used.  ECOFF thereby takes the trophy from Intel `b.out' for
39    the most brain-dead adaptation of a file format to byte order.
40
41    This module can read all four of the known byte-order combinations,
42    on any type of host.  */
43
44 #include "defs.h"
45 #include "symtab.h"
46 #include "gdbtypes.h"
47 #include "gdbcore.h"
48 #include "symfile.h"
49 #include "objfiles.h"
50 #include "obstack.h"
51 #include "buildsym.h"
52 #include "stabsread.h"
53 #include "complaints.h"
54 #include "demangle.h"
55
56 /* These are needed if the tm.h file does not contain the necessary
57    mips specific definitions.  */
58
59 #ifndef MIPS_EFI_SYMBOL_NAME
60 #define MIPS_EFI_SYMBOL_NAME "__GDB_EFI_INFO__"
61 extern void ecoff_relocate_efi (struct symbol *, CORE_ADDR);
62 #include "coff/sym.h"
63 #include "coff/symconst.h"
64 typedef struct mips_extra_func_info
65   {
66     long numargs;
67     PDR pdr;
68   }
69  *mips_extra_func_info_t;
70 #ifndef RA_REGNUM
71 #define RA_REGNUM 0
72 #endif
73 #endif
74
75 #ifdef USG
76 #include <sys/types.h>
77 #endif
78
79 #include "gdb_stat.h"
80 #include "gdb_string.h"
81
82 #include "gdb-stabs.h"
83
84 #include "bfd.h"
85
86 #include "coff/ecoff.h"         /* COFF-like aspects of ecoff files */
87
88 #include "libaout.h"            /* Private BFD a.out information.  */
89 #include "aout/aout64.h"
90 #include "aout/stab_gnu.h"      /* STABS information */
91
92 #include "expression.h"
93 #include "language.h"           /* Needed inside partial-stab.h */
94
95 extern void _initialize_mdebugread (void);
96
97 /* Provide a way to test if we have both ECOFF and ELF symbol tables.  
98    We use this define in order to know whether we should override a 
99    symbol's ECOFF section with its ELF section.  This is necessary in 
100    case the symbol's ELF section could not be represented in ECOFF.  */
101 #define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
102                            && bfd_get_section_by_name (bfd, ".mdebug") != NULL)
103 \f
104
105 /* We put a pointer to this structure in the read_symtab_private field
106    of the psymtab.  */
107
108 struct symloc
109   {
110     /* Index of the FDR that this psymtab represents.  */
111     int fdr_idx;
112     /* The BFD that the psymtab was created from.  */
113     bfd *cur_bfd;
114     const struct ecoff_debug_swap *debug_swap;
115     struct ecoff_debug_info *debug_info;
116     struct mdebug_pending **pending_list;
117     /* Pointer to external symbols for this file.  */
118     EXTR *extern_tab;
119     /* Size of extern_tab.  */
120     int extern_count;
121     enum language pst_language;
122   };
123
124 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
125 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
126 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
127 #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
128 #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
129 #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
130
131 #define SC_IS_TEXT(sc) ((sc) == scText \
132                    || (sc) == scRConst \
133                    || (sc) == scInit \
134                    || (sc) == scFini)
135 #define SC_IS_DATA(sc) ((sc) == scData \
136                    || (sc) == scSData \
137                    || (sc) == scRData \
138                    || (sc) == scPData \
139                    || (sc) == scXData)
140 #define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon)
141 #define SC_IS_BSS(sc) ((sc) == scBss || (sc) == scSBss)
142 #define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined)
143 \f
144
145 /* Things we import explicitly from other modules */
146
147 extern int info_verbose;
148
149 /* Various complaints about symbol reading that don't abort the process */
150
151 static struct complaint bad_file_number_complaint =
152 {"bad file number %d", 0, 0};
153
154 static struct complaint index_complaint =
155 {"bad aux index at symbol %s", 0, 0};
156
157 static struct complaint aux_index_complaint =
158 {"bad proc end in aux found from symbol %s", 0, 0};
159
160 static struct complaint block_index_complaint =
161 {"bad aux index at block symbol %s", 0, 0};
162
163 static struct complaint unknown_ext_complaint =
164 {"unknown external symbol %s", 0, 0};
165
166 static struct complaint unknown_sym_complaint =
167 {"unknown local symbol %s", 0, 0};
168
169 static struct complaint unknown_st_complaint =
170 {"with type %d", 0, 0};
171
172 static struct complaint block_overflow_complaint =
173 {"block containing %s overfilled", 0, 0};
174
175 static struct complaint basic_type_complaint =
176 {"cannot map ECOFF basic type 0x%x for %s", 0, 0};
177
178 static struct complaint unknown_type_qual_complaint =
179 {"unknown type qualifier 0x%x", 0, 0};
180
181 static struct complaint array_index_type_complaint =
182 {"illegal array index type for %s, assuming int", 0, 0};
183
184 static struct complaint bad_tag_guess_complaint =
185 {"guessed tag type of %s incorrectly", 0, 0};
186
187 static struct complaint block_member_complaint =
188 {"declaration block contains unhandled symbol type %d", 0, 0};
189
190 static struct complaint stEnd_complaint =
191 {"stEnd with storage class %d not handled", 0, 0};
192
193 static struct complaint unknown_mdebug_symtype_complaint =
194 {"unknown symbol type 0x%x", 0, 0};
195
196 static struct complaint stab_unknown_complaint =
197 {"unknown stabs symbol %s", 0, 0};
198
199 static struct complaint pdr_for_nonsymbol_complaint =
200 {"PDR for %s, but no symbol", 0, 0};
201
202 static struct complaint pdr_static_symbol_complaint =
203 {"can't handle PDR for static proc at 0x%lx", 0, 0};
204
205 static struct complaint bad_setjmp_pdr_complaint =
206 {"fixing bad setjmp PDR from libc", 0, 0};
207
208 static struct complaint bad_fbitfield_complaint =
209 {"can't handle TIR fBitfield for %s", 0, 0};
210
211 static struct complaint bad_continued_complaint =
212 {"illegal TIR continued for %s", 0, 0};
213
214 static struct complaint bad_rfd_entry_complaint =
215 {"bad rfd entry for %s: file %d, index %d", 0, 0};
216
217 static struct complaint unexpected_type_code_complaint =
218 {"unexpected type code for %s", 0, 0};
219
220 static struct complaint unable_to_cross_ref_complaint =
221 {"unable to cross ref btTypedef for %s", 0, 0};
222
223 static struct complaint bad_indirect_xref_complaint =
224 {"unable to cross ref btIndirect for %s", 0, 0};
225
226 static struct complaint illegal_forward_tq0_complaint =
227 {"illegal tq0 in forward typedef for %s", 0, 0};
228
229 static struct complaint illegal_forward_bt_complaint =
230 {"illegal bt %d in forward typedef for %s", 0, 0};
231
232 static struct complaint bad_linetable_guess_complaint =
233 {"guessed size of linetable for %s incorrectly", 0, 0};
234
235 static struct complaint bad_ext_ifd_complaint =
236 {"bad ifd for external symbol: %d (max %d)", 0, 0};
237
238 static struct complaint bad_ext_iss_complaint =
239 {"bad iss for external symbol: %ld (max %ld)", 0, 0};
240
241 /* Macros and extra defs */
242
243 /* Puns: hard to find whether -g was used and how */
244
245 #define MIN_GLEVEL GLEVEL_0
246 #define compare_glevel(a,b)                                     \
247         (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) :                 \
248          ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
249 \f
250 /* Things that really are local to this module */
251
252 /* Remember what we deduced to be the source language of this psymtab. */
253
254 static enum language psymtab_language = language_unknown;
255
256 /* Current BFD.  */
257
258 static bfd *cur_bfd;
259
260 /* How to parse debugging information for CUR_BFD.  */
261
262 static const struct ecoff_debug_swap *debug_swap;
263
264 /* Pointers to debugging information for CUR_BFD.  */
265
266 static struct ecoff_debug_info *debug_info;
267
268 /* Pointer to current file decriptor record, and its index */
269
270 static FDR *cur_fdr;
271 static int cur_fd;
272
273 /* Index of current symbol */
274
275 static int cur_sdx;
276
277 /* Note how much "debuggable" this image is.  We would like
278    to see at least one FDR with full symbols */
279
280 static int max_gdbinfo;
281 static int max_glevel;
282
283 /* When examining .o files, report on undefined symbols */
284
285 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
286
287 /* Pseudo symbol to use when putting stabs into the symbol table.  */
288
289 static char stabs_symbol[] = STABS_SYMBOL;
290
291 /* Types corresponding to mdebug format bt* basic types.  */
292
293 static struct type *mdebug_type_void;
294 static struct type *mdebug_type_char;
295 static struct type *mdebug_type_short;
296 static struct type *mdebug_type_int_32;
297 #define mdebug_type_int mdebug_type_int_32
298 static struct type *mdebug_type_int_64;
299 static struct type *mdebug_type_long_32;
300 static struct type *mdebug_type_long_64;
301 static struct type *mdebug_type_long_long_64;
302 static struct type *mdebug_type_unsigned_char;
303 static struct type *mdebug_type_unsigned_short;
304 static struct type *mdebug_type_unsigned_int_32;
305 static struct type *mdebug_type_unsigned_int_64;
306 static struct type *mdebug_type_unsigned_long_32;
307 static struct type *mdebug_type_unsigned_long_64;
308 static struct type *mdebug_type_unsigned_long_long_64;
309 static struct type *mdebug_type_adr_32;
310 static struct type *mdebug_type_adr_64;
311 static struct type *mdebug_type_float;
312 static struct type *mdebug_type_double;
313 static struct type *mdebug_type_complex;
314 static struct type *mdebug_type_double_complex;
315 static struct type *mdebug_type_fixed_dec;
316 static struct type *mdebug_type_float_dec;
317 static struct type *mdebug_type_string;
318
319 /* Types for symbols from files compiled without debugging info.  */
320
321 static struct type *nodebug_func_symbol_type;
322 static struct type *nodebug_var_symbol_type;
323
324 /* Nonzero if we have seen ecoff debugging info for a file.  */
325
326 static int found_ecoff_debugging_info;
327
328 /* Forward declarations */
329
330 static void add_pending (FDR *, char *, struct type *);
331
332 static struct mdebug_pending *is_pending_symbol (FDR *, char *);
333
334 static void pop_parse_stack (void);
335
336 static void push_parse_stack (void);
337
338 static char *fdr_name (FDR *);
339
340 static void mdebug_psymtab_to_symtab (struct partial_symtab *);
341
342 static int
343 upgrade_type (int, struct type **, int, union aux_ext *, int, char *);
344
345 static void parse_partial_symbols (struct objfile *);
346
347 static FDR * get_rfd (int, int);
348
349 static int has_opaque_xref (FDR *, SYMR *);
350
351 static int
352 cross_ref (int, union aux_ext *, struct type **, enum type_code,
353            char **, int, char *);
354
355 static struct symbol *new_symbol (char *);
356
357 static struct type *new_type (char *);
358
359 static struct block *new_block (int);
360
361 static struct symtab *new_symtab (char *, int, int, struct objfile *);
362
363 static struct linetable *new_linetable (int);
364
365 static struct blockvector *new_bvect (int);
366
367 static int
368 parse_symbol (SYMR *, union aux_ext *, char *, int, struct section_offsets *,
369               struct objfile *);
370
371 static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
372                                 int, char *);
373
374 static struct symbol *mylookup_symbol (char *, struct block *, namespace_enum,
375                                        enum address_class);
376
377 static struct block *shrink_block (struct block *, struct symtab *);
378
379 static PTR xzalloc (unsigned int);
380
381 static void sort_blocks (struct symtab *);
382
383 static int compare_blocks (const void *, const void *);
384
385 static struct partial_symtab *new_psymtab (char *, struct objfile *);
386
387 static void psymtab_to_symtab_1 (struct partial_symtab *, char *);
388
389 static void add_block (struct block *, struct symtab *);
390
391 static void add_symbol (struct symbol *, struct block *);
392
393 static int add_line (struct linetable *, int, CORE_ADDR, int);
394
395 static struct linetable *shrink_linetable (struct linetable *);
396
397 static void
398 handle_psymbol_enumerators (struct objfile *, FDR *, int, CORE_ADDR);
399
400 static char *mdebug_next_symbol_text (struct objfile *);
401 \f
402 /* Address bounds for the signal trampoline in inferior, if any */
403
404 CORE_ADDR sigtramp_address, sigtramp_end;
405
406 /* Allocate zeroed memory */
407
408 static PTR
409 xzalloc (unsigned int size)
410 {
411   PTR p = xmalloc (size);
412
413   memset (p, 0, size);
414   return p;
415 }
416
417 /* Exported procedure: Builds a symtab from the PST partial one.
418    Restores the environment in effect when PST was created, delegates
419    most of the work to an ancillary procedure, and sorts
420    and reorders the symtab list at the end */
421
422 static void
423 mdebug_psymtab_to_symtab (struct partial_symtab *pst)
424 {
425
426   if (!pst)
427     return;
428
429   if (info_verbose)
430     {
431       printf_filtered ("Reading in symbols for %s...", pst->filename);
432       gdb_flush (gdb_stdout);
433     }
434
435   next_symbol_text_func = mdebug_next_symbol_text;
436
437   psymtab_to_symtab_1 (pst, pst->filename);
438
439   /* Match with global symbols.  This only needs to be done once,
440      after all of the symtabs and dependencies have been read in.   */
441   scan_file_globals (pst->objfile);
442
443   if (info_verbose)
444     printf_filtered ("done.\n");
445 }
446 \f
447 /* File-level interface functions */
448
449 /* Find a file descriptor given its index RF relative to a file CF */
450
451 static FDR *
452 get_rfd (int cf, int rf)
453 {
454   FDR *fdrs;
455   register FDR *f;
456   RFDT rfd;
457
458   fdrs = debug_info->fdr;
459   f = fdrs + cf;
460   /* Object files do not have the RFD table, all refs are absolute */
461   if (f->rfdBase == 0)
462     return fdrs + rf;
463   (*debug_swap->swap_rfd_in) (cur_bfd,
464                               ((char *) debug_info->external_rfd
465                                + ((f->rfdBase + rf)
466                                   * debug_swap->external_rfd_size)),
467                               &rfd);
468   return fdrs + rfd;
469 }
470
471 /* Return a safer print NAME for a file descriptor */
472
473 static char *
474 fdr_name (FDR *f)
475 {
476   if (f->rss == -1)
477     return "<stripped file>";
478   if (f->rss == 0)
479     return "<NFY>";
480   return debug_info->ss + f->issBase + f->rss;
481 }
482
483
484 /* Read in and parse the symtab of the file OBJFILE.  Symbols from
485    different sections are relocated via the SECTION_OFFSETS.  */
486
487 void
488 mdebug_build_psymtabs (struct objfile *objfile,
489                        const struct ecoff_debug_swap *swap,
490                        struct ecoff_debug_info *info)
491 {
492   cur_bfd = objfile->obfd;
493   debug_swap = swap;
494   debug_info = info;
495
496   /* Make sure all the FDR information is swapped in.  */
497   if (info->fdr == (FDR *) NULL)
498     {
499       char *fdr_src;
500       char *fdr_end;
501       FDR *fdr_ptr;
502
503       info->fdr = (FDR *) obstack_alloc (&objfile->psymbol_obstack,
504                                          (info->symbolic_header.ifdMax
505                                           * sizeof (FDR)));
506       fdr_src = info->external_fdr;
507       fdr_end = (fdr_src
508                  + info->symbolic_header.ifdMax * swap->external_fdr_size);
509       fdr_ptr = info->fdr;
510       for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++)
511         (*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
512     }
513
514   parse_partial_symbols (objfile);
515
516 #if 0
517   /* Check to make sure file was compiled with -g.  If not, warn the
518      user of this limitation.  */
519   if (compare_glevel (max_glevel, GLEVEL_2) < 0)
520     {
521       if (max_gdbinfo == 0)
522         printf_unfiltered ("\n%s not compiled with -g, debugging support is limited.\n",
523                            objfile->name);
524       printf_unfiltered ("You should compile with -g2 or -g3 for best debugging support.\n");
525       gdb_flush (gdb_stdout);
526     }
527 #endif
528 }
529 \f
530 /* Local utilities */
531
532 /* Map of FDR indexes to partial symtabs */
533
534 struct pst_map
535 {
536   struct partial_symtab *pst;   /* the psymtab proper */
537   long n_globals;               /* exported globals (external symbols) */
538   long globals_offset;          /* cumulative */
539 };
540
541
542 /* Utility stack, used to nest procedures and blocks properly.
543    It is a doubly linked list, to avoid too many alloc/free.
544    Since we might need it quite a few times it is NOT deallocated
545    after use. */
546
547 static struct parse_stack
548   {
549     struct parse_stack *next, *prev;
550     struct symtab *cur_st;      /* Current symtab. */
551     struct block *cur_block;    /* Block in it. */
552
553     /* What are we parsing.  stFile, or stBlock are for files and
554        blocks.  stProc or stStaticProc means we have seen the start of a
555        procedure, but not the start of the block within in.  When we see
556        the start of that block, we change it to stNil, without pushing a
557        new block, i.e. stNil means both a procedure and a block.  */
558
559     int blocktype;
560
561     int maxsyms;                /* Max symbols in this block. */
562     struct type *cur_type;      /* Type we parse fields for. */
563     int cur_field;              /* Field number in cur_type. */
564     CORE_ADDR procadr;          /* Start addres of this procedure */
565     int numargs;                /* Its argument count */
566   }
567
568  *top_stack;                    /* Top stack ptr */
569
570
571 /* Enter a new lexical context */
572
573 static void
574 push_parse_stack (void)
575 {
576   struct parse_stack *new;
577
578   /* Reuse frames if possible */
579   if (top_stack && top_stack->prev)
580     new = top_stack->prev;
581   else
582     new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack));
583   /* Initialize new frame with previous content */
584   if (top_stack)
585     {
586       register struct parse_stack *prev = new->prev;
587
588       *new = *top_stack;
589       top_stack->prev = new;
590       new->prev = prev;
591       new->next = top_stack;
592     }
593   top_stack = new;
594 }
595
596 /* Exit a lexical context */
597
598 static void
599 pop_parse_stack (void)
600 {
601   if (!top_stack)
602     return;
603   if (top_stack->next)
604     top_stack = top_stack->next;
605 }
606
607
608 /* Cross-references might be to things we haven't looked at
609    yet, e.g. type references.  To avoid too many type
610    duplications we keep a quick fixup table, an array
611    of lists of references indexed by file descriptor */
612
613 struct mdebug_pending
614 {
615   struct mdebug_pending *next;  /* link */
616   char *s;                      /* the unswapped symbol */
617   struct type *t;               /* its partial type descriptor */
618 };
619
620
621 /* The pending information is kept for an entire object file, and used
622    to be in the sym_private field.  I took it out when I split
623    mdebugread from mipsread, because this might not be the only type
624    of symbols read from an object file.  Instead, we allocate the
625    pending information table when we create the partial symbols, and
626    we store a pointer to the single table in each psymtab.  */
627
628 static struct mdebug_pending **pending_list;
629
630 /* Check whether we already saw symbol SH in file FH */
631
632 static struct mdebug_pending *
633 is_pending_symbol (FDR *fh, char *sh)
634 {
635   int f_idx = fh - debug_info->fdr;
636   register struct mdebug_pending *p;
637
638   /* Linear search is ok, list is typically no more than 10 deep */
639   for (p = pending_list[f_idx]; p; p = p->next)
640     if (p->s == sh)
641       break;
642   return p;
643 }
644
645 /* Add a new symbol SH of type T */
646
647 static void
648 add_pending (FDR *fh, char *sh, struct type *t)
649 {
650   int f_idx = fh - debug_info->fdr;
651   struct mdebug_pending *p = is_pending_symbol (fh, sh);
652
653   /* Make sure we do not make duplicates */
654   if (!p)
655     {
656       p = ((struct mdebug_pending *)
657            obstack_alloc (&current_objfile->psymbol_obstack,
658                           sizeof (struct mdebug_pending)));
659       p->s = sh;
660       p->t = t;
661       p->next = pending_list[f_idx];
662       pending_list[f_idx] = p;
663     }
664 }
665 \f
666
667 /* Parsing Routines proper. */
668
669 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
670    For blocks, procedures and types we open a new lexical context.
671    This is basically just a big switch on the symbol's type.  Argument
672    AX is the base pointer of aux symbols for this file (fh->iauxBase).
673    EXT_SH points to the unswapped symbol, which is needed for struct,
674    union, etc., types; it is NULL for an EXTR.  BIGEND says whether
675    aux symbols are big-endian or little-endian.  Return count of
676    SYMR's handled (normally one).  */
677
678 static int
679 parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
680               struct section_offsets *section_offsets, struct objfile *objfile)
681 {
682   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
683   void (*const swap_sym_in) (bfd *, PTR, SYMR *) = debug_swap->swap_sym_in;
684   char *name;
685   struct symbol *s;
686   struct block *b;
687   struct mdebug_pending *pend;
688   struct type *t;
689   struct field *f;
690   int count = 1;
691   enum address_class class;
692   TIR tir;
693   long svalue = sh->value;
694   int bitsize;
695
696   if (ext_sh == (char *) NULL)
697     name = debug_info->ssext + sh->iss;
698   else
699     name = debug_info->ss + cur_fdr->issBase + sh->iss;
700
701   switch (sh->sc)
702     {
703     case scText:
704     case scRConst:
705       /* Do not relocate relative values.
706          The value of a stEnd symbol is the displacement from the
707          corresponding start symbol value.
708          The value of a stBlock symbol is the displacement from the
709          procedure address.  */
710       if (sh->st != stEnd && sh->st != stBlock)
711         sh->value += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
712       break;
713     case scData:
714     case scSData:
715     case scRData:
716     case scPData:
717     case scXData:
718       sh->value += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
719       break;
720     case scBss:
721     case scSBss:
722       sh->value += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
723       break;
724     }
725
726   switch (sh->st)
727     {
728     case stNil:
729       break;
730
731     case stGlobal:              /* external symbol, goes into global block */
732       class = LOC_STATIC;
733       b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
734                              GLOBAL_BLOCK);
735       s = new_symbol (name);
736       SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
737       goto data;
738
739     case stStatic:              /* static data, goes into current block. */
740       class = LOC_STATIC;
741       b = top_stack->cur_block;
742       s = new_symbol (name);
743       if (SC_IS_COMMON (sh->sc))
744         {
745           /* It is a FORTRAN common block.  At least for SGI Fortran the
746              address is not in the symbol; we need to fix it later in
747              scan_file_globals.  */
748           int bucket = hashname (SYMBOL_NAME (s));
749           SYMBOL_VALUE_CHAIN (s) = global_sym_chain[bucket];
750           global_sym_chain[bucket] = s;
751         }
752       else
753         SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
754       goto data;
755
756     case stLocal:               /* local variable, goes into current block */
757       if (sh->sc == scRegister)
758         {
759           class = LOC_REGISTER;
760           svalue = ECOFF_REG_TO_REGNUM (svalue);
761         }
762       else
763         class = LOC_LOCAL;
764       b = top_stack->cur_block;
765       s = new_symbol (name);
766       SYMBOL_VALUE (s) = svalue;
767
768     data:                       /* Common code for symbols describing data */
769       SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
770       SYMBOL_CLASS (s) = class;
771       add_symbol (s, b);
772
773       /* Type could be missing if file is compiled without debugging info.  */
774       if (SC_IS_UNDEF (sh->sc)
775           || sh->sc == scNil || sh->index == indexNil)
776         SYMBOL_TYPE (s) = nodebug_var_symbol_type;
777       else
778         SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
779       /* Value of a data symbol is its memory address */
780       break;
781
782     case stParam:               /* arg to procedure, goes into current block */
783       max_gdbinfo++;
784       found_ecoff_debugging_info = 1;
785       top_stack->numargs++;
786
787       /* Special GNU C++ name.  */
788       if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0)
789         name = "this";          /* FIXME, not alloc'd in obstack */
790       s = new_symbol (name);
791
792       SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
793       switch (sh->sc)
794         {
795         case scRegister:
796           /* Pass by value in register.  */
797           SYMBOL_CLASS (s) = LOC_REGPARM;
798           svalue = ECOFF_REG_TO_REGNUM (svalue);
799           break;
800         case scVar:
801           /* Pass by reference on stack.  */
802           SYMBOL_CLASS (s) = LOC_REF_ARG;
803           break;
804         case scVarRegister:
805           /* Pass by reference in register.  */
806           SYMBOL_CLASS (s) = LOC_REGPARM_ADDR;
807           svalue = ECOFF_REG_TO_REGNUM (svalue);
808           break;
809         default:
810           /* Pass by value on stack.  */
811           SYMBOL_CLASS (s) = LOC_ARG;
812           break;
813         }
814       SYMBOL_VALUE (s) = svalue;
815       SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
816       add_symbol (s, top_stack->cur_block);
817       break;
818
819     case stLabel:               /* label, goes into current block */
820       s = new_symbol (name);
821       SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;     /* so that it can be used */
822       SYMBOL_CLASS (s) = LOC_LABEL;     /* but not misused */
823       SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
824       SYMBOL_TYPE (s) = mdebug_type_int;
825       add_symbol (s, top_stack->cur_block);
826       break;
827
828     case stProc:                /* Procedure, usually goes into global block */
829     case stStaticProc:          /* Static procedure, goes into current block */
830       s = new_symbol (name);
831       SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
832       SYMBOL_CLASS (s) = LOC_BLOCK;
833       /* Type of the return value */
834       if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
835         t = mdebug_type_int;
836       else
837         {
838           t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
839           if (STREQ (name, "malloc") && t->code == TYPE_CODE_VOID)
840             {
841               /* I don't know why, but, at least under Alpha GNU/Linux,
842                  when linking against a malloc without debugging
843                  symbols, its read as a function returning void---this
844                  is bad because it means we cannot call functions with
845                  string arguments interactively; i.e., "call
846                  printf("howdy\n")" would fail with the error message
847                  "program has no memory available".  To avoid this, we
848                  patch up the type and make it void*
849                  instead. (davidm@azstarnet.com)
850                */
851               t = make_pointer_type (t, NULL);
852             }
853         }
854       b = top_stack->cur_block;
855       if (sh->st == stProc)
856         {
857           struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
858           /* The next test should normally be true, but provides a
859              hook for nested functions (which we don't want to make
860              global). */
861           if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
862             b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
863           /* Irix 5 sometimes has duplicate names for the same
864              function.  We want to add such names up at the global
865              level, not as a nested function.  */
866           else if (sh->value == top_stack->procadr)
867             b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
868         }
869       add_symbol (s, b);
870
871       /* Make a type for the procedure itself */
872       SYMBOL_TYPE (s) = lookup_function_type (t);
873
874       /* Create and enter a new lexical context */
875       b = new_block (top_stack->maxsyms);
876       SYMBOL_BLOCK_VALUE (s) = b;
877       BLOCK_FUNCTION (b) = s;
878       BLOCK_START (b) = BLOCK_END (b) = sh->value;
879       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
880       add_block (b, top_stack->cur_st);
881
882       /* Not if we only have partial info */
883       if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
884         break;
885
886       push_parse_stack ();
887       top_stack->cur_block = b;
888       top_stack->blocktype = sh->st;
889       top_stack->cur_type = SYMBOL_TYPE (s);
890       top_stack->cur_field = -1;
891       top_stack->procadr = sh->value;
892       top_stack->numargs = 0;
893       break;
894
895       /* Beginning of code for structure, union, and enum definitions.
896          They all share a common set of local variables, defined here.  */
897       {
898         enum type_code type_code;
899         char *ext_tsym;
900         int nfields;
901         long max_value;
902         struct field *f;
903
904     case stStruct:              /* Start a block defining a struct type */
905         type_code = TYPE_CODE_STRUCT;
906         goto structured_common;
907
908     case stUnion:               /* Start a block defining a union type */
909         type_code = TYPE_CODE_UNION;
910         goto structured_common;
911
912     case stEnum:                /* Start a block defining an enum type */
913         type_code = TYPE_CODE_ENUM;
914         goto structured_common;
915
916     case stBlock:               /* Either a lexical block, or some type */
917         if (sh->sc != scInfo && !SC_IS_COMMON (sh->sc))
918           goto case_stBlock_code;       /* Lexical block */
919
920         type_code = TYPE_CODE_UNDEF;    /* We have a type.  */
921
922         /* Common code for handling struct, union, enum, and/or as-yet-
923            unknown-type blocks of info about structured data.  `type_code'
924            has been set to the proper TYPE_CODE, if we know it.  */
925       structured_common:
926         found_ecoff_debugging_info = 1;
927         push_parse_stack ();
928         top_stack->blocktype = stBlock;
929
930         /* First count the number of fields and the highest value. */
931         nfields = 0;
932         max_value = 0;
933         for (ext_tsym = ext_sh + external_sym_size;
934              ;
935              ext_tsym += external_sym_size)
936           {
937             SYMR tsym;
938
939             (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
940
941             switch (tsym.st)
942               {
943               case stEnd:
944                 goto end_of_fields;
945
946               case stMember:
947                 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
948                   {
949                     /* If the type of the member is Nil (or Void),
950                        without qualifiers, assume the tag is an
951                        enumeration.
952                        Alpha cc -migrate enums are recognized by a zero
953                        index and a zero symbol value.
954                        DU 4.0 cc enums are recognized by a member type of
955                        btEnum without qualifiers and a zero symbol value.  */
956                     if (tsym.index == indexNil
957                         || (tsym.index == 0 && sh->value == 0))
958                       type_code = TYPE_CODE_ENUM;
959                     else
960                       {
961                         (*debug_swap->swap_tir_in) (bigend,
962                                                     &ax[tsym.index].a_ti,
963                                                     &tir);
964                         if ((tir.bt == btNil || tir.bt == btVoid
965                              || (tir.bt == btEnum && sh->value == 0))
966                             && tir.tq0 == tqNil)
967                           type_code = TYPE_CODE_ENUM;
968                       }
969                   }
970                 nfields++;
971                 if (tsym.value > max_value)
972                   max_value = tsym.value;
973                 break;
974
975               case stBlock:
976               case stUnion:
977               case stEnum:
978               case stStruct:
979                 {
980 #if 0
981                   /* This is a no-op; is it trying to tell us something
982                      we should be checking?  */
983                   if (tsym.sc == scVariant);    /*UNIMPLEMENTED */
984 #endif
985                   if (tsym.index != 0)
986                     {
987                       /* This is something like a struct within a
988                          struct.  Skip over the fields of the inner
989                          struct.  The -1 is because the for loop will
990                          increment ext_tsym.  */
991                       ext_tsym = ((char *) debug_info->external_sym
992                                   + ((cur_fdr->isymBase + tsym.index - 1)
993                                      * external_sym_size));
994                     }
995                 }
996                 break;
997
998               case stTypedef:
999                 /* mips cc puts out a typedef for struct x if it is not yet
1000                    defined when it encounters
1001                    struct y { struct x *xp; };
1002                    Just ignore it. */
1003                 break;
1004
1005               case stIndirect:
1006                 /* Irix5 cc puts out a stIndirect for struct x if it is not
1007                    yet defined when it encounters
1008                    struct y { struct x *xp; };
1009                    Just ignore it. */
1010                 break;
1011
1012               default:
1013                 complain (&block_member_complaint, tsym.st);
1014               }
1015           }
1016       end_of_fields:;
1017
1018         /* In an stBlock, there is no way to distinguish structs,
1019            unions, and enums at this point.  This is a bug in the
1020            original design (that has been fixed with the recent
1021            addition of the stStruct, stUnion, and stEnum symbol
1022            types.)  The way you can tell is if/when you see a variable
1023            or field of that type.  In that case the variable's type
1024            (in the AUX table) says if the type is struct, union, or
1025            enum, and points back to the stBlock here.  So you can
1026            patch the tag kind up later - but only if there actually is
1027            a variable or field of that type.
1028
1029            So until we know for sure, we will guess at this point.
1030            The heuristic is:
1031            If the first member has index==indexNil or a void type,
1032            assume we have an enumeration.
1033            Otherwise, if there is more than one member, and all
1034            the members have offset 0, assume we have a union.
1035            Otherwise, assume we have a struct.
1036
1037            The heuristic could guess wrong in the case of of an
1038            enumeration with no members or a union with one (or zero)
1039            members, or when all except the last field of a struct have
1040            width zero.  These are uncommon and/or illegal situations,
1041            and in any case guessing wrong probably doesn't matter
1042            much.
1043
1044            But if we later do find out we were wrong, we fixup the tag
1045            kind.  Members of an enumeration must be handled
1046            differently from struct/union fields, and that is harder to
1047            patch up, but luckily we shouldn't need to.  (If there are
1048            any enumeration members, we can tell for sure it's an enum
1049            here.) */
1050
1051         if (type_code == TYPE_CODE_UNDEF)
1052           {
1053             if (nfields > 1 && max_value == 0)
1054               type_code = TYPE_CODE_UNION;
1055             else
1056               type_code = TYPE_CODE_STRUCT;
1057           }
1058
1059         /* Create a new type or use the pending type.  */
1060         pend = is_pending_symbol (cur_fdr, ext_sh);
1061         if (pend == (struct mdebug_pending *) NULL)
1062           {
1063             t = new_type (NULL);
1064             add_pending (cur_fdr, ext_sh, t);
1065           }
1066         else
1067           t = pend->t;
1068
1069         /* Do not set the tag name if it is a compiler generated tag name
1070            (.Fxx or .xxfake or empty) for unnamed struct/union/enums.
1071            Alpha cc puts out an sh->iss of zero for those.  */
1072         if (sh->iss == 0 || name[0] == '.' || name[0] == '\0')
1073           TYPE_TAG_NAME (t) = NULL;
1074         else
1075           TYPE_TAG_NAME (t) = obconcat (&current_objfile->symbol_obstack,
1076                                         "", "", name);
1077
1078         TYPE_CODE (t) = type_code;
1079         TYPE_LENGTH (t) = sh->value;
1080         TYPE_NFIELDS (t) = nfields;
1081         TYPE_FIELDS (t) = f = ((struct field *)
1082                                TYPE_ALLOC (t,
1083                                            nfields * sizeof (struct field)));
1084
1085         if (type_code == TYPE_CODE_ENUM)
1086           {
1087             int unsigned_enum = 1;
1088
1089             /* This is a non-empty enum. */
1090
1091             /* DEC c89 has the number of enumerators in the sh.value field,
1092                not the type length, so we have to compensate for that
1093                incompatibility quirk.
1094                This might do the wrong thing for an enum with one or two
1095                enumerators and gcc -gcoff -fshort-enums, but these cases
1096                are hopefully rare enough.
1097                Alpha cc -migrate has a sh.value field of zero, we adjust
1098                that too.  */
1099             if (TYPE_LENGTH (t) == TYPE_NFIELDS (t)
1100                 || TYPE_LENGTH (t) == 0)
1101               TYPE_LENGTH (t) = TARGET_INT_BIT / HOST_CHAR_BIT;
1102             for (ext_tsym = ext_sh + external_sym_size;
1103                  ;
1104                  ext_tsym += external_sym_size)
1105               {
1106                 SYMR tsym;
1107                 struct symbol *enum_sym;
1108
1109                 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
1110
1111                 if (tsym.st != stMember)
1112                   break;
1113
1114                 FIELD_BITPOS (*f) = tsym.value;
1115                 FIELD_TYPE (*f) = t;
1116                 FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss;
1117                 FIELD_BITSIZE (*f) = 0;
1118
1119                 enum_sym = ((struct symbol *)
1120                             obstack_alloc (&current_objfile->symbol_obstack,
1121                                            sizeof (struct symbol)));
1122                 memset ((PTR) enum_sym, 0, sizeof (struct symbol));
1123                 SYMBOL_NAME (enum_sym) =
1124                   obsavestring (f->name, strlen (f->name),
1125                                 &current_objfile->symbol_obstack);
1126                 SYMBOL_CLASS (enum_sym) = LOC_CONST;
1127                 SYMBOL_TYPE (enum_sym) = t;
1128                 SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
1129                 SYMBOL_VALUE (enum_sym) = tsym.value;
1130                 if (SYMBOL_VALUE (enum_sym) < 0)
1131                   unsigned_enum = 0;
1132                 add_symbol (enum_sym, top_stack->cur_block);
1133
1134                 /* Skip the stMembers that we've handled. */
1135                 count++;
1136                 f++;
1137               }
1138             if (unsigned_enum)
1139               TYPE_FLAGS (t) |= TYPE_FLAG_UNSIGNED;
1140           }
1141         /* make this the current type */
1142         top_stack->cur_type = t;
1143         top_stack->cur_field = 0;
1144
1145         /* Do not create a symbol for alpha cc unnamed structs.  */
1146         if (sh->iss == 0)
1147           break;
1148
1149         /* gcc puts out an empty struct for an opaque struct definitions,
1150            do not create a symbol for it either.  */
1151         if (TYPE_NFIELDS (t) == 0)
1152           {
1153             TYPE_FLAGS (t) |= TYPE_FLAG_STUB;
1154             break;
1155           }
1156
1157         s = new_symbol (name);
1158         SYMBOL_NAMESPACE (s) = STRUCT_NAMESPACE;
1159         SYMBOL_CLASS (s) = LOC_TYPEDEF;
1160         SYMBOL_VALUE (s) = 0;
1161         SYMBOL_TYPE (s) = t;
1162         add_symbol (s, top_stack->cur_block);
1163         break;
1164
1165         /* End of local variables shared by struct, union, enum, and
1166            block (as yet unknown struct/union/enum) processing.  */
1167       }
1168
1169     case_stBlock_code:
1170       found_ecoff_debugging_info = 1;
1171       /* beginnning of (code) block. Value of symbol
1172          is the displacement from procedure start */
1173       push_parse_stack ();
1174
1175       /* Do not start a new block if this is the outermost block of a
1176          procedure.  This allows the LOC_BLOCK symbol to point to the
1177          block with the local variables, so funcname::var works.  */
1178       if (top_stack->blocktype == stProc
1179           || top_stack->blocktype == stStaticProc)
1180         {
1181           top_stack->blocktype = stNil;
1182           break;
1183         }
1184
1185       top_stack->blocktype = stBlock;
1186       b = new_block (top_stack->maxsyms);
1187       BLOCK_START (b) = sh->value + top_stack->procadr;
1188       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1189       top_stack->cur_block = b;
1190       add_block (b, top_stack->cur_st);
1191       break;
1192
1193     case stEnd:         /* end (of anything) */
1194       if (sh->sc == scInfo || SC_IS_COMMON (sh->sc))
1195         {
1196           /* Finished with type */
1197           top_stack->cur_type = 0;
1198         }
1199       else if (sh->sc == scText &&
1200                (top_stack->blocktype == stProc ||
1201                 top_stack->blocktype == stStaticProc))
1202         {
1203           /* Finished with procedure */
1204           struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
1205           struct mips_extra_func_info *e;
1206           struct block *b;
1207           struct type *ftype = top_stack->cur_type;
1208           int i;
1209
1210           BLOCK_END (top_stack->cur_block) += sh->value;        /* size */
1211
1212           /* Make up special symbol to contain procedure specific info */
1213           s = new_symbol (MIPS_EFI_SYMBOL_NAME);
1214           SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
1215           SYMBOL_CLASS (s) = LOC_CONST;
1216           SYMBOL_TYPE (s) = mdebug_type_void;
1217           e = ((struct mips_extra_func_info *)
1218                obstack_alloc (&current_objfile->symbol_obstack,
1219                               sizeof (struct mips_extra_func_info)));
1220           memset ((PTR) e, 0, sizeof (struct mips_extra_func_info));
1221           SYMBOL_VALUE (s) = (long) e;
1222           e->numargs = top_stack->numargs;
1223           e->pdr.framereg = -1;
1224           add_symbol (s, top_stack->cur_block);
1225
1226           /* Reallocate symbols, saving memory */
1227           b = shrink_block (top_stack->cur_block, top_stack->cur_st);
1228
1229           /* f77 emits proc-level with address bounds==[0,0],
1230              So look for such child blocks, and patch them.  */
1231           for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
1232             {
1233               struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
1234               if (BLOCK_SUPERBLOCK (b_bad) == b
1235                   && BLOCK_START (b_bad) == top_stack->procadr
1236                   && BLOCK_END (b_bad) == top_stack->procadr)
1237                 {
1238                   BLOCK_START (b_bad) = BLOCK_START (b);
1239                   BLOCK_END (b_bad) = BLOCK_END (b);
1240                 }
1241             }
1242
1243           if (TYPE_NFIELDS (ftype) <= 0)
1244             {
1245               /* No parameter type information is recorded with the function's
1246                  type.  Set that from the type of the parameter symbols. */
1247               int nparams = top_stack->numargs;
1248               int iparams;
1249               struct symbol *sym;
1250
1251               if (nparams > 0)
1252                 {
1253                   TYPE_NFIELDS (ftype) = nparams;
1254                   TYPE_FIELDS (ftype) = (struct field *)
1255                     TYPE_ALLOC (ftype, nparams * sizeof (struct field));
1256
1257                   for (i = iparams = 0; iparams < nparams; i++)
1258                     {
1259                       sym = BLOCK_SYM (b, i);
1260                       switch (SYMBOL_CLASS (sym))
1261                         {
1262                         case LOC_ARG:
1263                         case LOC_REF_ARG:
1264                         case LOC_REGPARM:
1265                         case LOC_REGPARM_ADDR:
1266                           TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
1267                           iparams++;
1268                           break;
1269                         default:
1270                           break;
1271                         }
1272                     }
1273                 }
1274             }
1275         }
1276       else if (sh->sc == scText && top_stack->blocktype == stBlock)
1277         {
1278           /* End of (code) block. The value of the symbol is the
1279              displacement from the procedure`s start address of the
1280              end of this block. */
1281           BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
1282           shrink_block (top_stack->cur_block, top_stack->cur_st);
1283         }
1284       else if (sh->sc == scText && top_stack->blocktype == stNil)
1285         {
1286           /* End of outermost block.  Pop parse stack and ignore.  The
1287              following stEnd of stProc will take care of the block.  */
1288           ;
1289         }
1290       else if (sh->sc == scText && top_stack->blocktype == stFile)
1291         {
1292           /* End of file.  Pop parse stack and ignore.  Higher
1293              level code deals with this.  */
1294           ;
1295         }
1296       else
1297         complain (&stEnd_complaint, sh->sc);
1298
1299       pop_parse_stack ();       /* restore previous lexical context */
1300       break;
1301
1302     case stMember:              /* member of struct or union */
1303       f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++];
1304       FIELD_NAME (*f) = name;
1305       FIELD_BITPOS (*f) = sh->value;
1306       bitsize = 0;
1307       FIELD_TYPE (*f) = parse_type (cur_fd, ax, sh->index, &bitsize, bigend, name);
1308       FIELD_BITSIZE (*f) = bitsize;
1309       break;
1310
1311     case stIndirect:            /* forward declaration on Irix5 */
1312       /* Forward declarations from Irix5 cc are handled by cross_ref,
1313          skip them.  */
1314       break;
1315
1316     case stTypedef:             /* type definition */
1317       found_ecoff_debugging_info = 1;
1318
1319       /* Typedefs for forward declarations and opaque structs from alpha cc
1320          are handled by cross_ref, skip them.  */
1321       if (sh->iss == 0)
1322         break;
1323
1324       /* Parse the type or use the pending type.  */
1325       pend = is_pending_symbol (cur_fdr, ext_sh);
1326       if (pend == (struct mdebug_pending *) NULL)
1327         {
1328           t = parse_type (cur_fd, ax, sh->index, (int *) NULL, bigend, name);
1329           add_pending (cur_fdr, ext_sh, t);
1330         }
1331       else
1332         t = pend->t;
1333
1334       /* mips cc puts out a typedef with the name of the struct for forward
1335          declarations. These should not go into the symbol table and
1336          TYPE_NAME should not be set for them.
1337          They can't be distinguished from an intentional typedef to
1338          the same name however:
1339          x.h:
1340          struct x { int ix; int jx; };
1341          struct xx;
1342          x.c:
1343          typedef struct x x;
1344          struct xx {int ixx; int jxx; };
1345          generates a cross referencing stTypedef for x and xx.
1346          The user visible effect of this is that the type of a pointer
1347          to struct foo sometimes is given as `foo *' instead of `struct foo *'.
1348          The problem is fixed with alpha cc and Irix5 cc.  */
1349
1350       /* However if the typedef cross references to an opaque aggregate, it
1351          is safe to omit it from the symbol table.  */
1352
1353       if (has_opaque_xref (cur_fdr, sh))
1354         break;
1355       s = new_symbol (name);
1356       SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1357       SYMBOL_CLASS (s) = LOC_TYPEDEF;
1358       SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
1359       SYMBOL_TYPE (s) = t;
1360       add_symbol (s, top_stack->cur_block);
1361
1362       /* Incomplete definitions of structs should not get a name.  */
1363       if (TYPE_NAME (SYMBOL_TYPE (s)) == NULL
1364           && (TYPE_NFIELDS (SYMBOL_TYPE (s)) != 0
1365               || (TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_STRUCT
1366                   && TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_UNION)))
1367         {
1368           if (TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_PTR
1369               || TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_FUNC)
1370             {
1371               /* If we are giving a name to a type such as "pointer to
1372                  foo" or "function returning foo", we better not set
1373                  the TYPE_NAME.  If the program contains "typedef char
1374                  *caddr_t;", we don't want all variables of type char
1375                  * to print as caddr_t.  This is not just a
1376                  consequence of GDB's type management; CC and GCC (at
1377                  least through version 2.4) both output variables of
1378                  either type char * or caddr_t with the type
1379                  refering to the stTypedef symbol for caddr_t.  If a future
1380                  compiler cleans this up it GDB is not ready for it
1381                  yet, but if it becomes ready we somehow need to
1382                  disable this check (without breaking the PCC/GCC2.4
1383                  case).
1384
1385                  Sigh.
1386
1387                  Fortunately, this check seems not to be necessary
1388                  for anything except pointers or functions.  */
1389             }
1390           else
1391             TYPE_NAME (SYMBOL_TYPE (s)) = SYMBOL_NAME (s);
1392         }
1393       break;
1394
1395     case stFile:                /* file name */
1396       push_parse_stack ();
1397       top_stack->blocktype = sh->st;
1398       break;
1399
1400       /* I`ve never seen these for C */
1401     case stRegReloc:
1402       break;                    /* register relocation */
1403     case stForward:
1404       break;                    /* forwarding address */
1405     case stConstant:
1406       break;                    /* constant */
1407     default:
1408       complain (&unknown_mdebug_symtype_complaint, sh->st);
1409       break;
1410     }
1411
1412   return count;
1413 }
1414
1415 /* Parse the type information provided in the raw AX entries for
1416    the symbol SH. Return the bitfield size in BS, in case.
1417    We must byte-swap the AX entries before we use them; BIGEND says whether
1418    they are big-endian or little-endian (from fh->fBigendian).  */
1419
1420 static struct type *
1421 parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
1422             int bigend, char *sym_name)
1423 {
1424   /* Null entries in this map are treated specially */
1425   static struct type **map_bt[] =
1426   {
1427     &mdebug_type_void,          /* btNil */
1428     &mdebug_type_adr_32,        /* btAdr */
1429     &mdebug_type_char,          /* btChar */
1430     &mdebug_type_unsigned_char, /* btUChar */
1431     &mdebug_type_short,         /* btShort */
1432     &mdebug_type_unsigned_short,        /* btUShort */
1433     &mdebug_type_int_32,        /* btInt */
1434     &mdebug_type_unsigned_int_32,       /* btUInt */
1435     &mdebug_type_long_32,       /* btLong */
1436     &mdebug_type_unsigned_long_32,      /* btULong */
1437     &mdebug_type_float,         /* btFloat */
1438     &mdebug_type_double,        /* btDouble */
1439     0,                          /* btStruct */
1440     0,                          /* btUnion */
1441     0,                          /* btEnum */
1442     0,                          /* btTypedef */
1443     0,                          /* btRange */
1444     0,                          /* btSet */
1445     &mdebug_type_complex,       /* btComplex */
1446     &mdebug_type_double_complex,        /* btDComplex */
1447     0,                          /* btIndirect */
1448     &mdebug_type_fixed_dec,     /* btFixedDec */
1449     &mdebug_type_float_dec,     /* btFloatDec */
1450     &mdebug_type_string,        /* btString */
1451     0,                          /* btBit */
1452     0,                          /* btPicture */
1453     &mdebug_type_void,          /* btVoid */
1454     0,                          /* DEC C++:  Pointer to member */
1455     0,                          /* DEC C++:  Virtual function table */
1456     0,                          /* DEC C++:  Class (Record) */
1457     &mdebug_type_long_64,       /* btLong64  */
1458     &mdebug_type_unsigned_long_64,      /* btULong64 */
1459     &mdebug_type_long_long_64,  /* btLongLong64  */
1460     &mdebug_type_unsigned_long_long_64,         /* btULongLong64 */
1461     &mdebug_type_adr_64,        /* btAdr64 */
1462     &mdebug_type_int_64,        /* btInt64  */
1463     &mdebug_type_unsigned_int_64,       /* btUInt64 */
1464   };
1465
1466   TIR t[1];
1467   struct type *tp = 0;
1468   enum type_code type_code = TYPE_CODE_UNDEF;
1469
1470   /* Handle undefined types, they have indexNil. */
1471   if (aux_index == indexNil)
1472     return mdebug_type_int;
1473
1474   /* Handle corrupt aux indices.  */
1475   if (aux_index >= (debug_info->fdr + fd)->caux)
1476     {
1477       complain (&index_complaint, sym_name);
1478       return mdebug_type_int;
1479     }
1480   ax += aux_index;
1481
1482   /* Use aux as a type information record, map its basic type.  */
1483   (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
1484   if (t->bt >= (sizeof (map_bt) / sizeof (*map_bt)))
1485     {
1486       complain (&basic_type_complaint, t->bt, sym_name);
1487       return mdebug_type_int;
1488     }
1489   if (map_bt[t->bt])
1490     {
1491       tp = *map_bt[t->bt];
1492     }
1493   else
1494     {
1495       tp = NULL;
1496       /* Cannot use builtin types -- build our own */
1497       switch (t->bt)
1498         {
1499         case btStruct:
1500           type_code = TYPE_CODE_STRUCT;
1501           break;
1502         case btUnion:
1503           type_code = TYPE_CODE_UNION;
1504           break;
1505         case btEnum:
1506           type_code = TYPE_CODE_ENUM;
1507           break;
1508         case btRange:
1509           type_code = TYPE_CODE_RANGE;
1510           break;
1511         case btSet:
1512           type_code = TYPE_CODE_SET;
1513           break;
1514         case btIndirect:
1515           /* alpha cc -migrate uses this for typedefs. The true type will
1516              be obtained by crossreferencing below.  */
1517           type_code = TYPE_CODE_ERROR;
1518           break;
1519         case btTypedef:
1520           /* alpha cc uses this for typedefs. The true type will be
1521              obtained by crossreferencing below.  */
1522           type_code = TYPE_CODE_ERROR;
1523           break;
1524         default:
1525           complain (&basic_type_complaint, t->bt, sym_name);
1526           return mdebug_type_int;
1527         }
1528     }
1529
1530   /* Move on to next aux */
1531   ax++;
1532
1533   if (t->fBitfield)
1534     {
1535       int width = AUX_GET_WIDTH (bigend, ax);
1536
1537       /* Inhibit core dumps with some cfront generated objects that
1538          corrupt the TIR.  */
1539       if (bs == (int *) NULL)
1540         {
1541           /* Alpha cc -migrate encodes char and unsigned char types
1542              as short and unsigned short types with a field width of 8.
1543              Enum types also have a field width which we ignore for now.  */
1544           if (t->bt == btShort && width == 8)
1545             tp = mdebug_type_char;
1546           else if (t->bt == btUShort && width == 8)
1547             tp = mdebug_type_unsigned_char;
1548           else if (t->bt == btEnum)
1549             ;
1550           else
1551             complain (&bad_fbitfield_complaint, sym_name);
1552         }
1553       else
1554         *bs = width;
1555       ax++;
1556     }
1557
1558   /* A btIndirect entry cross references to an aux entry containing
1559      the type.  */
1560   if (t->bt == btIndirect)
1561     {
1562       RNDXR rn[1];
1563       int rf;
1564       FDR *xref_fh;
1565       int xref_fd;
1566
1567       (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
1568       ax++;
1569       if (rn->rfd == 0xfff)
1570         {
1571           rf = AUX_GET_ISYM (bigend, ax);
1572           ax++;
1573         }
1574       else
1575         rf = rn->rfd;
1576
1577       if (rf == -1)
1578         {
1579           complain (&bad_indirect_xref_complaint, sym_name);
1580           return mdebug_type_int;
1581         }
1582       xref_fh = get_rfd (fd, rf);
1583       xref_fd = xref_fh - debug_info->fdr;
1584       tp = parse_type (xref_fd, debug_info->external_aux + xref_fh->iauxBase,
1585                     rn->index, (int *) NULL, xref_fh->fBigendian, sym_name);
1586     }
1587
1588   /* All these types really point to some (common) MIPS type
1589      definition, and only the type-qualifiers fully identify
1590      them.  We'll make the same effort at sharing. */
1591   if (t->bt == btStruct ||
1592       t->bt == btUnion ||
1593       t->bt == btEnum ||
1594
1595   /* btSet (I think) implies that the name is a tag name, not a typedef
1596      name.  This apparently is a MIPS extension for C sets.  */
1597       t->bt == btSet)
1598     {
1599       char *name;
1600
1601       /* Try to cross reference this type, build new type on failure.  */
1602       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1603       if (tp == (struct type *) NULL)
1604         tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
1605
1606       /* DEC c89 produces cross references to qualified aggregate types,
1607          dereference them.  */
1608       while (TYPE_CODE (tp) == TYPE_CODE_PTR
1609              || TYPE_CODE (tp) == TYPE_CODE_ARRAY)
1610         tp = tp->target_type;
1611
1612       /* Make sure that TYPE_CODE(tp) has an expected type code.
1613          Any type may be returned from cross_ref if file indirect entries
1614          are corrupted.  */
1615       if (TYPE_CODE (tp) != TYPE_CODE_STRUCT
1616           && TYPE_CODE (tp) != TYPE_CODE_UNION
1617           && TYPE_CODE (tp) != TYPE_CODE_ENUM)
1618         {
1619           complain (&unexpected_type_code_complaint, sym_name);
1620         }
1621       else
1622         {
1623
1624           /* Usually, TYPE_CODE(tp) is already type_code.  The main
1625              exception is if we guessed wrong re struct/union/enum.
1626              But for struct vs. union a wrong guess is harmless, so
1627              don't complain().  */
1628           if ((TYPE_CODE (tp) == TYPE_CODE_ENUM
1629                && type_code != TYPE_CODE_ENUM)
1630               || (TYPE_CODE (tp) != TYPE_CODE_ENUM
1631                   && type_code == TYPE_CODE_ENUM))
1632             {
1633               complain (&bad_tag_guess_complaint, sym_name);
1634             }
1635
1636           if (TYPE_CODE (tp) != type_code)
1637             {
1638               TYPE_CODE (tp) = type_code;
1639             }
1640
1641           /* Do not set the tag name if it is a compiler generated tag name
1642              (.Fxx or .xxfake or empty) for unnamed struct/union/enums.  */
1643           if (name[0] == '.' || name[0] == '\0')
1644             TYPE_TAG_NAME (tp) = NULL;
1645           else if (TYPE_TAG_NAME (tp) == NULL
1646                    || !STREQ (TYPE_TAG_NAME (tp), name))
1647             TYPE_TAG_NAME (tp) = obsavestring (name, strlen (name),
1648                                             &current_objfile->type_obstack);
1649         }
1650     }
1651
1652   /* All these types really point to some (common) MIPS type
1653      definition, and only the type-qualifiers fully identify
1654      them.  We'll make the same effort at sharing.
1655      FIXME: We are not doing any guessing on range types.  */
1656   if (t->bt == btRange)
1657     {
1658       char *name;
1659
1660       /* Try to cross reference this type, build new type on failure.  */
1661       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1662       if (tp == (struct type *) NULL)
1663         tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
1664
1665       /* Make sure that TYPE_CODE(tp) has an expected type code.
1666          Any type may be returned from cross_ref if file indirect entries
1667          are corrupted.  */
1668       if (TYPE_CODE (tp) != TYPE_CODE_RANGE)
1669         {
1670           complain (&unexpected_type_code_complaint, sym_name);
1671         }
1672       else
1673         {
1674           /* Usually, TYPE_CODE(tp) is already type_code.  The main
1675              exception is if we guessed wrong re struct/union/enum. */
1676           if (TYPE_CODE (tp) != type_code)
1677             {
1678               complain (&bad_tag_guess_complaint, sym_name);
1679               TYPE_CODE (tp) = type_code;
1680             }
1681           if (TYPE_NAME (tp) == NULL || !STREQ (TYPE_NAME (tp), name))
1682             TYPE_NAME (tp) = obsavestring (name, strlen (name),
1683                                            &current_objfile->type_obstack);
1684         }
1685     }
1686   if (t->bt == btTypedef)
1687     {
1688       char *name;
1689
1690       /* Try to cross reference this type, it should succeed.  */
1691       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1692       if (tp == (struct type *) NULL)
1693         {
1694           complain (&unable_to_cross_ref_complaint, sym_name);
1695           tp = mdebug_type_int;
1696         }
1697     }
1698
1699   /* Deal with range types */
1700   if (t->bt == btRange)
1701     {
1702       TYPE_NFIELDS (tp) = 2;
1703       TYPE_FIELDS (tp) = ((struct field *)
1704                           TYPE_ALLOC (tp, 2 * sizeof (struct field)));
1705       TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
1706                                             &current_objfile->type_obstack);
1707       TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
1708       ax++;
1709       TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
1710                                             &current_objfile->type_obstack);
1711       TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
1712       ax++;
1713     }
1714
1715   /* Parse all the type qualifiers now. If there are more
1716      than 6 the game will continue in the next aux */
1717
1718   while (1)
1719     {
1720 #define PARSE_TQ(tq) \
1721       if (t->tq != tqNil) \
1722         ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
1723       else \
1724         break;
1725
1726       PARSE_TQ (tq0);
1727       PARSE_TQ (tq1);
1728       PARSE_TQ (tq2);
1729       PARSE_TQ (tq3);
1730       PARSE_TQ (tq4);
1731       PARSE_TQ (tq5);
1732 #undef  PARSE_TQ
1733
1734       /* mips cc 2.x and gcc never put out continued aux entries.  */
1735       if (!t->continued)
1736         break;
1737
1738       (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
1739       ax++;
1740     }
1741
1742   /* Complain for illegal continuations due to corrupt aux entries.  */
1743   if (t->continued)
1744     complain (&bad_continued_complaint, sym_name);
1745
1746   return tp;
1747 }
1748
1749 /* Make up a complex type from a basic one.  Type is passed by
1750    reference in TPP and side-effected as necessary. The type
1751    qualifier TQ says how to handle the aux symbols at AX for
1752    the symbol SX we are currently analyzing.  BIGEND says whether
1753    aux symbols are big-endian or little-endian.
1754    Returns the number of aux symbols we parsed. */
1755
1756 static int
1757 upgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend,
1758               char *sym_name)
1759 {
1760   int off;
1761   struct type *t;
1762
1763   /* Used in array processing */
1764   int rf, id;
1765   FDR *fh;
1766   struct type *range;
1767   struct type *indx;
1768   int lower, upper;
1769   RNDXR rndx;
1770
1771   switch (tq)
1772     {
1773     case tqPtr:
1774       t = lookup_pointer_type (*tpp);
1775       *tpp = t;
1776       return 0;
1777
1778     case tqProc:
1779       t = lookup_function_type (*tpp);
1780       *tpp = t;
1781       return 0;
1782
1783     case tqArray:
1784       off = 0;
1785
1786       /* Determine and record the domain type (type of index) */
1787       (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, &rndx);
1788       id = rndx.index;
1789       rf = rndx.rfd;
1790       if (rf == 0xfff)
1791         {
1792           ax++;
1793           rf = AUX_GET_ISYM (bigend, ax);
1794           off++;
1795         }
1796       fh = get_rfd (fd, rf);
1797
1798       indx = parse_type (fh - debug_info->fdr,
1799                          debug_info->external_aux + fh->iauxBase,
1800                          id, (int *) NULL, bigend, sym_name);
1801
1802       /* The bounds type should be an integer type, but might be anything
1803          else due to corrupt aux entries.  */
1804       if (TYPE_CODE (indx) != TYPE_CODE_INT)
1805         {
1806           complain (&array_index_type_complaint, sym_name);
1807           indx = mdebug_type_int;
1808         }
1809
1810       /* Get the bounds, and create the array type.  */
1811       ax++;
1812       lower = AUX_GET_DNLOW (bigend, ax);
1813       ax++;
1814       upper = AUX_GET_DNHIGH (bigend, ax);
1815       ax++;
1816       rf = AUX_GET_WIDTH (bigend, ax);  /* bit size of array element */
1817
1818       range = create_range_type ((struct type *) NULL, indx,
1819                                  lower, upper);
1820
1821       t = create_array_type ((struct type *) NULL, *tpp, range);
1822
1823       /* We used to fill in the supplied array element bitsize
1824          here if the TYPE_LENGTH of the target type was zero.
1825          This happens for a `pointer to an array of anonymous structs',
1826          but in this case the array element bitsize is also zero,
1827          so nothing is gained.
1828          And we used to check the TYPE_LENGTH of the target type against
1829          the supplied array element bitsize.
1830          gcc causes a mismatch for `pointer to array of object',
1831          since the sdb directives it uses do not have a way of
1832          specifying the bitsize, but it does no harm (the
1833          TYPE_LENGTH should be correct) and we should be able to
1834          ignore the erroneous bitsize from the auxiliary entry safely.
1835          dbx seems to ignore it too.  */
1836
1837       /* TYPE_FLAG_TARGET_STUB now takes care of the zero TYPE_LENGTH
1838          problem.  */
1839       if (TYPE_LENGTH (*tpp) == 0)
1840         {
1841           TYPE_FLAGS (t) |= TYPE_FLAG_TARGET_STUB;
1842         }
1843
1844       *tpp = t;
1845       return 4 + off;
1846
1847     case tqVol:
1848       /* Volatile -- currently ignored */
1849       return 0;
1850
1851     case tqConst:
1852       /* Const -- currently ignored */
1853       return 0;
1854
1855     default:
1856       complain (&unknown_type_qual_complaint, tq);
1857       return 0;
1858     }
1859 }
1860
1861
1862 /* Parse a procedure descriptor record PR.  Note that the procedure is
1863    parsed _after_ the local symbols, now we just insert the extra
1864    information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1865    already been placed in the procedure's main block.  Note also that
1866    images that have been partially stripped (ld -x) have been deprived
1867    of local symbols, and we have to cope with them here.  FIRST_OFF is
1868    the offset of the first procedure for this FDR; we adjust the
1869    address by this amount, but I don't know why.  SEARCH_SYMTAB is the symtab
1870    to look for the function which contains the MIPS_EFI_SYMBOL_NAME symbol
1871    in question, or NULL to use top_stack->cur_block.  */
1872
1873 static void parse_procedure (PDR *, struct symtab *, struct partial_symtab *);
1874
1875 static void
1876 parse_procedure (PDR *pr, struct symtab *search_symtab,
1877                  struct partial_symtab *pst)
1878 {
1879   struct symbol *s, *i;
1880   struct block *b;
1881   struct mips_extra_func_info *e;
1882   char *sh_name;
1883
1884   /* Simple rule to find files linked "-x" */
1885   if (cur_fdr->rss == -1)
1886     {
1887       if (pr->isym == -1)
1888         {
1889           /* Static procedure at address pr->adr.  Sigh. */
1890           /* FIXME-32x64.  assuming pr->adr fits in long.  */
1891           complain (&pdr_static_symbol_complaint, (unsigned long) pr->adr);
1892           return;
1893         }
1894       else
1895         {
1896           /* external */
1897           EXTR she;
1898
1899           (*debug_swap->swap_ext_in) (cur_bfd,
1900                                       ((char *) debug_info->external_ext
1901                                        + (pr->isym
1902                                           * debug_swap->external_ext_size)),
1903                                       &she);
1904           sh_name = debug_info->ssext + she.asym.iss;
1905         }
1906     }
1907   else
1908     {
1909       /* Full symbols */
1910       SYMR sh;
1911
1912       (*debug_swap->swap_sym_in) (cur_bfd,
1913                                   ((char *) debug_info->external_sym
1914                                    + ((cur_fdr->isymBase + pr->isym)
1915                                       * debug_swap->external_sym_size)),
1916                                   &sh);
1917       sh_name = debug_info->ss + cur_fdr->issBase + sh.iss;
1918     }
1919
1920   if (search_symtab != NULL)
1921     {
1922 #if 0
1923       /* This loses both in the case mentioned (want a static, find a global),
1924          but also if we are looking up a non-mangled name which happens to
1925          match the name of a mangled function.  */
1926       /* We have to save the cur_fdr across the call to lookup_symbol.
1927          If the pdr is for a static function and if a global function with
1928          the same name exists, lookup_symbol will eventually read in the symtab
1929          for the global function and clobber cur_fdr.  */
1930       FDR *save_cur_fdr = cur_fdr;
1931       s = lookup_symbol (sh_name, NULL, VAR_NAMESPACE, 0, NULL);
1932       cur_fdr = save_cur_fdr;
1933 #else
1934       s = mylookup_symbol
1935         (sh_name,
1936          BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab), STATIC_BLOCK),
1937          VAR_NAMESPACE,
1938          LOC_BLOCK);
1939 #endif
1940     }
1941   else
1942     s = mylookup_symbol (sh_name, top_stack->cur_block,
1943                          VAR_NAMESPACE, LOC_BLOCK);
1944
1945   if (s != 0)
1946     {
1947       b = SYMBOL_BLOCK_VALUE (s);
1948     }
1949   else
1950     {
1951       complain (&pdr_for_nonsymbol_complaint, sh_name);
1952 #if 1
1953       return;
1954 #else
1955 /* FIXME -- delete.  We can't do symbol allocation now; it's all done.  */
1956       s = new_symbol (sh_name);
1957       SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1958       SYMBOL_CLASS (s) = LOC_BLOCK;
1959       /* Donno its type, hope int is ok */
1960       SYMBOL_TYPE (s) = lookup_function_type (mdebug_type_int);
1961       add_symbol (s, top_stack->cur_block);
1962       /* Wont have symbols for this one */
1963       b = new_block (2);
1964       SYMBOL_BLOCK_VALUE (s) = b;
1965       BLOCK_FUNCTION (b) = s;
1966       BLOCK_START (b) = pr->adr;
1967       /* BOUND used to be the end of procedure's text, but the
1968          argument is no longer passed in.  */
1969       BLOCK_END (b) = bound;
1970       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1971       add_block (b, top_stack->cur_st);
1972 #endif
1973     }
1974
1975   i = mylookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, LOC_CONST);
1976
1977   if (i)
1978     {
1979       e = (struct mips_extra_func_info *) SYMBOL_VALUE (i);
1980       e->pdr = *pr;
1981       e->pdr.isym = (long) s;
1982
1983       /* GDB expects the absolute function start address for the
1984          procedure descriptor in e->pdr.adr.
1985          As the address in the procedure descriptor is usually relative,
1986          we would have to relocate e->pdr.adr with cur_fdr->adr and
1987          ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile)).
1988          Unfortunately cur_fdr->adr and e->pdr.adr are both absolute
1989          in shared libraries on some systems, and on other systems
1990          e->pdr.adr is sometimes offset by a bogus value.
1991          To work around these problems, we replace e->pdr.adr with
1992          the start address of the function.  */
1993       e->pdr.adr = BLOCK_START (b);
1994
1995       /* Correct incorrect setjmp procedure descriptor from the library
1996          to make backtrace through setjmp work.  */
1997       if (e->pdr.pcreg == 0 && STREQ (sh_name, "setjmp"))
1998         {
1999           complain (&bad_setjmp_pdr_complaint, 0);
2000           e->pdr.pcreg = RA_REGNUM;
2001           e->pdr.regmask = 0x80000000;
2002           e->pdr.regoffset = -4;
2003         }
2004     }
2005
2006   /* It would be reasonable that functions that have been compiled
2007      without debugging info have a btNil type for their return value,
2008      and functions that are void and are compiled with debugging info
2009      have btVoid.
2010      gcc and DEC f77 put out btNil types for both cases, so btNil is mapped
2011      to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info'
2012      case right.
2013      The glevel field in cur_fdr could be used to determine the presence
2014      of debugging info, but GCC doesn't always pass the -g switch settings
2015      to the assembler and GAS doesn't set the glevel field from the -g switch
2016      settings.
2017      To work around these problems, the return value type of a TYPE_CODE_VOID
2018      function is adjusted accordingly if no debugging info was found in the
2019      compilation unit.  */
2020
2021   if (processing_gcc_compilation == 0
2022       && found_ecoff_debugging_info == 0
2023       && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (s))) == TYPE_CODE_VOID)
2024     SYMBOL_TYPE (s) = nodebug_func_symbol_type;
2025 }
2026
2027 /* Relocate the extra function info pointed to by the symbol table.  */
2028
2029 void
2030 ecoff_relocate_efi (struct symbol *sym, CORE_ADDR delta)
2031 {
2032   struct mips_extra_func_info *e;
2033
2034   e = (struct mips_extra_func_info *) SYMBOL_VALUE (sym);
2035
2036   e->pdr.adr += delta;
2037 }
2038
2039 /* Parse the external symbol ES. Just call parse_symbol() after
2040    making sure we know where the aux are for it.
2041    BIGEND says whether aux entries are big-endian or little-endian.
2042
2043    This routine clobbers top_stack->cur_block and ->cur_st. */
2044
2045 static void parse_external (EXTR *, int, struct section_offsets *,
2046                             struct objfile *);
2047
2048 static void
2049 parse_external (EXTR *es, int bigend, struct section_offsets *section_offsets,
2050                 struct objfile *objfile)
2051 {
2052   union aux_ext *ax;
2053
2054   if (es->ifd != ifdNil)
2055     {
2056       cur_fd = es->ifd;
2057       cur_fdr = debug_info->fdr + cur_fd;
2058       ax = debug_info->external_aux + cur_fdr->iauxBase;
2059     }
2060   else
2061     {
2062       cur_fdr = debug_info->fdr;
2063       ax = 0;
2064     }
2065
2066   /* Reading .o files */
2067   if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil)
2068     {
2069       char *what;
2070       switch (es->asym.st)
2071         {
2072         case stNil:
2073           /* These are generated for static symbols in .o files,
2074              ignore them.  */
2075           return;
2076         case stStaticProc:
2077         case stProc:
2078           what = "procedure";
2079           n_undef_procs++;
2080           break;
2081         case stGlobal:
2082           what = "variable";
2083           n_undef_vars++;
2084           break;
2085         case stLabel:
2086           what = "label";
2087           n_undef_labels++;
2088           break;
2089         default:
2090           what = "symbol";
2091           break;
2092         }
2093       n_undef_symbols++;
2094       /* FIXME:  Turn this into a complaint? */
2095       if (info_verbose)
2096         printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
2097                          what, debug_info->ssext + es->asym.iss,
2098                          fdr_name (cur_fdr));
2099       return;
2100     }
2101
2102   switch (es->asym.st)
2103     {
2104     case stProc:
2105     case stStaticProc:
2106       /* There is no need to parse the external procedure symbols.
2107          If they are from objects compiled without -g, their index will
2108          be indexNil, and the symbol definition from the minimal symbol
2109          is preferrable (yielding a function returning int instead of int).
2110          If the index points to a local procedure symbol, the local
2111          symbol already provides the correct type.
2112          Note that the index of the external procedure symbol points
2113          to the local procedure symbol in the local symbol table, and
2114          _not_ to the auxiliary symbol info.  */
2115       break;
2116     case stGlobal:
2117     case stLabel:
2118       /* Global common symbols are resolved by the runtime loader,
2119          ignore them.  */
2120       if (SC_IS_COMMON (es->asym.sc))
2121         break;
2122
2123       /* Note that the case of a symbol with indexNil must be handled
2124          anyways by parse_symbol().  */
2125       parse_symbol (&es->asym, ax, (char *) NULL, bigend, section_offsets, objfile);
2126       break;
2127     default:
2128       break;
2129     }
2130 }
2131
2132 /* Parse the line number info for file descriptor FH into
2133    GDB's linetable LT.  MIPS' encoding requires a little bit
2134    of magic to get things out.  Note also that MIPS' line
2135    numbers can go back and forth, apparently we can live
2136    with that and do not need to reorder our linetables */
2137
2138 static void parse_lines (FDR *, PDR *, struct linetable *, int,
2139                          struct partial_symtab *, CORE_ADDR);
2140
2141 static void
2142 parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
2143              struct partial_symtab *pst, CORE_ADDR lowest_pdr_addr)
2144 {
2145   unsigned char *base;
2146   int j, k;
2147   int delta, count, lineno = 0;
2148
2149   if (fh->cbLine == 0)
2150     return;
2151
2152   /* Scan by procedure descriptors */
2153   k = 0;
2154   for (j = 0; j < fh->cpd; j++, pr++)
2155     {
2156       CORE_ADDR l;
2157       CORE_ADDR adr;
2158       unsigned char *halt;
2159
2160       /* No code for this one */
2161       if (pr->iline == ilineNil ||
2162           pr->lnLow == -1 || pr->lnHigh == -1)
2163         continue;
2164
2165       /* Determine start and end address of compressed line bytes for
2166          this procedure.  */
2167       base = debug_info->line + fh->cbLineOffset;
2168       if (j != (fh->cpd - 1))
2169         halt = base + pr[1].cbLineOffset;
2170       else
2171         halt = base + fh->cbLine;
2172       base += pr->cbLineOffset;
2173
2174       adr = pst->textlow + pr->adr - lowest_pdr_addr;
2175
2176       l = adr >> 2;             /* in words */
2177       for (lineno = pr->lnLow; base < halt;)
2178         {
2179           count = *base & 0x0f;
2180           delta = *base++ >> 4;
2181           if (delta >= 8)
2182             delta -= 16;
2183           if (delta == -8)
2184             {
2185               delta = (base[0] << 8) | base[1];
2186               if (delta >= 0x8000)
2187                 delta -= 0x10000;
2188               base += 2;
2189             }
2190           lineno += delta;      /* first delta is 0 */
2191
2192           /* Complain if the line table overflows. Could happen
2193              with corrupt binaries.  */
2194           if (lt->nitems >= maxlines)
2195             {
2196               complain (&bad_linetable_guess_complaint, fdr_name (fh));
2197               break;
2198             }
2199           k = add_line (lt, lineno, l, k);
2200           l += count + 1;
2201         }
2202     }
2203 }
2204 \f
2205 /* Master parsing procedure for first-pass reading of file symbols
2206    into a partial_symtab.  */
2207
2208 static void
2209 parse_partial_symbols (struct objfile *objfile)
2210 {
2211   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
2212   const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
2213   const bfd_size_type external_ext_size = debug_swap->external_ext_size;
2214   void (*const swap_ext_in) (bfd *, PTR, EXTR *) = debug_swap->swap_ext_in;
2215   void (*const swap_sym_in) (bfd *, PTR, SYMR *) = debug_swap->swap_sym_in;
2216   void (*const swap_rfd_in) (bfd *, PTR, RFDT *) = debug_swap->swap_rfd_in;
2217   int f_idx, s_idx;
2218   HDRR *hdr = &debug_info->symbolic_header;
2219   /* Running pointers */
2220   FDR *fh;
2221   char *ext_out;
2222   char *ext_out_end;
2223   EXTR *ext_block;
2224   register EXTR *ext_in;
2225   EXTR *ext_in_end;
2226   SYMR sh;
2227   struct partial_symtab *pst;
2228   int textlow_not_set = 1;
2229   int past_first_source_file = 0;
2230
2231   /* List of current psymtab's include files */
2232   char **psymtab_include_list;
2233   int includes_allocated;
2234   int includes_used;
2235   EXTR *extern_tab;
2236   struct pst_map *fdr_to_pst;
2237   /* Index within current psymtab dependency list */
2238   struct partial_symtab **dependency_list;
2239   int dependencies_used, dependencies_allocated;
2240   struct cleanup *old_chain;
2241   char *name;
2242   enum language prev_language;
2243   asection *text_sect;
2244   int relocatable = 0;
2245
2246   /* Irix 5.2 shared libraries have a fh->adr field of zero, but
2247      the shared libraries are prelinked at a high memory address.
2248      We have to adjust the start address of the object file for this case,
2249      by setting it to the start address of the first procedure in the file.
2250      But we should do no adjustments if we are debugging a .o file, where
2251      the text section (and fh->adr) really starts at zero.  */
2252   text_sect = bfd_get_section_by_name (cur_bfd, ".text");
2253   if (text_sect != NULL
2254       && (bfd_get_section_flags (cur_bfd, text_sect) & SEC_RELOC))
2255     relocatable = 1;
2256
2257   extern_tab = (EXTR *) obstack_alloc (&objfile->psymbol_obstack,
2258                                        sizeof (EXTR) * hdr->iextMax);
2259
2260   includes_allocated = 30;
2261   includes_used = 0;
2262   psymtab_include_list = (char **) alloca (includes_allocated *
2263                                            sizeof (char *));
2264   next_symbol_text_func = mdebug_next_symbol_text;
2265
2266   dependencies_allocated = 30;
2267   dependencies_used = 0;
2268   dependency_list =
2269     (struct partial_symtab **) alloca (dependencies_allocated *
2270                                        sizeof (struct partial_symtab *));
2271
2272   last_source_file = NULL;
2273
2274   /*
2275    * Big plan:
2276    *
2277    * Only parse the Local and External symbols, and the Relative FDR.
2278    * Fixup enough of the loader symtab to be able to use it.
2279    * Allocate space only for the file's portions we need to
2280    * look at. (XXX)
2281    */
2282
2283   max_gdbinfo = 0;
2284   max_glevel = MIN_GLEVEL;
2285
2286   /* Allocate the map FDR -> PST.
2287      Minor hack: -O3 images might claim some global data belongs
2288      to FDR -1. We`ll go along with that */
2289   fdr_to_pst = (struct pst_map *) xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst);
2290   old_chain = make_cleanup (xfree, fdr_to_pst);
2291   fdr_to_pst++;
2292   {
2293     struct partial_symtab *pst = new_psymtab ("", objfile);
2294     fdr_to_pst[-1].pst = pst;
2295     FDR_IDX (pst) = -1;
2296   }
2297
2298   /* Allocate the global pending list.  */
2299   pending_list =
2300     ((struct mdebug_pending **)
2301      obstack_alloc (&objfile->psymbol_obstack,
2302                     hdr->ifdMax * sizeof (struct mdebug_pending *)));
2303   memset ((PTR) pending_list, 0,
2304           hdr->ifdMax * sizeof (struct mdebug_pending *));
2305
2306   /* Pass 0 over external syms: swap them in.  */
2307   ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR));
2308   make_cleanup (xfree, ext_block);
2309
2310   ext_out = (char *) debug_info->external_ext;
2311   ext_out_end = ext_out + hdr->iextMax * external_ext_size;
2312   ext_in = ext_block;
2313   for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++)
2314     (*swap_ext_in) (cur_bfd, ext_out, ext_in);
2315
2316   /* Pass 1 over external syms: Presize and partition the list */
2317   ext_in = ext_block;
2318   ext_in_end = ext_in + hdr->iextMax;
2319   for (; ext_in < ext_in_end; ext_in++)
2320     {
2321       /* See calls to complain below.  */
2322       if (ext_in->ifd >= -1
2323           && ext_in->ifd < hdr->ifdMax
2324           && ext_in->asym.iss >= 0
2325           && ext_in->asym.iss < hdr->issExtMax)
2326         fdr_to_pst[ext_in->ifd].n_globals++;
2327     }
2328
2329   /* Pass 1.5 over files:  partition out global symbol space */
2330   s_idx = 0;
2331   for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
2332     {
2333       fdr_to_pst[f_idx].globals_offset = s_idx;
2334       s_idx += fdr_to_pst[f_idx].n_globals;
2335       fdr_to_pst[f_idx].n_globals = 0;
2336     }
2337
2338   /* ECOFF in ELF:
2339
2340      For ECOFF in ELF, we skip the creation of the minimal symbols.
2341      The ECOFF symbols should be a subset of the Elf symbols, and the 
2342      section information of the elf symbols will be more accurate.
2343      FIXME!  What about Irix 5's native linker?
2344
2345      By default, Elf sections which don't exist in ECOFF 
2346      get put in ECOFF's absolute section by the gnu linker.
2347      Since absolute sections don't get relocated, we 
2348      end up calculating an address different from that of 
2349      the symbol's minimal symbol (created earlier from the
2350      Elf symtab).  
2351
2352      To fix this, either :
2353      1) don't create the duplicate symbol
2354      (assumes ECOFF symtab is a subset of the ELF symtab;
2355      assumes no side-effects result from ignoring ECOFF symbol)
2356      2) create it, only if lookup for existing symbol in ELF's minimal 
2357      symbols fails
2358      (inefficient; 
2359      assumes no side-effects result from ignoring ECOFF symbol)
2360      3) create it, but lookup ELF's minimal symbol and use it's section
2361      during relocation, then modify "uniqify" phase to merge and 
2362      eliminate the duplicate symbol
2363      (highly inefficient)
2364
2365      I've implemented #1 here...
2366      Skip the creation of the minimal symbols based on the ECOFF 
2367      symbol table. */
2368
2369   /* Pass 2 over external syms: fill in external symbols */
2370   ext_in = ext_block;
2371   ext_in_end = ext_in + hdr->iextMax;
2372   for (; ext_in < ext_in_end; ext_in++)
2373     {
2374       enum minimal_symbol_type ms_type = mst_text;
2375       CORE_ADDR svalue = ext_in->asym.value;
2376
2377       /* The Irix 5 native tools seem to sometimes generate bogus
2378          external symbols.  */
2379       if (ext_in->ifd < -1 || ext_in->ifd >= hdr->ifdMax)
2380         {
2381           complain (&bad_ext_ifd_complaint, ext_in->ifd, hdr->ifdMax);
2382           continue;
2383         }
2384       if (ext_in->asym.iss < 0 || ext_in->asym.iss >= hdr->issExtMax)
2385         {
2386           complain (&bad_ext_iss_complaint, ext_in->asym.iss,
2387                     hdr->issExtMax);
2388           continue;
2389         }
2390
2391       extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
2392                  + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
2393
2394
2395       if (SC_IS_UNDEF (ext_in->asym.sc) || ext_in->asym.sc == scNil)
2396         continue;
2397
2398
2399       /* Pass 3 over files, over local syms: fill in static symbols */
2400       name = debug_info->ssext + ext_in->asym.iss;
2401
2402       /* Process ECOFF Symbol Types and Storage Classes */
2403       switch (ext_in->asym.st)
2404         {
2405         case stProc:
2406           /* Beginnning of Procedure */
2407           svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2408           break;
2409         case stStaticProc:
2410           /* Load time only static procs */
2411           ms_type = mst_file_text;
2412           svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2413           break;
2414         case stGlobal:
2415           /* External symbol */
2416           if (SC_IS_COMMON (ext_in->asym.sc))
2417             {
2418               /* The value of a common symbol is its size, not its address.
2419                  Ignore it.  */
2420               continue;
2421             }
2422           else if (SC_IS_DATA (ext_in->asym.sc))
2423             {
2424               ms_type = mst_data;
2425               svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2426             }
2427           else if (SC_IS_BSS (ext_in->asym.sc))
2428             {
2429               ms_type = mst_bss;
2430               svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2431             }
2432           else
2433             ms_type = mst_abs;
2434           break;
2435         case stLabel:
2436           /* Label */
2437           if (SC_IS_TEXT (ext_in->asym.sc))
2438             {
2439               ms_type = mst_file_text;
2440               svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2441             }
2442           else if (SC_IS_DATA (ext_in->asym.sc))
2443             {
2444               ms_type = mst_file_data;
2445               svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2446             }
2447           else if (SC_IS_BSS (ext_in->asym.sc))
2448             {
2449               ms_type = mst_file_bss;
2450               svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2451             }
2452           else
2453             ms_type = mst_abs;
2454           break;
2455         case stLocal:
2456         case stNil:
2457           /* The alpha has the section start addresses in stLocal symbols
2458              whose name starts with a `.'. Skip those but complain for all
2459              other stLocal symbols.
2460              Irix6 puts the section start addresses in stNil symbols, skip
2461              those too. */
2462           if (name[0] == '.')
2463             continue;
2464           /* Fall through.  */
2465         default:
2466           ms_type = mst_unknown;
2467           complain (&unknown_ext_complaint, name);
2468         }
2469       if (!ECOFF_IN_ELF (cur_bfd))
2470         prim_record_minimal_symbol (name, svalue, ms_type, objfile);
2471     }
2472
2473   /* Pass 3 over files, over local syms: fill in static symbols */
2474   for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
2475     {
2476       struct partial_symtab *save_pst;
2477       EXTR *ext_ptr;
2478       CORE_ADDR textlow;
2479
2480       cur_fdr = fh = debug_info->fdr + f_idx;
2481
2482       if (fh->csym == 0)
2483         {
2484           fdr_to_pst[f_idx].pst = NULL;
2485           continue;
2486         }
2487
2488       /* Determine the start address for this object file from the
2489          file header and relocate it, except for Irix 5.2 zero fh->adr.  */
2490       if (fh->cpd)
2491         {
2492           textlow = fh->adr;
2493           if (relocatable || textlow != 0)
2494             textlow += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2495         }
2496       else
2497         textlow = 0;
2498       pst = start_psymtab_common (objfile, objfile->section_offsets,
2499                                   fdr_name (fh),
2500                                   textlow,
2501                                   objfile->global_psymbols.next,
2502                                   objfile->static_psymbols.next);
2503       pst->read_symtab_private = ((char *)
2504                                   obstack_alloc (&objfile->psymbol_obstack,
2505                                                  sizeof (struct symloc)));
2506       memset ((PTR) pst->read_symtab_private, 0, sizeof (struct symloc));
2507
2508       save_pst = pst;
2509       FDR_IDX (pst) = f_idx;
2510       CUR_BFD (pst) = cur_bfd;
2511       DEBUG_SWAP (pst) = debug_swap;
2512       DEBUG_INFO (pst) = debug_info;
2513       PENDING_LIST (pst) = pending_list;
2514
2515       /* The way to turn this into a symtab is to call... */
2516       pst->read_symtab = mdebug_psymtab_to_symtab;
2517
2518       /* Set up language for the pst.
2519          The language from the FDR is used if it is unambigious (e.g. cfront
2520          with native cc and g++ will set the language to C).
2521          Otherwise we have to deduce the language from the filename.
2522          Native ecoff has every header file in a separate FDR, so
2523          deduce_language_from_filename will return language_unknown for
2524          a header file, which is not what we want.
2525          But the FDRs for the header files are after the FDR for the source
2526          file, so we can assign the language of the source file to the
2527          following header files. Then we save the language in the private
2528          pst data so that we can reuse it when building symtabs.  */
2529       prev_language = psymtab_language;
2530
2531       switch (fh->lang)
2532         {
2533         case langCplusplusV2:
2534           psymtab_language = language_cplus;
2535           break;
2536         default:
2537           psymtab_language = deduce_language_from_filename (fdr_name (fh));
2538           break;
2539         }
2540       if (psymtab_language == language_unknown)
2541         psymtab_language = prev_language;
2542       PST_PRIVATE (pst)->pst_language = psymtab_language;
2543
2544       pst->texthigh = pst->textlow;
2545
2546       /* For stabs-in-ecoff files, the second symbol must be @stab.
2547          This symbol is emitted by mips-tfile to signal that the
2548          current object file uses encapsulated stabs instead of mips
2549          ecoff for local symbols.  (It is the second symbol because
2550          the first symbol is the stFile used to signal the start of a
2551          file). */
2552       processing_gcc_compilation = 0;
2553       if (fh->csym >= 2)
2554         {
2555           (*swap_sym_in) (cur_bfd,
2556                           ((char *) debug_info->external_sym
2557                            + (fh->isymBase + 1) * external_sym_size),
2558                           &sh);
2559           if (STREQ (debug_info->ss + fh->issBase + sh.iss, stabs_symbol))
2560             processing_gcc_compilation = 2;
2561         }
2562
2563       if (processing_gcc_compilation != 0)
2564         {
2565           for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
2566             {
2567               int type_code;
2568               char *namestring;
2569
2570               (*swap_sym_in) (cur_bfd,
2571                               (((char *) debug_info->external_sym)
2572                             + (fh->isymBase + cur_sdx) * external_sym_size),
2573                               &sh);
2574               type_code = ECOFF_UNMARK_STAB (sh.index);
2575               if (!ECOFF_IS_STAB (&sh))
2576                 {
2577                   if (sh.st == stProc || sh.st == stStaticProc)
2578                     {
2579                       CORE_ADDR procaddr;
2580                       long isym;
2581
2582                       sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2583                       if (sh.st == stStaticProc)
2584                         {
2585                           namestring = debug_info->ss + fh->issBase + sh.iss;
2586                           prim_record_minimal_symbol_and_info (namestring,
2587                                                                sh.value,
2588                                                                mst_file_text,
2589                                                                NULL,
2590                                                                SECT_OFF_TEXT (objfile),
2591                                                                NULL,
2592                                                                objfile);
2593                         }
2594                       procaddr = sh.value;
2595
2596                       isym = AUX_GET_ISYM (fh->fBigendian,
2597                                            (debug_info->external_aux
2598                                             + fh->iauxBase
2599                                             + sh.index));
2600                       (*swap_sym_in) (cur_bfd,
2601                                       ((char *) debug_info->external_sym
2602                                        + ((fh->isymBase + isym - 1)
2603                                           * external_sym_size)),
2604                                       &sh);
2605                       if (sh.st == stEnd)
2606                         {
2607                           CORE_ADDR high = procaddr + sh.value;
2608
2609                           /* Kludge for Irix 5.2 zero fh->adr.  */
2610                           if (!relocatable
2611                           && (pst->textlow == 0 || procaddr < pst->textlow))
2612                             pst->textlow = procaddr;
2613                           if (high > pst->texthigh)
2614                             pst->texthigh = high;
2615                         }
2616                     }
2617                   else if (sh.st == stStatic)
2618                     {
2619                       switch (sh.sc)
2620                         {
2621                         case scUndefined:
2622                         case scSUndefined:
2623                         case scNil:
2624                         case scAbs:
2625                           break;
2626
2627                         case scData:
2628                         case scSData:
2629                         case scRData:
2630                         case scPData:
2631                         case scXData:
2632                           namestring = debug_info->ss + fh->issBase + sh.iss;
2633                           sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2634                           prim_record_minimal_symbol_and_info (namestring,
2635                                                                sh.value,
2636                                                                mst_file_data,
2637                                                                NULL,
2638                                                                SECT_OFF_DATA (objfile),
2639                                                                NULL,
2640                                                                objfile);
2641                           break;
2642
2643                         default:
2644                           /* FIXME!  Shouldn't this use cases for bss, 
2645                              then have the default be abs? */
2646                           namestring = debug_info->ss + fh->issBase + sh.iss;
2647                           sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2648                           prim_record_minimal_symbol_and_info (namestring,
2649                                                                sh.value,
2650                                                                mst_file_bss,
2651                                                                NULL,
2652                                                                SECT_OFF_BSS (objfile),
2653                                                                NULL,
2654                                                                objfile);
2655                           break;
2656                         }
2657                     }
2658                   continue;
2659                 }
2660               /* Handle stabs continuation */
2661               {
2662                 char *stabstring = debug_info->ss + fh->issBase + sh.iss;
2663                 int len = strlen (stabstring);
2664                 while (stabstring[len - 1] == '\\')
2665                   {
2666                     SYMR sh2;
2667                     char *stabstring1 = stabstring;
2668                     char *stabstring2;
2669                     int len2;
2670
2671                     /* Ignore continuation char from 1st string */
2672                     len--;
2673
2674                     /* Read next stabstring */
2675                     cur_sdx++;
2676                     (*swap_sym_in) (cur_bfd,
2677                                     (((char *) debug_info->external_sym)
2678                                      + (fh->isymBase + cur_sdx)
2679                                      * external_sym_size),
2680                                     &sh2);
2681                     stabstring2 = debug_info->ss + fh->issBase + sh2.iss;
2682                     len2 = strlen (stabstring2);
2683
2684                     /* Concatinate stabstring2 with stabstring1 */
2685                     if (stabstring
2686                      && stabstring != debug_info->ss + fh->issBase + sh.iss)
2687                       stabstring = xrealloc (stabstring, len + len2 + 1);
2688                     else
2689                       stabstring = xmalloc (len + len2 + 1);
2690                     strcpy (stabstring, stabstring1);
2691                     strcpy (stabstring + len, stabstring2);
2692                     len += len2;
2693                   }
2694
2695 #define SET_NAMESTRING() \
2696   namestring = stabstring
2697 #define CUR_SYMBOL_TYPE type_code
2698 #define CUR_SYMBOL_VALUE sh.value
2699 #define START_PSYMTAB(ofile,fname,low,symoff,global_syms,static_syms)\
2700   (pst = save_pst)
2701 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set) (void)0
2702 #define HANDLE_RBRAC(val) \
2703   if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2704 #include "partial-stab.h"
2705
2706                 if (stabstring
2707                     && stabstring != debug_info->ss + fh->issBase + sh.iss)
2708                   xfree (stabstring);
2709               }
2710               /* end - Handle continuation */
2711             }
2712         }
2713       else
2714         {
2715           for (cur_sdx = 0; cur_sdx < fh->csym;)
2716             {
2717               char *name;
2718               enum address_class class;
2719
2720               (*swap_sym_in) (cur_bfd,
2721                               ((char *) debug_info->external_sym
2722                                + ((fh->isymBase + cur_sdx)
2723                                   * external_sym_size)),
2724                               &sh);
2725
2726               if (ECOFF_IS_STAB (&sh))
2727                 {
2728                   cur_sdx++;
2729                   continue;
2730                 }
2731
2732               /* Non absolute static symbols go into the minimal table.  */
2733               if (SC_IS_UNDEF (sh.sc) || sh.sc == scNil
2734                   || (sh.index == indexNil
2735                       && (sh.st != stStatic || sh.sc == scAbs)))
2736                 {
2737                   /* FIXME, premature? */
2738                   cur_sdx++;
2739                   continue;
2740                 }
2741
2742               name = debug_info->ss + fh->issBase + sh.iss;
2743
2744               switch (sh.sc)
2745                 {
2746                 case scText:
2747                 case scRConst:
2748                   /* The value of a stEnd symbol is the displacement from the
2749                      corresponding start symbol value, do not relocate it.  */
2750                   if (sh.st != stEnd)
2751                     sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2752                   break;
2753                 case scData:
2754                 case scSData:
2755                 case scRData:
2756                 case scPData:
2757                 case scXData:
2758                   sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2759                   break;
2760                 case scBss:
2761                 case scSBss:
2762                   sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2763                   break;
2764                 }
2765
2766               switch (sh.st)
2767                 {
2768                   CORE_ADDR high;
2769                   CORE_ADDR procaddr;
2770                   int new_sdx;
2771
2772                 case stStaticProc:
2773                   prim_record_minimal_symbol_and_info (name, sh.value,
2774                                                        mst_file_text, NULL,
2775                                                        SECT_OFF_TEXT (objfile), NULL,
2776                                                        objfile);
2777
2778                   /* FALLTHROUGH */
2779
2780                 case stProc:
2781                   /* Usually there is a local and a global stProc symbol
2782                      for a function. This means that the function name
2783                      has already been entered into the mimimal symbol table
2784                      while processing the global symbols in pass 2 above.
2785                      One notable exception is the PROGRAM name from
2786                      f77 compiled executables, it is only put out as
2787                      local stProc symbol, and a global MAIN__ stProc symbol
2788                      points to it.  It doesn't matter though, as gdb is
2789                      still able to find the PROGRAM name via the partial
2790                      symbol table, and the MAIN__ symbol via the minimal
2791                      symbol table.  */
2792                   if (sh.st == stProc)
2793                     add_psymbol_to_list (name, strlen (name),
2794                                          VAR_NAMESPACE, LOC_BLOCK,
2795                                          &objfile->global_psymbols,
2796                                     0, sh.value, psymtab_language, objfile);
2797                   else
2798                     add_psymbol_to_list (name, strlen (name),
2799                                          VAR_NAMESPACE, LOC_BLOCK,
2800                                          &objfile->static_psymbols,
2801                                     0, sh.value, psymtab_language, objfile);
2802
2803                   /* Skip over procedure to next one. */
2804                   if (sh.index >= hdr->iauxMax)
2805                     {
2806                       /* Should not happen, but does when cross-compiling
2807                          with the MIPS compiler.  FIXME -- pull later.  */
2808                       complain (&index_complaint, name);
2809                       new_sdx = cur_sdx + 1;    /* Don't skip at all */
2810                     }
2811                   else
2812                     new_sdx = AUX_GET_ISYM (fh->fBigendian,
2813                                             (debug_info->external_aux
2814                                              + fh->iauxBase
2815                                              + sh.index));
2816                   procaddr = sh.value;
2817
2818                   if (new_sdx <= cur_sdx)
2819                     {
2820                       /* This should not happen either... FIXME.  */
2821                       complain (&aux_index_complaint, name);
2822                       new_sdx = cur_sdx + 1;    /* Don't skip backward */
2823                     }
2824
2825                   cur_sdx = new_sdx;
2826                   (*swap_sym_in) (cur_bfd,
2827                                   ((char *) debug_info->external_sym
2828                                    + ((fh->isymBase + cur_sdx - 1)
2829                                       * external_sym_size)),
2830                                   &sh);
2831                   if (sh.st != stEnd)
2832                     continue;
2833
2834                   /* Kludge for Irix 5.2 zero fh->adr.  */
2835                   if (!relocatable
2836                       && (pst->textlow == 0 || procaddr < pst->textlow))
2837                     pst->textlow = procaddr;
2838
2839                   high = procaddr + sh.value;
2840                   if (high > pst->texthigh)
2841                     pst->texthigh = high;
2842                   continue;
2843
2844                 case stStatic:  /* Variable */
2845                   if (SC_IS_DATA (sh.sc))
2846                     prim_record_minimal_symbol_and_info (name, sh.value,
2847                                                          mst_file_data, NULL,
2848                                                          SECT_OFF_DATA (objfile),
2849                                                          NULL,
2850                                                          objfile);
2851                   else
2852                     prim_record_minimal_symbol_and_info (name, sh.value,
2853                                                          mst_file_bss, NULL,
2854                                                          SECT_OFF_BSS (objfile),
2855                                                          NULL,
2856                                                          objfile);
2857                   class = LOC_STATIC;
2858                   break;
2859
2860                 case stIndirect:        /* Irix5 forward declaration */
2861                   /* Skip forward declarations from Irix5 cc */
2862                   goto skip;
2863
2864                 case stTypedef: /* Typedef */
2865                   /* Skip typedefs for forward declarations and opaque
2866                      structs from alpha and mips cc.  */
2867                   if (sh.iss == 0 || has_opaque_xref (fh, &sh))
2868                     goto skip;
2869                   class = LOC_TYPEDEF;
2870                   break;
2871
2872                 case stConstant:        /* Constant decl */
2873                   class = LOC_CONST;
2874                   break;
2875
2876                 case stUnion:
2877                 case stStruct:
2878                 case stEnum:
2879                 case stBlock:   /* { }, str, un, enum */
2880                   /* Do not create a partial symbol for cc unnamed aggregates
2881                      and gcc empty aggregates. */
2882                   if ((sh.sc == scInfo
2883                        || SC_IS_COMMON (sh.sc))
2884                       && sh.iss != 0
2885                       && sh.index != cur_sdx + 2)
2886                     {
2887                       add_psymbol_to_list (name, strlen (name),
2888                                            STRUCT_NAMESPACE, LOC_TYPEDEF,
2889                                            &objfile->static_psymbols,
2890                                            0, (CORE_ADDR) 0,
2891                                            psymtab_language, objfile);
2892                     }
2893                   handle_psymbol_enumerators (objfile, fh, sh.st, sh.value);
2894
2895                   /* Skip over the block */
2896                   new_sdx = sh.index;
2897                   if (new_sdx <= cur_sdx)
2898                     {
2899                       /* This happens with the Ultrix kernel. */
2900                       complain (&block_index_complaint, name);
2901                       new_sdx = cur_sdx + 1;    /* Don't skip backward */
2902                     }
2903                   cur_sdx = new_sdx;
2904                   continue;
2905
2906                 case stFile:    /* File headers */
2907                 case stLabel:   /* Labels */
2908                 case stEnd:     /* Ends of files */
2909                   goto skip;
2910
2911                 case stLocal:   /* Local variables */
2912                   /* Normally these are skipped because we skip over
2913                      all blocks we see.  However, these can occur
2914                      as visible symbols in a .h file that contains code. */
2915                   goto skip;
2916
2917                 default:
2918                   /* Both complaints are valid:  one gives symbol name,
2919                      the other the offending symbol type.  */
2920                   complain (&unknown_sym_complaint, name);
2921                   complain (&unknown_st_complaint, sh.st);
2922                   cur_sdx++;
2923                   continue;
2924                 }
2925               /* Use this gdb symbol */
2926               add_psymbol_to_list (name, strlen (name),
2927                                    VAR_NAMESPACE, class,
2928                                    &objfile->static_psymbols,
2929                                    0, sh.value, psymtab_language, objfile);
2930             skip:
2931               cur_sdx++;        /* Go to next file symbol */
2932             }
2933
2934           /* Now do enter the external symbols. */
2935           ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
2936           cur_sdx = fdr_to_pst[f_idx].n_globals;
2937           PST_PRIVATE (save_pst)->extern_count = cur_sdx;
2938           PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
2939           for (; --cur_sdx >= 0; ext_ptr++)
2940             {
2941               enum address_class class;
2942               SYMR *psh;
2943               char *name;
2944               CORE_ADDR svalue;
2945
2946               if (ext_ptr->ifd != f_idx)
2947                 internal_error (__FILE__, __LINE__, "failed internal consistency check");
2948               psh = &ext_ptr->asym;
2949
2950               /* Do not add undefined symbols to the partial symbol table.  */
2951               if (SC_IS_UNDEF (psh->sc) || psh->sc == scNil)
2952                 continue;
2953
2954               svalue = psh->value;
2955               switch (psh->sc)
2956                 {
2957                 case scText:
2958                 case scRConst:
2959                   svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2960                   break;
2961                 case scData:
2962                 case scSData:
2963                 case scRData:
2964                 case scPData:
2965                 case scXData:
2966                   svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2967                   break;
2968                 case scBss:
2969                 case scSBss:
2970                   svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2971                   break;
2972                 }
2973
2974               switch (psh->st)
2975                 {
2976                 case stNil:
2977                   /* These are generated for static symbols in .o files,
2978                      ignore them.  */
2979                   continue;
2980                 case stProc:
2981                 case stStaticProc:
2982                   /* External procedure symbols have been entered
2983                      into the minimal symbol table in pass 2 above.
2984                      Ignore them, as parse_external will ignore them too.  */
2985                   continue;
2986                 case stLabel:
2987                   class = LOC_LABEL;
2988                   break;
2989                 default:
2990                   complain (&unknown_ext_complaint,
2991                             debug_info->ssext + psh->iss);
2992                   /* Fall through, pretend it's global.  */
2993                 case stGlobal:
2994                   /* Global common symbols are resolved by the runtime loader,
2995                      ignore them.  */
2996                   if (SC_IS_COMMON (psh->sc))
2997                     continue;
2998
2999                   class = LOC_STATIC;
3000                   break;
3001                 }
3002               name = debug_info->ssext + psh->iss;
3003               add_psymbol_to_list (name, strlen (name),
3004                                    VAR_NAMESPACE, class,
3005                                    &objfile->global_psymbols,
3006                                    0, svalue,
3007                                    psymtab_language, objfile);
3008             }
3009         }
3010
3011       /* Link pst to FDR. end_psymtab returns NULL if the psymtab was
3012          empty and put on the free list.  */
3013       fdr_to_pst[f_idx].pst = end_psymtab (save_pst,
3014                                         psymtab_include_list, includes_used,
3015                                            -1, save_pst->texthigh,
3016                        dependency_list, dependencies_used, textlow_not_set);
3017       includes_used = 0;
3018       dependencies_used = 0;
3019
3020       if (objfile->ei.entry_point >= save_pst->textlow &&
3021           objfile->ei.entry_point < save_pst->texthigh)
3022         {
3023           objfile->ei.entry_file_lowpc = save_pst->textlow;
3024           objfile->ei.entry_file_highpc = save_pst->texthigh;
3025         }
3026
3027       /* The objfile has its functions reordered if this partial symbol
3028          table overlaps any other partial symbol table.
3029          We cannot assume a reordered objfile if a partial symbol table
3030          is contained within another partial symbol table, as partial symbol
3031          tables for include files with executable code are contained
3032          within the partial symbol table for the including source file,
3033          and we do not want to flag the objfile reordered for these cases.
3034
3035          This strategy works well for Irix-5.2 shared libraries, but we
3036          might have to use a more elaborate (and slower) algorithm for
3037          other cases.  */
3038       save_pst = fdr_to_pst[f_idx].pst;
3039       if (save_pst != NULL
3040           && save_pst->textlow != 0
3041           && !(objfile->flags & OBJF_REORDERED))
3042         {
3043           ALL_OBJFILE_PSYMTABS (objfile, pst)
3044           {
3045             if (save_pst != pst
3046                 && save_pst->textlow >= pst->textlow
3047                 && save_pst->textlow < pst->texthigh
3048                 && save_pst->texthigh > pst->texthigh)
3049               {
3050                 objfile->flags |= OBJF_REORDERED;
3051                 break;
3052               }
3053           }
3054         }
3055     }
3056
3057   /* Now scan the FDRs for dependencies */
3058   for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
3059     {
3060       fh = f_idx + debug_info->fdr;
3061       pst = fdr_to_pst[f_idx].pst;
3062
3063       if (pst == (struct partial_symtab *) NULL)
3064         continue;
3065
3066       /* This should catch stabs-in-ecoff. */
3067       if (fh->crfd <= 1)
3068         continue;
3069
3070       /* Skip the first file indirect entry as it is a self dependency
3071          for source files or a reverse .h -> .c dependency for header files.  */
3072       pst->number_of_dependencies = 0;
3073       pst->dependencies =
3074         ((struct partial_symtab **)
3075          obstack_alloc (&objfile->psymbol_obstack,
3076                         ((fh->crfd - 1)
3077                          * sizeof (struct partial_symtab *))));
3078       for (s_idx = 1; s_idx < fh->crfd; s_idx++)
3079         {
3080           RFDT rh;
3081
3082           (*swap_rfd_in) (cur_bfd,
3083                           ((char *) debug_info->external_rfd
3084                            + (fh->rfdBase + s_idx) * external_rfd_size),
3085                           &rh);
3086           if (rh < 0 || rh >= hdr->ifdMax)
3087             {
3088               complain (&bad_file_number_complaint, rh);
3089               continue;
3090             }
3091
3092           /* Skip self dependencies of header files.  */
3093           if (rh == f_idx)
3094             continue;
3095
3096           /* Do not add to dependeny list if psymtab was empty.  */
3097           if (fdr_to_pst[rh].pst == (struct partial_symtab *) NULL)
3098             continue;
3099           pst->dependencies[pst->number_of_dependencies++] = fdr_to_pst[rh].pst;
3100         }
3101     }
3102
3103   /* Remove the dummy psymtab created for -O3 images above, if it is
3104      still empty, to enable the detection of stripped executables.  */
3105   if (objfile->psymtabs->next == NULL
3106       && objfile->psymtabs->number_of_dependencies == 0
3107       && objfile->psymtabs->n_global_syms == 0
3108       && objfile->psymtabs->n_static_syms == 0)
3109     objfile->psymtabs = NULL;
3110   do_cleanups (old_chain);
3111 }
3112
3113 /* If the current psymbol has an enumerated type, we need to add
3114    all the the enum constants to the partial symbol table.  */
3115
3116 static void
3117 handle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype,
3118                             CORE_ADDR svalue)
3119 {
3120   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
3121   void (*const swap_sym_in) (bfd *, PTR, SYMR *) = debug_swap->swap_sym_in;
3122   char *ext_sym = ((char *) debug_info->external_sym
3123                    + ((fh->isymBase + cur_sdx + 1) * external_sym_size));
3124   SYMR sh;
3125   TIR tir;
3126
3127   switch (stype)
3128     {
3129     case stEnum:
3130       break;
3131
3132     case stBlock:
3133       /* It is an enumerated type if the next symbol entry is a stMember
3134          and its auxiliary index is indexNil or its auxiliary entry
3135          is a plain btNil or btVoid.
3136          Alpha cc -migrate enums are recognized by a zero index and
3137          a zero symbol value.
3138          DU 4.0 cc enums are recognized by a member type of btEnum without
3139          qualifiers and a zero symbol value.  */
3140       (*swap_sym_in) (cur_bfd, ext_sym, &sh);
3141       if (sh.st != stMember)
3142         return;
3143
3144       if (sh.index == indexNil
3145           || (sh.index == 0 && svalue == 0))
3146         break;
3147       (*debug_swap->swap_tir_in) (fh->fBigendian,
3148                                   &(debug_info->external_aux
3149                                     + fh->iauxBase + sh.index)->a_ti,
3150                                   &tir);
3151       if ((tir.bt != btNil
3152            && tir.bt != btVoid
3153            && (tir.bt != btEnum || svalue != 0))
3154           || tir.tq0 != tqNil)
3155         return;
3156       break;
3157
3158     default:
3159       return;
3160     }
3161
3162   for (;;)
3163     {
3164       char *name;
3165
3166       (*swap_sym_in) (cur_bfd, ext_sym, &sh);
3167       if (sh.st != stMember)
3168         break;
3169       name = debug_info->ss + cur_fdr->issBase + sh.iss;
3170
3171       /* Note that the value doesn't matter for enum constants
3172          in psymtabs, just in symtabs.  */
3173       add_psymbol_to_list (name, strlen (name),
3174                            VAR_NAMESPACE, LOC_CONST,
3175                            &objfile->static_psymbols, 0,
3176                            (CORE_ADDR) 0, psymtab_language, objfile);
3177       ext_sym += external_sym_size;
3178     }
3179 }
3180
3181 /* Get the next symbol.  OBJFILE is unused. */
3182
3183 static char *
3184 mdebug_next_symbol_text (struct objfile *objfile)
3185 {
3186   SYMR sh;
3187
3188   cur_sdx++;
3189   (*debug_swap->swap_sym_in) (cur_bfd,
3190                               ((char *) debug_info->external_sym
3191                                + ((cur_fdr->isymBase + cur_sdx)
3192                                   * debug_swap->external_sym_size)),
3193                               &sh);
3194   return debug_info->ss + cur_fdr->issBase + sh.iss;
3195 }
3196
3197 /* Ancillary function to psymtab_to_symtab().  Does all the work
3198    for turning the partial symtab PST into a symtab, recurring
3199    first on all dependent psymtabs.  The argument FILENAME is
3200    only passed so we can see in debug stack traces what file
3201    is being read.
3202
3203    This function has a split personality, based on whether the
3204    symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
3205    The flow of control and even the memory allocation differs.  FIXME.  */
3206
3207 static void
3208 psymtab_to_symtab_1 (struct partial_symtab *pst, char *filename)
3209 {
3210   bfd_size_type external_sym_size;
3211   bfd_size_type external_pdr_size;
3212   void (*swap_sym_in) (bfd *, PTR, SYMR *);
3213   void (*swap_pdr_in) (bfd *, PTR, PDR *);
3214   int i;
3215   struct symtab *st;
3216   FDR *fh;
3217   struct linetable *lines;
3218   CORE_ADDR lowest_pdr_addr = 0;
3219
3220   if (pst->readin)
3221     return;
3222   pst->readin = 1;
3223
3224   /* Read in all partial symbtabs on which this one is dependent.
3225      NOTE that we do have circular dependencies, sigh.  We solved
3226      that by setting pst->readin before this point.  */
3227
3228   for (i = 0; i < pst->number_of_dependencies; i++)
3229     if (!pst->dependencies[i]->readin)
3230       {
3231         /* Inform about additional files to be read in.  */
3232         if (info_verbose)
3233           {
3234             fputs_filtered (" ", gdb_stdout);
3235             wrap_here ("");
3236             fputs_filtered ("and ", gdb_stdout);
3237             wrap_here ("");
3238             printf_filtered ("%s...",
3239                              pst->dependencies[i]->filename);
3240             wrap_here ("");     /* Flush output */
3241             gdb_flush (gdb_stdout);
3242           }
3243         /* We only pass the filename for debug purposes */
3244         psymtab_to_symtab_1 (pst->dependencies[i],
3245                              pst->dependencies[i]->filename);
3246       }
3247
3248   /* Do nothing if this is a dummy psymtab.  */
3249
3250   if (pst->n_global_syms == 0 && pst->n_static_syms == 0
3251       && pst->textlow == 0 && pst->texthigh == 0)
3252     return;
3253
3254   /* Now read the symbols for this symtab */
3255
3256   cur_bfd = CUR_BFD (pst);
3257   debug_swap = DEBUG_SWAP (pst);
3258   debug_info = DEBUG_INFO (pst);
3259   pending_list = PENDING_LIST (pst);
3260   external_sym_size = debug_swap->external_sym_size;
3261   external_pdr_size = debug_swap->external_pdr_size;
3262   swap_sym_in = debug_swap->swap_sym_in;
3263   swap_pdr_in = debug_swap->swap_pdr_in;
3264   current_objfile = pst->objfile;
3265   cur_fd = FDR_IDX (pst);
3266   fh = ((cur_fd == -1)
3267         ? (FDR *) NULL
3268         : debug_info->fdr + cur_fd);
3269   cur_fdr = fh;
3270
3271   /* See comment in parse_partial_symbols about the @stabs sentinel. */
3272   processing_gcc_compilation = 0;
3273   if (fh != (FDR *) NULL && fh->csym >= 2)
3274     {
3275       SYMR sh;
3276
3277       (*swap_sym_in) (cur_bfd,
3278                       ((char *) debug_info->external_sym
3279                        + (fh->isymBase + 1) * external_sym_size),
3280                       &sh);
3281       if (STREQ (debug_info->ss + fh->issBase + sh.iss,
3282                  stabs_symbol))
3283         {
3284           /* We indicate that this is a GCC compilation so that certain
3285              features will be enabled in stabsread/dbxread.  */
3286           processing_gcc_compilation = 2;
3287         }
3288     }
3289
3290   if (processing_gcc_compilation != 0)
3291     {
3292
3293       /* This symbol table contains stabs-in-ecoff entries.  */
3294
3295       /* Parse local symbols first */
3296
3297       if (fh->csym <= 2)        /* FIXME, this blows psymtab->symtab ptr */
3298         {
3299           current_objfile = NULL;
3300           return;
3301         }
3302       for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
3303         {
3304           SYMR sh;
3305           char *name;
3306           CORE_ADDR valu;
3307
3308           (*swap_sym_in) (cur_bfd,
3309                           (((char *) debug_info->external_sym)
3310                            + (fh->isymBase + cur_sdx) * external_sym_size),
3311                           &sh);
3312           name = debug_info->ss + fh->issBase + sh.iss;
3313           valu = sh.value;
3314           /* XXX This is a hack.  It will go away!  */
3315           if (ECOFF_IS_STAB (&sh) || (name[0] == '#'))
3316             {
3317               int type_code = ECOFF_UNMARK_STAB (sh.index);
3318
3319               /* We should never get non N_STAB symbols here, but they
3320                  should be harmless, so keep process_one_symbol from
3321                  complaining about them.  */
3322               if (type_code & N_STAB)
3323                 {
3324                   process_one_symbol (type_code, 0, valu, name,
3325                                       pst->section_offsets, pst->objfile);
3326                 }
3327               /* Similarly a hack.  */
3328               else if (name[0] == '#')
3329                 {
3330                   process_one_symbol (N_SLINE, 0, valu, name,
3331                                       pst->section_offsets, pst->objfile);
3332                 }
3333               if (type_code == N_FUN)
3334                 {
3335                   /* Make up special symbol to contain
3336                      procedure specific info */
3337                   struct mips_extra_func_info *e =
3338                   ((struct mips_extra_func_info *)
3339                    obstack_alloc (&current_objfile->symbol_obstack,
3340                                   sizeof (struct mips_extra_func_info)));
3341                   struct symbol *s = new_symbol (MIPS_EFI_SYMBOL_NAME);
3342
3343                   memset ((PTR) e, 0, sizeof (struct mips_extra_func_info));
3344                   SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
3345                   SYMBOL_CLASS (s) = LOC_CONST;
3346                   SYMBOL_TYPE (s) = mdebug_type_void;
3347                   SYMBOL_VALUE (s) = (long) e;
3348                   e->pdr.framereg = -1;
3349                   add_symbol_to_list (s, &local_symbols);
3350                 }
3351             }
3352           else if (sh.st == stLabel)
3353             {
3354               if (sh.index == indexNil)
3355                 {
3356                   /* This is what the gcc2_compiled and __gnu_compiled_*
3357                      show up as.  So don't complain.  */
3358                   ;
3359                 }
3360               else
3361                 {
3362                   /* Handle encoded stab line number. */
3363                   valu += ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile));
3364                   record_line (current_subfile, sh.index, valu);
3365                 }
3366             }
3367           else if (sh.st == stProc || sh.st == stStaticProc
3368                    || sh.st == stStatic || sh.st == stEnd)
3369             /* These are generated by gcc-2.x, do not complain */
3370             ;
3371           else
3372             complain (&stab_unknown_complaint, name);
3373         }
3374       st = end_symtab (pst->texthigh, pst->objfile, SECT_OFF_TEXT (pst->objfile));
3375       end_stabs ();
3376
3377       /* Sort the symbol table now, we are done adding symbols to it.
3378          We must do this before parse_procedure calls lookup_symbol.  */
3379       sort_symtab_syms (st);
3380
3381       /* There used to be a call to sort_blocks here, but this should not
3382          be necessary for stabs symtabs.  And as sort_blocks modifies the
3383          start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK,
3384          it did the wrong thing if the first procedure in a file was
3385          generated via asm statements.  */
3386
3387       /* Fill in procedure info next.  */
3388       if (fh->cpd > 0)
3389         {
3390           PDR *pr_block;
3391           struct cleanup *old_chain;
3392           char *pdr_ptr;
3393           char *pdr_end;
3394           PDR *pdr_in;
3395           PDR *pdr_in_end;
3396
3397           pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
3398           old_chain = make_cleanup (xfree, pr_block);
3399
3400           pdr_ptr = ((char *) debug_info->external_pdr
3401                      + fh->ipdFirst * external_pdr_size);
3402           pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
3403           pdr_in = pr_block;
3404           for (;
3405                pdr_ptr < pdr_end;
3406                pdr_ptr += external_pdr_size, pdr_in++)
3407             {
3408               (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
3409
3410               /* Determine lowest PDR address, the PDRs are not always
3411                  sorted.  */
3412               if (pdr_in == pr_block)
3413                 lowest_pdr_addr = pdr_in->adr;
3414               else if (pdr_in->adr < lowest_pdr_addr)
3415                 lowest_pdr_addr = pdr_in->adr;
3416             }
3417
3418           pdr_in = pr_block;
3419           pdr_in_end = pdr_in + fh->cpd;
3420           for (; pdr_in < pdr_in_end; pdr_in++)
3421             parse_procedure (pdr_in, st, pst);
3422
3423           do_cleanups (old_chain);
3424         }
3425     }
3426   else
3427     {
3428       /* This symbol table contains ordinary ecoff entries.  */
3429
3430       int f_max;
3431       int maxlines;
3432       EXTR *ext_ptr;
3433
3434       /* How many symbols will we need */
3435       /* FIXME, this does not count enum values. */
3436       f_max = pst->n_global_syms + pst->n_static_syms;
3437       if (fh == 0)
3438         {
3439           maxlines = 0;
3440           st = new_symtab ("unknown", f_max, 0, pst->objfile);
3441         }
3442       else
3443         {
3444           f_max += fh->csym + fh->cpd;
3445           maxlines = 2 * fh->cline;
3446           st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
3447
3448           /* The proper language was already determined when building
3449              the psymtab, use it.  */
3450           st->language = PST_PRIVATE (pst)->pst_language;
3451         }
3452
3453       psymtab_language = st->language;
3454
3455       lines = LINETABLE (st);
3456
3457       /* Get a new lexical context */
3458
3459       push_parse_stack ();
3460       top_stack->cur_st = st;
3461       top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st),
3462                                                 STATIC_BLOCK);
3463       BLOCK_START (top_stack->cur_block) = pst->textlow;
3464       BLOCK_END (top_stack->cur_block) = 0;
3465       top_stack->blocktype = stFile;
3466       top_stack->maxsyms = 2 * f_max;
3467       top_stack->cur_type = 0;
3468       top_stack->procadr = 0;
3469       top_stack->numargs = 0;
3470       found_ecoff_debugging_info = 0;
3471
3472       if (fh)
3473         {
3474           char *sym_ptr;
3475           char *sym_end;
3476
3477           /* Parse local symbols first */
3478           sym_ptr = ((char *) debug_info->external_sym
3479                      + fh->isymBase * external_sym_size);
3480           sym_end = sym_ptr + fh->csym * external_sym_size;
3481           while (sym_ptr < sym_end)
3482             {
3483               SYMR sh;
3484               int c;
3485
3486               (*swap_sym_in) (cur_bfd, sym_ptr, &sh);
3487               c = parse_symbol (&sh,
3488                                 debug_info->external_aux + fh->iauxBase,
3489                                 sym_ptr, fh->fBigendian, pst->section_offsets, pst->objfile);
3490               sym_ptr += c * external_sym_size;
3491             }
3492
3493           /* Linenumbers.  At the end, check if we can save memory.
3494              parse_lines has to look ahead an arbitrary number of PDR
3495              structures, so we swap them all first.  */
3496           if (fh->cpd > 0)
3497             {
3498               PDR *pr_block;
3499               struct cleanup *old_chain;
3500               char *pdr_ptr;
3501               char *pdr_end;
3502               PDR *pdr_in;
3503               PDR *pdr_in_end;
3504
3505               pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
3506
3507               old_chain = make_cleanup (xfree, pr_block);
3508
3509               pdr_ptr = ((char *) debug_info->external_pdr
3510                          + fh->ipdFirst * external_pdr_size);
3511               pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
3512               pdr_in = pr_block;
3513               for (;
3514                    pdr_ptr < pdr_end;
3515                    pdr_ptr += external_pdr_size, pdr_in++)
3516                 {
3517                   (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
3518
3519                   /* Determine lowest PDR address, the PDRs are not always
3520                      sorted.  */
3521                   if (pdr_in == pr_block)
3522                     lowest_pdr_addr = pdr_in->adr;
3523                   else if (pdr_in->adr < lowest_pdr_addr)
3524                     lowest_pdr_addr = pdr_in->adr;
3525                 }
3526
3527               parse_lines (fh, pr_block, lines, maxlines, pst, lowest_pdr_addr);
3528               if (lines->nitems < fh->cline)
3529                 lines = shrink_linetable (lines);
3530
3531               /* Fill in procedure info next.  */
3532               pdr_in = pr_block;
3533               pdr_in_end = pdr_in + fh->cpd;
3534               for (; pdr_in < pdr_in_end; pdr_in++)
3535                 parse_procedure (pdr_in, 0, pst);
3536
3537               do_cleanups (old_chain);
3538             }
3539         }
3540
3541       LINETABLE (st) = lines;
3542
3543       /* .. and our share of externals.
3544          XXX use the global list to speed up things here. how?
3545          FIXME, Maybe quit once we have found the right number of ext's? */
3546       top_stack->cur_st = st;
3547       top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
3548                                                 GLOBAL_BLOCK);
3549       top_stack->blocktype = stFile;
3550       top_stack->maxsyms
3551         = (debug_info->symbolic_header.isymMax
3552            + debug_info->symbolic_header.ipdMax
3553            + debug_info->symbolic_header.iextMax);
3554
3555       ext_ptr = PST_PRIVATE (pst)->extern_tab;
3556       for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
3557         parse_external (ext_ptr, fh->fBigendian, pst->section_offsets, pst->objfile);
3558
3559       /* If there are undefined symbols, tell the user.
3560          The alpha has an undefined symbol for every symbol that is
3561          from a shared library, so tell the user only if verbose is on.  */
3562       if (info_verbose && n_undef_symbols)
3563         {
3564           printf_filtered ("File %s contains %d unresolved references:",
3565                            st->filename, n_undef_symbols);
3566           printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
3567                            n_undef_vars, n_undef_procs, n_undef_labels);
3568           n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
3569
3570         }
3571       pop_parse_stack ();
3572
3573       st->primary = 1;
3574
3575       /* Sort the symbol table now, we are done adding symbols to it. */
3576       sort_symtab_syms (st);
3577
3578       sort_blocks (st);
3579     }
3580
3581   /* Now link the psymtab and the symtab.  */
3582   pst->symtab = st;
3583
3584   current_objfile = NULL;
3585 }
3586 \f
3587 /* Ancillary parsing procedures. */
3588
3589 /* Return 1 if the symbol pointed to by SH has a cross reference
3590    to an opaque aggregate type, else 0.  */
3591
3592 static int
3593 has_opaque_xref (FDR *fh, SYMR *sh)
3594 {
3595   TIR tir;
3596   union aux_ext *ax;
3597   RNDXR rn[1];
3598   unsigned int rf;
3599
3600   if (sh->index == indexNil)
3601     return 0;
3602
3603   ax = debug_info->external_aux + fh->iauxBase + sh->index;
3604   (*debug_swap->swap_tir_in) (fh->fBigendian, &ax->a_ti, &tir);
3605   if (tir.bt != btStruct && tir.bt != btUnion && tir.bt != btEnum)
3606     return 0;
3607
3608   ax++;
3609   (*debug_swap->swap_rndx_in) (fh->fBigendian, &ax->a_rndx, rn);
3610   if (rn->rfd == 0xfff)
3611     rf = AUX_GET_ISYM (fh->fBigendian, ax + 1);
3612   else
3613     rf = rn->rfd;
3614   if (rf != -1)
3615     return 0;
3616   return 1;
3617 }
3618
3619 /* Lookup the type at relative index RN.  Return it in TPP
3620    if found and in any event come up with its name PNAME.
3621    BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
3622    Return value says how many aux symbols we ate. */
3623
3624 static int
3625 cross_ref (int fd, union aux_ext *ax, struct type **tpp, enum type_code type_code,      /* Use to alloc new type if none is found. */
3626            char **pname, int bigend, char *sym_name)
3627 {
3628   RNDXR rn[1];
3629   unsigned int rf;
3630   int result = 1;
3631   FDR *fh;
3632   char *esh;
3633   SYMR sh;
3634   int xref_fd;
3635   struct mdebug_pending *pend;
3636
3637   *tpp = (struct type *) NULL;
3638
3639   (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
3640
3641   /* Escape index means 'the next one' */
3642   if (rn->rfd == 0xfff)
3643     {
3644       result++;
3645       rf = AUX_GET_ISYM (bigend, ax + 1);
3646     }
3647   else
3648     {
3649       rf = rn->rfd;
3650     }
3651
3652   /* mips cc uses a rf of -1 for opaque struct definitions.
3653      Set TYPE_FLAG_STUB for these types so that check_typedef will
3654      resolve them if the struct gets defined in another compilation unit.  */
3655   if (rf == -1)
3656     {
3657       *pname = "<undefined>";
3658       *tpp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
3659       TYPE_FLAGS (*tpp) |= TYPE_FLAG_STUB;
3660       return result;
3661     }
3662
3663   /* mips cc uses an escaped rn->index of 0 for struct return types
3664      of procedures that were compiled without -g. These will always remain
3665      undefined.  */
3666   if (rn->rfd == 0xfff && rn->index == 0)
3667     {
3668       *pname = "<undefined>";
3669       return result;
3670     }
3671
3672   /* Find the relative file descriptor and the symbol in it.  */
3673   fh = get_rfd (fd, rf);
3674   xref_fd = fh - debug_info->fdr;
3675
3676   if (rn->index >= fh->csym)
3677     {
3678       /* File indirect entry is corrupt.  */
3679       *pname = "<illegal>";
3680       complain (&bad_rfd_entry_complaint,
3681                 sym_name, xref_fd, rn->index);
3682       return result;
3683     }
3684
3685   /* If we have processed this symbol then we left a forwarding
3686      pointer to the type in the pending list.  If not, we`ll put
3687      it in a list of pending types, to be processed later when
3688      the file will be.  In any event, we collect the name for the
3689      type here.  */
3690
3691   esh = ((char *) debug_info->external_sym
3692          + ((fh->isymBase + rn->index)
3693             * debug_swap->external_sym_size));
3694   (*debug_swap->swap_sym_in) (cur_bfd, esh, &sh);
3695
3696   /* Make sure that this type of cross reference can be handled.  */
3697   if ((sh.sc != scInfo
3698        || (sh.st != stBlock && sh.st != stTypedef && sh.st != stIndirect
3699            && sh.st != stStruct && sh.st != stUnion
3700            && sh.st != stEnum))
3701       && (sh.st != stBlock || !SC_IS_COMMON (sh.sc)))
3702     {
3703       /* File indirect entry is corrupt.  */
3704       *pname = "<illegal>";
3705       complain (&bad_rfd_entry_complaint,
3706                 sym_name, xref_fd, rn->index);
3707       return result;
3708     }
3709
3710   *pname = debug_info->ss + fh->issBase + sh.iss;
3711
3712   pend = is_pending_symbol (fh, esh);
3713   if (pend)
3714     *tpp = pend->t;
3715   else
3716     {
3717       /* We have not yet seen this type.  */
3718
3719       if ((sh.iss == 0 && sh.st == stTypedef) || sh.st == stIndirect)
3720         {
3721           TIR tir;
3722
3723           /* alpha cc puts out a stTypedef with a sh.iss of zero for
3724              two cases:
3725              a) forward declarations of structs/unions/enums which are not
3726              defined in this compilation unit.
3727              For these the type will be void. This is a bad design decision
3728              as cross referencing across compilation units is impossible
3729              due to the missing name.
3730              b) forward declarations of structs/unions/enums/typedefs which
3731              are defined later in this file or in another file in the same
3732              compilation unit. Irix5 cc uses a stIndirect symbol for this.
3733              Simply cross reference those again to get the true type.
3734              The forward references are not entered in the pending list and
3735              in the symbol table.  */
3736
3737           (*debug_swap->swap_tir_in) (bigend,
3738                                       &(debug_info->external_aux
3739                                         + fh->iauxBase + sh.index)->a_ti,
3740                                       &tir);
3741           if (tir.tq0 != tqNil)
3742             complain (&illegal_forward_tq0_complaint, sym_name);
3743           switch (tir.bt)
3744             {
3745             case btVoid:
3746               *tpp = init_type (type_code, 0, 0, (char *) NULL,
3747                                 current_objfile);
3748               *pname = "<undefined>";
3749               break;
3750
3751             case btStruct:
3752             case btUnion:
3753             case btEnum:
3754               cross_ref (xref_fd,
3755                          (debug_info->external_aux
3756                           + fh->iauxBase + sh.index + 1),
3757                          tpp, type_code, pname,
3758                          fh->fBigendian, sym_name);
3759               break;
3760
3761             case btTypedef:
3762               /* Follow a forward typedef. This might recursively
3763                  call cross_ref till we get a non typedef'ed type.
3764                  FIXME: This is not correct behaviour, but gdb currently
3765                  cannot handle typedefs without type copying. Type
3766                  copying is impossible as we might have mutual forward
3767                  references between two files and the copied type would not
3768                  get filled in when we later parse its definition.  */
3769               *tpp = parse_type (xref_fd,
3770                                  debug_info->external_aux + fh->iauxBase,
3771                                  sh.index,
3772                                  (int *) NULL,
3773                                  fh->fBigendian,
3774                                  debug_info->ss + fh->issBase + sh.iss);
3775               add_pending (fh, esh, *tpp);
3776               break;
3777
3778             default:
3779               complain (&illegal_forward_bt_complaint, tir.bt, sym_name);
3780               *tpp = init_type (type_code, 0, 0, (char *) NULL,
3781                                 current_objfile);
3782               break;
3783             }
3784           return result;
3785         }
3786       else if (sh.st == stTypedef)
3787         {
3788           /* Parse the type for a normal typedef. This might recursively call
3789              cross_ref till we get a non typedef'ed type.
3790              FIXME: This is not correct behaviour, but gdb currently
3791              cannot handle typedefs without type copying. But type copying is
3792              impossible as we might have mutual forward references between
3793              two files and the copied type would not get filled in when
3794              we later parse its definition.   */
3795           *tpp = parse_type (xref_fd,
3796                              debug_info->external_aux + fh->iauxBase,
3797                              sh.index,
3798                              (int *) NULL,
3799                              fh->fBigendian,
3800                              debug_info->ss + fh->issBase + sh.iss);
3801         }
3802       else
3803         {
3804           /* Cross reference to a struct/union/enum which is defined
3805              in another file in the same compilation unit but that file
3806              has not been parsed yet.
3807              Initialize the type only, it will be filled in when
3808              it's definition is parsed.  */
3809           *tpp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
3810         }
3811       add_pending (fh, esh, *tpp);
3812     }
3813
3814   /* We used one auxent normally, two if we got a "next one" rf. */
3815   return result;
3816 }
3817
3818
3819 /* Quick&dirty lookup procedure, to avoid the MI ones that require
3820    keeping the symtab sorted */
3821
3822 static struct symbol *
3823 mylookup_symbol (char *name, register struct block *block,
3824                  namespace_enum namespace, enum address_class class)
3825 {
3826   register int bot, top, inc;
3827   register struct symbol *sym;
3828
3829   bot = 0;
3830   top = BLOCK_NSYMS (block);
3831   inc = name[0];
3832   while (bot < top)
3833     {
3834       sym = BLOCK_SYM (block, bot);
3835       if (SYMBOL_NAME (sym)[0] == inc
3836           && SYMBOL_NAMESPACE (sym) == namespace
3837           && SYMBOL_CLASS (sym) == class
3838           && strcmp (SYMBOL_NAME (sym), name) == 0)
3839         return sym;
3840       bot++;
3841     }
3842   block = BLOCK_SUPERBLOCK (block);
3843   if (block)
3844     return mylookup_symbol (name, block, namespace, class);
3845   return 0;
3846 }
3847
3848
3849 /* Add a new symbol S to a block B.
3850    Infrequently, we will need to reallocate the block to make it bigger.
3851    We only detect this case when adding to top_stack->cur_block, since
3852    that's the only time we know how big the block is.  FIXME.  */
3853
3854 static void
3855 add_symbol (struct symbol *s, struct block *b)
3856 {
3857   int nsyms = BLOCK_NSYMS (b)++;
3858   struct block *origb;
3859   struct parse_stack *stackp;
3860
3861   if (b == top_stack->cur_block &&
3862       nsyms >= top_stack->maxsyms)
3863     {
3864       complain (&block_overflow_complaint, SYMBOL_NAME (s));
3865       /* In this case shrink_block is actually grow_block, since
3866          BLOCK_NSYMS(b) is larger than its current size.  */
3867       origb = b;
3868       b = shrink_block (top_stack->cur_block, top_stack->cur_st);
3869
3870       /* Now run through the stack replacing pointers to the
3871          original block.  shrink_block has already done this
3872          for the blockvector and BLOCK_FUNCTION.  */
3873       for (stackp = top_stack; stackp; stackp = stackp->next)
3874         {
3875           if (stackp->cur_block == origb)
3876             {
3877               stackp->cur_block = b;
3878               stackp->maxsyms = BLOCK_NSYMS (b);
3879             }
3880         }
3881     }
3882   BLOCK_SYM (b, nsyms) = s;
3883 }
3884
3885 /* Add a new block B to a symtab S */
3886
3887 static void
3888 add_block (struct block *b, struct symtab *s)
3889 {
3890   struct blockvector *bv = BLOCKVECTOR (s);
3891
3892   bv = (struct blockvector *) xrealloc ((PTR) bv,
3893                                         (sizeof (struct blockvector)
3894                                          + BLOCKVECTOR_NBLOCKS (bv)
3895                                          * sizeof (bv->block)));
3896   if (bv != BLOCKVECTOR (s))
3897     BLOCKVECTOR (s) = bv;
3898
3899   BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
3900 }
3901
3902 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
3903    MIPS' linenumber encoding might need more than one byte
3904    to describe it, LAST is used to detect these continuation lines.
3905
3906    Combining lines with the same line number seems like a bad idea.
3907    E.g: There could be a line number entry with the same line number after the
3908    prologue and GDB should not ignore it (this is a better way to find
3909    a prologue than mips_skip_prologue).
3910    But due to the compressed line table format there are line number entries
3911    for the same line which are needed to bridge the gap to the next
3912    line number entry. These entries have a bogus address info with them
3913    and we are unable to tell them from intended duplicate line number
3914    entries.
3915    This is another reason why -ggdb debugging format is preferable.  */
3916
3917 static int
3918 add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last)
3919 {
3920   /* DEC c89 sometimes produces zero linenos which confuse gdb.
3921      Change them to something sensible. */
3922   if (lineno == 0)
3923     lineno = 1;
3924   if (last == 0)
3925     last = -2;                  /* make sure we record first line */
3926
3927   if (last == lineno)           /* skip continuation lines */
3928     return lineno;
3929
3930   lt->item[lt->nitems].line = lineno;
3931   lt->item[lt->nitems++].pc = adr << 2;
3932   return lineno;
3933 }
3934 \f
3935 /* Sorting and reordering procedures */
3936
3937 /* Blocks with a smaller low bound should come first */
3938
3939 static int
3940 compare_blocks (const PTR arg1, const PTR arg2)
3941 {
3942   register int addr_diff;
3943   struct block **b1 = (struct block **) arg1;
3944   struct block **b2 = (struct block **) arg2;
3945
3946   addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
3947   if (addr_diff == 0)
3948     return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
3949   return addr_diff;
3950 }
3951
3952 /* Sort the blocks of a symtab S.
3953    Reorder the blocks in the blockvector by code-address,
3954    as required by some MI search routines */
3955
3956 static void
3957 sort_blocks (struct symtab *s)
3958 {
3959   struct blockvector *bv = BLOCKVECTOR (s);
3960
3961   if (BLOCKVECTOR_NBLOCKS (bv) <= 2)
3962     {
3963       /* Cosmetic */
3964       if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
3965         BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
3966       if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
3967         BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
3968       return;
3969     }
3970   /*
3971    * This is very unfortunate: normally all functions are compiled in
3972    * the order they are found, but if the file is compiled -O3 things
3973    * are very different.  It would be nice to find a reliable test
3974    * to detect -O3 images in advance.
3975    */
3976   if (BLOCKVECTOR_NBLOCKS (bv) > 3)
3977     qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
3978            BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
3979            sizeof (struct block *),
3980            compare_blocks);
3981
3982   {
3983     register CORE_ADDR high = 0;
3984     register int i, j = BLOCKVECTOR_NBLOCKS (bv);
3985
3986     for (i = FIRST_LOCAL_BLOCK; i < j; i++)
3987       if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
3988         high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
3989     BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
3990   }
3991
3992   BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
3993     BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
3994
3995   BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
3996     BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
3997   BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
3998     BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
3999 }
4000 \f
4001
4002 /* Constructor/restructor/destructor procedures */
4003
4004 /* Allocate a new symtab for NAME.  Needs an estimate of how many symbols
4005    MAXSYMS and linenumbers MAXLINES we'll put in it */
4006
4007 static struct symtab *
4008 new_symtab (char *name, int maxsyms, int maxlines, struct objfile *objfile)
4009 {
4010   struct symtab *s = allocate_symtab (name, objfile);
4011
4012   LINETABLE (s) = new_linetable (maxlines);
4013
4014   /* All symtabs must have at least two blocks */
4015   BLOCKVECTOR (s) = new_bvect (2);
4016   BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = new_block (maxsyms);
4017   BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = new_block (maxsyms);
4018   BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
4019     BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
4020
4021   s->free_code = free_linetable;
4022   s->debugformat = obsavestring ("ECOFF", 5,
4023                                  &objfile->symbol_obstack);
4024   return (s);
4025 }
4026
4027 /* Allocate a new partial_symtab NAME */
4028
4029 static struct partial_symtab *
4030 new_psymtab (char *name, struct objfile *objfile)
4031 {
4032   struct partial_symtab *psymtab;
4033
4034   psymtab = allocate_psymtab (name, objfile);
4035   psymtab->section_offsets = objfile->section_offsets;
4036
4037   /* Keep a backpointer to the file's symbols */
4038
4039   psymtab->read_symtab_private = ((char *)
4040                                   obstack_alloc (&objfile->psymbol_obstack,
4041                                                  sizeof (struct symloc)));
4042   memset ((PTR) psymtab->read_symtab_private, 0, sizeof (struct symloc));
4043   CUR_BFD (psymtab) = cur_bfd;
4044   DEBUG_SWAP (psymtab) = debug_swap;
4045   DEBUG_INFO (psymtab) = debug_info;
4046   PENDING_LIST (psymtab) = pending_list;
4047
4048   /* The way to turn this into a symtab is to call... */
4049   psymtab->read_symtab = mdebug_psymtab_to_symtab;
4050   return (psymtab);
4051 }
4052
4053
4054 /* Allocate a linetable array of the given SIZE.  Since the struct
4055    already includes one item, we subtract one when calculating the
4056    proper size to allocate.  */
4057
4058 static struct linetable *
4059 new_linetable (int size)
4060 {
4061   struct linetable *l;
4062
4063   size = (size - 1) * sizeof (l->item) + sizeof (struct linetable);
4064   l = (struct linetable *) xmalloc (size);
4065   l->nitems = 0;
4066   return l;
4067 }
4068
4069 /* Oops, too big. Shrink it.  This was important with the 2.4 linetables,
4070    I am not so sure about the 3.4 ones.
4071
4072    Since the struct linetable already includes one item, we subtract one when
4073    calculating the proper size to allocate.  */
4074
4075 static struct linetable *
4076 shrink_linetable (struct linetable *lt)
4077 {
4078
4079   return (struct linetable *) xrealloc ((PTR) lt,
4080                                         (sizeof (struct linetable)
4081                                          + ((lt->nitems - 1)
4082                                             * sizeof (lt->item))));
4083 }
4084
4085 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
4086
4087 static struct blockvector *
4088 new_bvect (int nblocks)
4089 {
4090   struct blockvector *bv;
4091   int size;
4092
4093   size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
4094   bv = (struct blockvector *) xzalloc (size);
4095
4096   BLOCKVECTOR_NBLOCKS (bv) = nblocks;
4097
4098   return bv;
4099 }
4100
4101 /* Allocate and zero a new block of MAXSYMS symbols */
4102
4103 static struct block *
4104 new_block (int maxsyms)
4105 {
4106   int size = sizeof (struct block) + (maxsyms - 1) * sizeof (struct symbol *);
4107
4108   return (struct block *) xzalloc (size);
4109 }
4110
4111 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
4112    Shrink_block can also be used by add_symbol to grow a block.  */
4113
4114 static struct block *
4115 shrink_block (struct block *b, struct symtab *s)
4116 {
4117   struct block *new;
4118   struct blockvector *bv = BLOCKVECTOR (s);
4119   int i;
4120
4121   /* Just reallocate it and fix references to the old one */
4122
4123   new = (struct block *) xrealloc ((PTR) b,
4124                                    (sizeof (struct block)
4125                                     + ((BLOCK_NSYMS (b) - 1)
4126                                        * sizeof (struct symbol *))));
4127
4128   /* Should chase pointers to old one.  Fortunately, that`s just
4129      the block`s function and inferior blocks */
4130   if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b)
4131     SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
4132   for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
4133     if (BLOCKVECTOR_BLOCK (bv, i) == b)
4134       BLOCKVECTOR_BLOCK (bv, i) = new;
4135     else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b)
4136       BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = new;
4137   return new;
4138 }
4139
4140 /* Create a new symbol with printname NAME */
4141
4142 static struct symbol *
4143 new_symbol (char *name)
4144 {
4145   struct symbol *s = ((struct symbol *)
4146                       obstack_alloc (&current_objfile->symbol_obstack,
4147                                      sizeof (struct symbol)));
4148
4149   memset ((PTR) s, 0, sizeof (*s));
4150   SYMBOL_NAME (s) = obsavestring (name, strlen (name),
4151                                   &current_objfile->symbol_obstack);
4152   SYMBOL_LANGUAGE (s) = psymtab_language;
4153   SYMBOL_INIT_DEMANGLED_NAME (s, &current_objfile->symbol_obstack);
4154   return s;
4155 }
4156
4157 /* Create a new type with printname NAME */
4158
4159 static struct type *
4160 new_type (char *name)
4161 {
4162   struct type *t;
4163
4164   t = alloc_type (current_objfile);
4165   TYPE_NAME (t) = name;
4166   TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default;
4167   return t;
4168 }
4169 \f
4170 /* Read ECOFF debugging information from a BFD section.  This is
4171    called from elfread.c.  It parses the section into a
4172    ecoff_debug_info struct, and then lets the rest of the file handle
4173    it as normal.  */
4174
4175 void
4176 elfmdebug_build_psymtabs (struct objfile *objfile,
4177                           const struct ecoff_debug_swap *swap, asection *sec)
4178 {
4179   bfd *abfd = objfile->obfd;
4180   struct ecoff_debug_info *info;
4181
4182   info = ((struct ecoff_debug_info *)
4183           obstack_alloc (&objfile->psymbol_obstack,
4184                          sizeof (struct ecoff_debug_info)));
4185
4186   if (!(*swap->read_debug_info) (abfd, sec, info))
4187     error ("Error reading ECOFF debugging information: %s",
4188            bfd_errmsg (bfd_get_error ()));
4189
4190   mdebug_build_psymtabs (objfile, swap, info);
4191 }
4192 \f
4193
4194 /* Things used for calling functions in the inferior.
4195    These functions are exported to our companion
4196    mips-tdep.c file and are here because they play
4197    with the symbol-table explicitly. */
4198
4199 /* Sigtramp: make sure we have all the necessary information
4200    about the signal trampoline code. Since the official code
4201    from MIPS does not do so, we make up that information ourselves.
4202    If they fix the library (unlikely) this code will neutralize itself. */
4203
4204 /* FIXME: This function is called only by mips-tdep.c.  It needs to be
4205    here because it calls functions defined in this file, but perhaps
4206    this could be handled in a better way.  Only compile it in when
4207    tm-mips.h is included. */
4208
4209 #ifdef TM_MIPS_H
4210
4211 void
4212 fixup_sigtramp (void)
4213 {
4214   struct symbol *s;
4215   struct symtab *st;
4216   struct block *b, *b0 = NULL;
4217
4218   sigtramp_address = -1;
4219
4220   /* We have to handle the following cases here:
4221      a) The Mips library has a sigtramp label within sigvec.
4222      b) Irix has a _sigtramp which we want to use, but it also has sigvec.  */
4223   s = lookup_symbol ("sigvec", 0, VAR_NAMESPACE, 0, NULL);
4224   if (s != 0)
4225     {
4226       b0 = SYMBOL_BLOCK_VALUE (s);
4227       s = lookup_symbol ("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
4228     }
4229   if (s == 0)
4230     {
4231       /* No sigvec or no sigtramp inside sigvec, try _sigtramp.  */
4232       s = lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE, 0, NULL);
4233     }
4234
4235   /* But maybe this program uses its own version of sigvec */
4236   if (s == 0)
4237     return;
4238
4239   /* Did we or MIPSco fix the library ? */
4240   if (SYMBOL_CLASS (s) == LOC_BLOCK)
4241     {
4242       sigtramp_address = BLOCK_START (SYMBOL_BLOCK_VALUE (s));
4243       sigtramp_end = BLOCK_END (SYMBOL_BLOCK_VALUE (s));
4244       return;
4245     }
4246
4247   sigtramp_address = SYMBOL_VALUE (s);
4248   sigtramp_end = sigtramp_address + 0x88;       /* black magic */
4249
4250   /* But what symtab does it live in ? */
4251   st = find_pc_symtab (SYMBOL_VALUE (s));
4252
4253   /*
4254    * Ok, there goes the fix: turn it into a procedure, with all the
4255    * needed info.  Note we make it a nested procedure of sigvec,
4256    * which is the way the (assembly) code is actually written.
4257    */
4258   SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
4259   SYMBOL_CLASS (s) = LOC_BLOCK;
4260   SYMBOL_TYPE (s) = init_type (TYPE_CODE_FUNC, 4, 0, (char *) NULL,
4261                                st->objfile);
4262   TYPE_TARGET_TYPE (SYMBOL_TYPE (s)) = mdebug_type_void;
4263
4264   /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
4265   b = new_block (1);
4266   SYMBOL_BLOCK_VALUE (s) = b;
4267   BLOCK_START (b) = sigtramp_address;
4268   BLOCK_END (b) = sigtramp_end;
4269   BLOCK_FUNCTION (b) = s;
4270   BLOCK_SUPERBLOCK (b) = BLOCK_SUPERBLOCK (b0);
4271   add_block (b, st);
4272   sort_blocks (st);
4273
4274   /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
4275   {
4276     struct mips_extra_func_info *e =
4277     ((struct mips_extra_func_info *)
4278      xzalloc (sizeof (struct mips_extra_func_info)));
4279
4280     e->numargs = 0;             /* the kernel thinks otherwise */
4281     e->pdr.frameoffset = 32;
4282     e->pdr.framereg = SP_REGNUM;
4283     /* Note that setting pcreg is no longer strictly necessary as
4284        mips_frame_saved_pc is now aware of signal handler frames.  */
4285     e->pdr.pcreg = PC_REGNUM;
4286     e->pdr.regmask = -2;
4287     /* Offset to saved r31, in the sigtramp case the saved registers
4288        are above the frame in the sigcontext.
4289        We have 4 alignment bytes, 12 bytes for onstack, mask and pc,
4290        32 * 4 bytes for the general registers, 12 bytes for mdhi, mdlo, ownedfp
4291        and 32 * 4 bytes for the floating point registers.  */
4292     e->pdr.regoffset = 4 + 12 + 31 * 4;
4293     e->pdr.fregmask = -1;
4294     /* Offset to saved f30 (first saved *double* register).  */
4295     e->pdr.fregoffset = 4 + 12 + 32 * 4 + 12 + 30 * 4;
4296     e->pdr.isym = (long) s;
4297     e->pdr.adr = sigtramp_address;
4298
4299     current_objfile = st->objfile;      /* Keep new_symbol happy */
4300     s = new_symbol (MIPS_EFI_SYMBOL_NAME);
4301     SYMBOL_VALUE (s) = (long) e;
4302     SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
4303     SYMBOL_CLASS (s) = LOC_CONST;
4304     SYMBOL_TYPE (s) = mdebug_type_void;
4305     current_objfile = NULL;
4306   }
4307
4308   BLOCK_SYM (b, BLOCK_NSYMS (b)++) = s;
4309 }
4310
4311 #endif /* TM_MIPS_H */
4312
4313 void
4314 _initialize_mdebugread (void)
4315 {
4316   mdebug_type_void =
4317     init_type (TYPE_CODE_VOID, 1,
4318                0,
4319                "void", (struct objfile *) NULL);
4320   mdebug_type_char =
4321     init_type (TYPE_CODE_INT, 1,
4322                0,
4323                "char", (struct objfile *) NULL);
4324   mdebug_type_unsigned_char =
4325     init_type (TYPE_CODE_INT, 1,
4326                TYPE_FLAG_UNSIGNED,
4327                "unsigned char", (struct objfile *) NULL);
4328   mdebug_type_short =
4329     init_type (TYPE_CODE_INT, 2,
4330                0,
4331                "short", (struct objfile *) NULL);
4332   mdebug_type_unsigned_short =
4333     init_type (TYPE_CODE_INT, 2,
4334                TYPE_FLAG_UNSIGNED,
4335                "unsigned short", (struct objfile *) NULL);
4336   mdebug_type_int_32 =
4337     init_type (TYPE_CODE_INT, 4,
4338                0,
4339                "int", (struct objfile *) NULL);
4340   mdebug_type_unsigned_int_32 =
4341     init_type (TYPE_CODE_INT, 4,
4342                TYPE_FLAG_UNSIGNED,
4343                "unsigned int", (struct objfile *) NULL);
4344   mdebug_type_int_64 =
4345     init_type (TYPE_CODE_INT, 8,
4346                0,
4347                "int", (struct objfile *) NULL);
4348   mdebug_type_unsigned_int_64 =
4349     init_type (TYPE_CODE_INT, 8,
4350                TYPE_FLAG_UNSIGNED,
4351                "unsigned int", (struct objfile *) NULL);
4352   mdebug_type_long_32 =
4353     init_type (TYPE_CODE_INT, 4,
4354                0,
4355                "long", (struct objfile *) NULL);
4356   mdebug_type_unsigned_long_32 =
4357     init_type (TYPE_CODE_INT, 4,
4358                TYPE_FLAG_UNSIGNED,
4359                "unsigned long", (struct objfile *) NULL);
4360   mdebug_type_long_64 =
4361     init_type (TYPE_CODE_INT, 8,
4362                0,
4363                "long", (struct objfile *) NULL);
4364   mdebug_type_unsigned_long_64 =
4365     init_type (TYPE_CODE_INT, 8,
4366                TYPE_FLAG_UNSIGNED,
4367                "unsigned long", (struct objfile *) NULL);
4368   mdebug_type_long_long_64 =
4369     init_type (TYPE_CODE_INT, 8,
4370                0,
4371                "long long", (struct objfile *) NULL);
4372   mdebug_type_unsigned_long_long_64 =
4373     init_type (TYPE_CODE_INT, 8,
4374                TYPE_FLAG_UNSIGNED,
4375                "unsigned long long", (struct objfile *) NULL);
4376   mdebug_type_adr_32 =
4377     init_type (TYPE_CODE_PTR, 4,
4378                TYPE_FLAG_UNSIGNED,
4379                "adr_32", (struct objfile *) NULL);
4380   TYPE_TARGET_TYPE (mdebug_type_adr_32) = mdebug_type_void;
4381   mdebug_type_adr_64 =
4382     init_type (TYPE_CODE_PTR, 8,
4383                TYPE_FLAG_UNSIGNED,
4384                "adr_64", (struct objfile *) NULL);
4385   TYPE_TARGET_TYPE (mdebug_type_adr_64) = mdebug_type_void;
4386   mdebug_type_float =
4387     init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
4388                0,
4389                "float", (struct objfile *) NULL);
4390   mdebug_type_double =
4391     init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
4392                0,
4393                "double", (struct objfile *) NULL);
4394   mdebug_type_complex =
4395     init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
4396                0,
4397                "complex", (struct objfile *) NULL);
4398   TYPE_TARGET_TYPE (mdebug_type_complex) = mdebug_type_float;
4399   mdebug_type_double_complex =
4400     init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
4401                0,
4402                "double complex", (struct objfile *) NULL);
4403   TYPE_TARGET_TYPE (mdebug_type_double_complex) = mdebug_type_double;
4404
4405   /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
4406      FIXME.  */
4407   mdebug_type_string =
4408     init_type (TYPE_CODE_STRING,
4409                TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4410                0, "string",
4411                (struct objfile *) NULL);
4412
4413   /* We use TYPE_CODE_INT to print these as integers.  Does this do any
4414      good?  Would we be better off with TYPE_CODE_ERROR?  Should
4415      TYPE_CODE_ERROR print things in hex if it knows the size?  */
4416   mdebug_type_fixed_dec =
4417     init_type (TYPE_CODE_INT,
4418                TARGET_INT_BIT / TARGET_CHAR_BIT,
4419                0, "fixed decimal",
4420                (struct objfile *) NULL);
4421
4422   mdebug_type_float_dec =
4423     init_type (TYPE_CODE_ERROR,
4424                TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
4425                0, "floating decimal",
4426                (struct objfile *) NULL);
4427
4428   nodebug_func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
4429                                         "<function, no debug info>", NULL);
4430   TYPE_TARGET_TYPE (nodebug_func_symbol_type) = mdebug_type_int;
4431   nodebug_var_symbol_type =
4432     init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
4433                "<variable, no debug info>", NULL);
4434 }