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