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