OSDN Git Service

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