GDB (API)
/home/stan/gdb/src/gdb/mdebugread.c
Go to the documentation of this file.
00001 /* Read a symbol table in ECOFF format (Third-Eye).
00002 
00003    Copyright (C) 1986-2013 Free Software Foundation, Inc.
00004 
00005    Original version contributed by Alessandro Forin (af@cs.cmu.edu) at
00006    CMU.  Major work by Per Bothner, John Gilmore and Ian Lance Taylor
00007    at Cygnus Support.
00008 
00009    This file is part of GDB.
00010 
00011    This program is free software; you can redistribute it and/or modify
00012    it under the terms of the GNU General Public License as published by
00013    the Free Software Foundation; either version 3 of the License, or
00014    (at your option) any later version.
00015 
00016    This program is distributed in the hope that it will be useful,
00017    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019    GNU General Public License for more details.
00020 
00021    You should have received a copy of the GNU General Public License
00022    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00023 
00024 /* This module provides the function mdebug_build_psymtabs.  It reads
00025    ECOFF debugging information into partial symbol tables.  The
00026    debugging information is read from two structures.  A struct
00027    ecoff_debug_swap includes the sizes of each ECOFF structure and
00028    swapping routines; these are fixed for a particular target.  A
00029    struct ecoff_debug_info points to the debugging information for a
00030    particular object file.
00031 
00032    ECOFF symbol tables are mostly written in the byte order of the
00033    target machine.  However, one section of the table (the auxiliary
00034    symbol information) is written in the host byte order.  There is a
00035    bit in the other symbol info which describes which host byte order
00036    was used.  ECOFF thereby takes the trophy from Intel `b.out' for
00037    the most brain-dead adaptation of a file format to byte order.
00038 
00039    This module can read all four of the known byte-order combinations,
00040    on any type of host.  */
00041 
00042 #include "defs.h"
00043 #include "symtab.h"
00044 #include "gdbtypes.h"
00045 #include "gdbcore.h"
00046 #include "filenames.h"
00047 #include "objfiles.h"
00048 #include "gdb_obstack.h"
00049 #include "buildsym.h"
00050 #include "stabsread.h"
00051 #include "complaints.h"
00052 #include "demangle.h"
00053 #include "gdb-demangle.h"
00054 #include "gdb_assert.h"
00055 #include "block.h"
00056 #include "dictionary.h"
00057 #include "mdebugread.h"
00058 #include "gdb_stat.h"
00059 #include "gdb_string.h"
00060 #include "psympriv.h"
00061 #include "source.h"
00062 
00063 #include "bfd.h"
00064 
00065 #include "coff/ecoff.h"         /* COFF-like aspects of ecoff files.  */
00066 
00067 #include "libaout.h"            /* Private BFD a.out information.  */
00068 #include "aout/aout64.h"
00069 #include "aout/stab_gnu.h"      /* STABS information.  */
00070 
00071 #include "expression.h"
00072 
00073 extern void _initialize_mdebugread (void);
00074 
00075 /* Provide a way to test if we have both ECOFF and ELF symbol tables.
00076    We use this define in order to know whether we should override a 
00077    symbol's ECOFF section with its ELF section.  This is necessary in 
00078    case the symbol's ELF section could not be represented in ECOFF.  */
00079 #define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
00080                            && bfd_get_section_by_name (bfd, ".mdebug") != NULL)
00081 
00082 /* The objfile we are currently reading.  */
00083 
00084 static struct objfile *mdebugread_objfile;
00085 
00086 
00087 
00088 /* We put a pointer to this structure in the read_symtab_private field
00089    of the psymtab.  */
00090 
00091 struct symloc
00092   {
00093     /* Index of the FDR that this psymtab represents.  */
00094     int fdr_idx;
00095     /* The BFD that the psymtab was created from.  */
00096     bfd *cur_bfd;
00097     const struct ecoff_debug_swap *debug_swap;
00098     struct ecoff_debug_info *debug_info;
00099     struct mdebug_pending **pending_list;
00100     /* Pointer to external symbols for this file.  */
00101     EXTR *extern_tab;
00102     /* Size of extern_tab.  */
00103     int extern_count;
00104     enum language pst_language;
00105   };
00106 
00107 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
00108 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
00109 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
00110 #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
00111 #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
00112 #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
00113 
00114 #define SC_IS_TEXT(sc) ((sc) == scText \
00115                    || (sc) == scRConst \
00116                    || (sc) == scInit \
00117                    || (sc) == scFini)
00118 #define SC_IS_DATA(sc) ((sc) == scData \
00119                    || (sc) == scSData \
00120                    || (sc) == scRData \
00121                    || (sc) == scPData \
00122                    || (sc) == scXData)
00123 #define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon)
00124 #define SC_IS_BSS(sc) ((sc) == scBss)
00125 #define SC_IS_SBSS(sc) ((sc) == scSBss)
00126 #define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined)
00127 
00128 /* Various complaints about symbol reading that don't abort the process.  */
00129 static void
00130 index_complaint (const char *arg1)
00131 {
00132   complaint (&symfile_complaints, _("bad aux index at symbol %s"), arg1);
00133 }
00134 
00135 static void
00136 unknown_ext_complaint (const char *arg1)
00137 {
00138   complaint (&symfile_complaints, _("unknown external symbol %s"), arg1);
00139 }
00140 
00141 static void
00142 basic_type_complaint (int arg1, const char *arg2)
00143 {
00144   complaint (&symfile_complaints, _("cannot map ECOFF basic type 0x%x for %s"),
00145              arg1, arg2);
00146 }
00147 
00148 static void
00149 bad_tag_guess_complaint (const char *arg1)
00150 {
00151   complaint (&symfile_complaints,
00152              _("guessed tag type of %s incorrectly"), arg1);
00153 }
00154 
00155 static void
00156 bad_rfd_entry_complaint (const char *arg1, int arg2, int arg3)
00157 {
00158   complaint (&symfile_complaints, _("bad rfd entry for %s: file %d, index %d"),
00159              arg1, arg2, arg3);
00160 }
00161 
00162 static void
00163 unexpected_type_code_complaint (const char *arg1)
00164 {
00165   complaint (&symfile_complaints, _("unexpected type code for %s"), arg1);
00166 }
00167 
00168 /* Macros and extra defs.  */
00169 
00170 /* Puns: hard to find whether -g was used and how.  */
00171 
00172 #define MIN_GLEVEL GLEVEL_0
00173 #define compare_glevel(a,b)                                     \
00174         (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) :                 \
00175          ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
00176 
00177 /* Things that really are local to this module.  */
00178 
00179 /* Remember what we deduced to be the source language of this psymtab.  */
00180 
00181 static enum language psymtab_language = language_unknown;
00182 
00183 /* Current BFD.  */
00184 
00185 static bfd *cur_bfd;
00186 
00187 /* How to parse debugging information for CUR_BFD.  */
00188 
00189 static const struct ecoff_debug_swap *debug_swap;
00190 
00191 /* Pointers to debugging information for CUR_BFD.  */
00192 
00193 static struct ecoff_debug_info *debug_info;
00194 
00195 /* Pointer to current file decriptor record, and its index.  */
00196 
00197 static FDR *cur_fdr;
00198 static int cur_fd;
00199 
00200 /* Index of current symbol.  */
00201 
00202 static int cur_sdx;
00203 
00204 /* Note how much "debuggable" this image is.  We would like
00205    to see at least one FDR with full symbols.  */
00206 
00207 static int max_gdbinfo;
00208 static int max_glevel;
00209 
00210 /* When examining .o files, report on undefined symbols.  */
00211 
00212 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
00213 
00214 /* Pseudo symbol to use when putting stabs into the symbol table.  */
00215 
00216 static char stabs_symbol[] = STABS_SYMBOL;
00217 
00218 /* Nonzero if we have seen ecoff debugging info for a file.  */
00219 
00220 static int found_ecoff_debugging_info;
00221 
00222 /* Forward declarations.  */
00223 
00224 static int upgrade_type (int, struct type **, int, union aux_ext *,
00225                          int, char *);
00226 
00227 static void parse_partial_symbols (struct objfile *);
00228 
00229 static int has_opaque_xref (FDR *, SYMR *);
00230 
00231 static int cross_ref (int, union aux_ext *, struct type **, enum type_code,
00232                       char **, int, char *);
00233 
00234 static struct symbol *new_symbol (char *);
00235 
00236 static struct type *new_type (char *);
00237 
00238 enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK };
00239 
00240 static struct block *new_block (enum block_type);
00241 
00242 static struct symtab *new_symtab (const char *, int, struct objfile *);
00243 
00244 static struct linetable *new_linetable (int);
00245 
00246 static struct blockvector *new_bvect (int);
00247 
00248 static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
00249                                 int, char *);
00250 
00251 static struct symbol *mylookup_symbol (char *, struct block *, domain_enum,
00252                                        enum address_class);
00253 
00254 static void sort_blocks (struct symtab *);
00255 
00256 static struct partial_symtab *new_psymtab (char *, struct objfile *);
00257 
00258 static void psymtab_to_symtab_1 (struct objfile *objfile,
00259                                  struct partial_symtab *, const char *);
00260 
00261 static void add_block (struct block *, struct symtab *);
00262 
00263 static void add_symbol (struct symbol *, struct symtab *, struct block *);
00264 
00265 static int add_line (struct linetable *, int, CORE_ADDR, int);
00266 
00267 static struct linetable *shrink_linetable (struct linetable *);
00268 
00269 static void handle_psymbol_enumerators (struct objfile *, FDR *, int,
00270                                         CORE_ADDR);
00271 
00272 static char *mdebug_next_symbol_text (struct objfile *);
00273 
00274 /* Exported procedure: Builds a symtab from the partial symtab SELF.
00275    Restores the environment in effect when SELF was created, delegates
00276    most of the work to an ancillary procedure, and sorts
00277    and reorders the symtab list at the end.  SELF is not NULL.  */
00278 
00279 static void
00280 mdebug_read_symtab (struct partial_symtab *self, struct objfile *objfile)
00281 {
00282   if (info_verbose)
00283     {
00284       printf_filtered (_("Reading in symbols for %s..."), self->filename);
00285       gdb_flush (gdb_stdout);
00286     }
00287 
00288   next_symbol_text_func = mdebug_next_symbol_text;
00289 
00290   psymtab_to_symtab_1 (objfile, self, self->filename);
00291 
00292   /* Match with global symbols.  This only needs to be done once,
00293      after all of the symtabs and dependencies have been read in.  */
00294   scan_file_globals (objfile);
00295 
00296   if (info_verbose)
00297     printf_filtered (_("done.\n"));
00298 }
00299 
00300 /* File-level interface functions.  */
00301 
00302 /* Find a file descriptor given its index RF relative to a file CF.  */
00303 
00304 static FDR *
00305 get_rfd (int cf, int rf)
00306 {
00307   FDR *fdrs;
00308   FDR *f;
00309   RFDT rfd;
00310 
00311   fdrs = debug_info->fdr;
00312   f = fdrs + cf;
00313   /* Object files do not have the RFD table, all refs are absolute.  */
00314   if (f->rfdBase == 0)
00315     return fdrs + rf;
00316   (*debug_swap->swap_rfd_in) (cur_bfd,
00317                               ((char *) debug_info->external_rfd
00318                                + ((f->rfdBase + rf)
00319                                   * debug_swap->external_rfd_size)),
00320                               &rfd);
00321   return fdrs + rfd;
00322 }
00323 
00324 /* Return a safer print NAME for a file descriptor.  */
00325 
00326 static char *
00327 fdr_name (FDR *f)
00328 {
00329   if (f->rss == -1)
00330     return "<stripped file>";
00331   if (f->rss == 0)
00332     return "<NFY>";
00333   return debug_info->ss + f->issBase + f->rss;
00334 }
00335 
00336 
00337 /* Read in and parse the symtab of the file OBJFILE.  Symbols from
00338    different sections are relocated via the SECTION_OFFSETS.  */
00339 
00340 void
00341 mdebug_build_psymtabs (struct objfile *objfile,
00342                        const struct ecoff_debug_swap *swap,
00343                        struct ecoff_debug_info *info)
00344 {
00345   cur_bfd = objfile->obfd;
00346   debug_swap = swap;
00347   debug_info = info;
00348 
00349   stabsread_new_init ();
00350   buildsym_new_init ();
00351   free_header_files ();
00352   init_header_files ();
00353         
00354   /* Make sure all the FDR information is swapped in.  */
00355   if (info->fdr == (FDR *) NULL)
00356     {
00357       char *fdr_src;
00358       char *fdr_end;
00359       FDR *fdr_ptr;
00360 
00361       info->fdr = (FDR *) obstack_alloc (&objfile->objfile_obstack,
00362                                          (info->symbolic_header.ifdMax
00363                                           * sizeof (FDR)));
00364       fdr_src = info->external_fdr;
00365       fdr_end = (fdr_src
00366                  + info->symbolic_header.ifdMax * swap->external_fdr_size);
00367       fdr_ptr = info->fdr;
00368       for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++)
00369         (*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
00370     }
00371 
00372   parse_partial_symbols (objfile);
00373 
00374 #if 0
00375   /* Check to make sure file was compiled with -g.  If not, warn the
00376      user of this limitation.  */
00377   if (compare_glevel (max_glevel, GLEVEL_2) < 0)
00378     {
00379       if (max_gdbinfo == 0)
00380         printf_unfiltered (_("\n%s not compiled with -g, "
00381                              "debugging support is limited.\n"),
00382                            objfile->name);
00383       printf_unfiltered (_("You should compile with -g2 or "
00384                            "-g3 for best debugging support.\n"));
00385       gdb_flush (gdb_stdout);
00386     }
00387 #endif
00388 }
00389 
00390 /* Local utilities */
00391 
00392 /* Map of FDR indexes to partial symtabs.  */
00393 
00394 struct pst_map
00395 {
00396   struct partial_symtab *pst;   /* the psymtab proper */
00397   long n_globals;               /* exported globals (external symbols) */
00398   long globals_offset;          /* cumulative */
00399 };
00400 
00401 
00402 /* Utility stack, used to nest procedures and blocks properly.
00403    It is a doubly linked list, to avoid too many alloc/free.
00404    Since we might need it quite a few times it is NOT deallocated
00405    after use.  */
00406 
00407 static struct parse_stack
00408   {
00409     struct parse_stack *next, *prev;
00410     struct symtab *cur_st;      /* Current symtab.  */
00411     struct block *cur_block;    /* Block in it.  */
00412 
00413     /* What are we parsing.  stFile, or stBlock are for files and
00414        blocks.  stProc or stStaticProc means we have seen the start of a
00415        procedure, but not the start of the block within in.  When we see
00416        the start of that block, we change it to stNil, without pushing a
00417        new block, i.e. stNil means both a procedure and a block.  */
00418 
00419     int blocktype;
00420 
00421     struct type *cur_type;      /* Type we parse fields for.  */
00422     int cur_field;              /* Field number in cur_type.  */
00423     CORE_ADDR procadr;          /* Start addres of this procedure.  */
00424     int numargs;                /* Its argument count.  */
00425   }
00426 
00427  *top_stack;                    /* Top stack ptr */
00428 
00429 
00430 /* Enter a new lexical context.  */
00431 
00432 static void
00433 push_parse_stack (void)
00434 {
00435   struct parse_stack *new;
00436 
00437   /* Reuse frames if possible.  */
00438   if (top_stack && top_stack->prev)
00439     new = top_stack->prev;
00440   else
00441     new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack));
00442   /* Initialize new frame with previous content.  */
00443   if (top_stack)
00444     {
00445       struct parse_stack *prev = new->prev;
00446 
00447       *new = *top_stack;
00448       top_stack->prev = new;
00449       new->prev = prev;
00450       new->next = top_stack;
00451     }
00452   top_stack = new;
00453 }
00454 
00455 /* Exit a lexical context.  */
00456 
00457 static void
00458 pop_parse_stack (void)
00459 {
00460   if (!top_stack)
00461     return;
00462   if (top_stack->next)
00463     top_stack = top_stack->next;
00464 }
00465 
00466 
00467 /* Cross-references might be to things we haven't looked at
00468    yet, e.g. type references.  To avoid too many type
00469    duplications we keep a quick fixup table, an array
00470    of lists of references indexed by file descriptor.  */
00471 
00472 struct mdebug_pending
00473 {
00474   struct mdebug_pending *next;  /* link */
00475   char *s;                      /* the unswapped symbol */
00476   struct type *t;               /* its partial type descriptor */
00477 };
00478 
00479 
00480 /* The pending information is kept for an entire object file.  We
00481    allocate the pending information table when we create the partial
00482    symbols, and we store a pointer to the single table in each
00483    psymtab.  */
00484 
00485 static struct mdebug_pending **pending_list;
00486 
00487 /* Check whether we already saw symbol SH in file FH.  */
00488 
00489 static struct mdebug_pending *
00490 is_pending_symbol (FDR *fh, char *sh)
00491 {
00492   int f_idx = fh - debug_info->fdr;
00493   struct mdebug_pending *p;
00494 
00495   /* Linear search is ok, list is typically no more than 10 deep.  */
00496   for (p = pending_list[f_idx]; p; p = p->next)
00497     if (p->s == sh)
00498       break;
00499   return p;
00500 }
00501 
00502 /* Add a new symbol SH of type T.  */
00503 
00504 static void
00505 add_pending (FDR *fh, char *sh, struct type *t)
00506 {
00507   int f_idx = fh - debug_info->fdr;
00508   struct mdebug_pending *p = is_pending_symbol (fh, sh);
00509 
00510   /* Make sure we do not make duplicates.  */
00511   if (!p)
00512     {
00513       p = ((struct mdebug_pending *)
00514            obstack_alloc (&mdebugread_objfile->objfile_obstack,
00515                           sizeof (struct mdebug_pending)));
00516       p->s = sh;
00517       p->t = t;
00518       p->next = pending_list[f_idx];
00519       pending_list[f_idx] = p;
00520     }
00521 }
00522 
00523 
00524 /* Parsing Routines proper.  */
00525 
00526 /* Parse a single symbol.  Mostly just make up a GDB symbol for it.
00527    For blocks, procedures and types we open a new lexical context.
00528    This is basically just a big switch on the symbol's type.  Argument
00529    AX is the base pointer of aux symbols for this file (fh->iauxBase).
00530    EXT_SH points to the unswapped symbol, which is needed for struct,
00531    union, etc., types; it is NULL for an EXTR.  BIGEND says whether
00532    aux symbols are big-endian or little-endian.  Return count of
00533    SYMR's handled (normally one).  */
00534 
00535 static int
00536 mdebug_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
00537 {
00538   return gdbarch_ecoff_reg_to_regnum (gdbarch, SYMBOL_VALUE (sym));
00539 }
00540 
00541 static const struct symbol_register_ops mdebug_register_funcs = {
00542   mdebug_reg_to_regnum
00543 };
00544 
00545 /* The "aclass" indices for computed symbols.  */
00546 
00547 static int mdebug_register_index;
00548 static int mdebug_regparm_index;
00549 
00550 static int
00551 parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
00552               struct section_offsets *section_offsets, struct objfile *objfile)
00553 {
00554   struct gdbarch *gdbarch = get_objfile_arch (objfile);
00555   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
00556   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
00557   char *name;
00558   struct symbol *s;
00559   struct block *b;
00560   struct mdebug_pending *pend;
00561   struct type *t;
00562   struct field *f;
00563   int count = 1;
00564   enum address_class class;
00565   TIR tir;
00566   long svalue = sh->value;
00567   int bitsize;
00568 
00569   if (ext_sh == (char *) NULL)
00570     name = debug_info->ssext + sh->iss;
00571   else
00572     name = debug_info->ss + cur_fdr->issBase + sh->iss;
00573 
00574   switch (sh->sc)
00575     {
00576     case scText:
00577     case scRConst:
00578       /* Do not relocate relative values.
00579          The value of a stEnd symbol is the displacement from the
00580          corresponding start symbol value.
00581          The value of a stBlock symbol is the displacement from the
00582          procedure address.  */
00583       if (sh->st != stEnd && sh->st != stBlock)
00584         sh->value += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
00585       break;
00586     case scData:
00587     case scSData:
00588     case scRData:
00589     case scPData:
00590     case scXData:
00591       sh->value += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
00592       break;
00593     case scBss:
00594     case scSBss:
00595       sh->value += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
00596       break;
00597     }
00598 
00599   switch (sh->st)
00600     {
00601     case stNil:
00602       break;
00603 
00604     case stGlobal:              /* External symbol, goes into global block.  */
00605       class = LOC_STATIC;
00606       b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
00607                              GLOBAL_BLOCK);
00608       s = new_symbol (name);
00609       SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
00610       goto data;
00611 
00612     case stStatic:              /* Static data, goes into current block.  */
00613       class = LOC_STATIC;
00614       b = top_stack->cur_block;
00615       s = new_symbol (name);
00616       if (SC_IS_COMMON (sh->sc))
00617         {
00618           /* It is a FORTRAN common block.  At least for SGI Fortran the
00619              address is not in the symbol; we need to fix it later in
00620              scan_file_globals.  */
00621           int bucket = hashname (SYMBOL_LINKAGE_NAME (s));
00622           SYMBOL_VALUE_CHAIN (s) = global_sym_chain[bucket];
00623           global_sym_chain[bucket] = s;
00624         }
00625       else
00626         SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
00627       goto data;
00628 
00629     case stLocal:               /* Local variable, goes into current block.  */
00630       b = top_stack->cur_block;
00631       s = new_symbol (name);
00632       SYMBOL_VALUE (s) = svalue;
00633       if (sh->sc == scRegister)
00634         class = mdebug_register_index;
00635       else
00636         class = LOC_LOCAL;
00637 
00638     data:                       /* Common code for symbols describing data.  */
00639       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
00640       SYMBOL_ACLASS_INDEX (s) = class;
00641       add_symbol (s, top_stack->cur_st, b);
00642 
00643       /* Type could be missing if file is compiled without debugging info.  */
00644       if (SC_IS_UNDEF (sh->sc)
00645           || sh->sc == scNil || sh->index == indexNil)
00646         SYMBOL_TYPE (s) = objfile_type (objfile)->nodebug_data_symbol;
00647       else
00648         SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
00649       /* Value of a data symbol is its memory address.  */
00650       break;
00651 
00652     case stParam:               /* Arg to procedure, goes into current
00653                                    block.  */
00654       max_gdbinfo++;
00655       found_ecoff_debugging_info = 1;
00656       top_stack->numargs++;
00657 
00658       /* Special GNU C++ name.  */
00659       if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0)
00660         name = "this";          /* FIXME, not alloc'd in obstack.  */
00661       s = new_symbol (name);
00662 
00663       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
00664       SYMBOL_IS_ARGUMENT (s) = 1;
00665       switch (sh->sc)
00666         {
00667         case scRegister:
00668           /* Pass by value in register.  */
00669           SYMBOL_ACLASS_INDEX (s) = mdebug_register_index;
00670           break;
00671         case scVar:
00672           /* Pass by reference on stack.  */
00673           SYMBOL_ACLASS_INDEX (s) = LOC_REF_ARG;
00674           break;
00675         case scVarRegister:
00676           /* Pass by reference in register.  */
00677           SYMBOL_ACLASS_INDEX (s) = mdebug_regparm_index;
00678           break;
00679         default:
00680           /* Pass by value on stack.  */
00681           SYMBOL_ACLASS_INDEX (s) = LOC_ARG;
00682           break;
00683         }
00684       SYMBOL_VALUE (s) = svalue;
00685       SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
00686       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
00687       break;
00688 
00689     case stLabel:               /* label, goes into current block.  */
00690       s = new_symbol (name);
00691       SYMBOL_DOMAIN (s) = VAR_DOMAIN;   /* So that it can be used */
00692       SYMBOL_ACLASS_INDEX (s) = LOC_LABEL;      /* but not misused.  */
00693       SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
00694       SYMBOL_TYPE (s) = objfile_type (objfile)->builtin_int;
00695       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
00696       break;
00697 
00698     case stProc:        /* Procedure, usually goes into global block.  */
00699     case stStaticProc:  /* Static procedure, goes into current block.  */
00700       /* For stProc symbol records, we need to check the storage class
00701          as well, as only (stProc, scText) entries represent "real"
00702          procedures - See the Compaq document titled "Object File /
00703          Symbol Table Format Specification" for more information.
00704          If the storage class is not scText, we discard the whole block
00705          of symbol records for this stProc.  */
00706       if (sh->st == stProc && sh->sc != scText)
00707         {
00708           char *ext_tsym = ext_sh;
00709           int keep_counting = 1;
00710           SYMR tsym;
00711 
00712           while (keep_counting)
00713             {
00714               ext_tsym += external_sym_size;
00715               (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
00716               count++;
00717               switch (tsym.st)
00718                 {
00719                   case stParam:
00720                     break;
00721                   case stEnd:
00722                     keep_counting = 0;
00723                     break;
00724                   default:
00725                     complaint (&symfile_complaints,
00726                                _("unknown symbol type 0x%x"), sh->st);
00727                     break;
00728                 }
00729             }
00730           break;
00731         }
00732       s = new_symbol (name);
00733       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
00734       SYMBOL_ACLASS_INDEX (s) = LOC_BLOCK;
00735       /* Type of the return value.  */
00736       if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
00737         t = objfile_type (objfile)->builtin_int;
00738       else
00739         {
00740           t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
00741           if (strcmp (name, "malloc") == 0
00742               && TYPE_CODE (t) == TYPE_CODE_VOID)
00743             {
00744               /* I don't know why, but, at least under Alpha GNU/Linux,
00745                  when linking against a malloc without debugging
00746                  symbols, its read as a function returning void---this
00747                  is bad because it means we cannot call functions with
00748                  string arguments interactively; i.e., "call
00749                  printf("howdy\n")" would fail with the error message
00750                  "program has no memory available".  To avoid this, we
00751                  patch up the type and make it void*
00752                  instead. (davidm@azstarnet.com).  */
00753               t = make_pointer_type (t, NULL);
00754             }
00755         }
00756       b = top_stack->cur_block;
00757       if (sh->st == stProc)
00758         {
00759           struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
00760 
00761           /* The next test should normally be true, but provides a
00762              hook for nested functions (which we don't want to make
00763              global).  */
00764           if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
00765             b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
00766           /* Irix 5 sometimes has duplicate names for the same
00767              function.  We want to add such names up at the global
00768              level, not as a nested function.  */
00769           else if (sh->value == top_stack->procadr)
00770             b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
00771         }
00772       add_symbol (s, top_stack->cur_st, b);
00773 
00774       /* Make a type for the procedure itself.  */
00775       SYMBOL_TYPE (s) = lookup_function_type (t);
00776 
00777       /* All functions in C++ have prototypes.  For C we don't have enough
00778          information in the debug info.  */
00779       if (SYMBOL_LANGUAGE (s) == language_cplus)
00780         TYPE_PROTOTYPED (SYMBOL_TYPE (s)) = 1;
00781 
00782       /* Create and enter a new lexical context.  */
00783       b = new_block (FUNCTION_BLOCK);
00784       SYMBOL_BLOCK_VALUE (s) = b;
00785       BLOCK_FUNCTION (b) = s;
00786       BLOCK_START (b) = BLOCK_END (b) = sh->value;
00787       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
00788       add_block (b, top_stack->cur_st);
00789 
00790       /* Not if we only have partial info.  */
00791       if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
00792         break;
00793 
00794       push_parse_stack ();
00795       top_stack->cur_block = b;
00796       top_stack->blocktype = sh->st;
00797       top_stack->cur_type = SYMBOL_TYPE (s);
00798       top_stack->cur_field = -1;
00799       top_stack->procadr = sh->value;
00800       top_stack->numargs = 0;
00801       break;
00802 
00803       /* Beginning of code for structure, union, and enum definitions.
00804          They all share a common set of local variables, defined here.  */
00805       {
00806         enum type_code type_code;
00807         char *ext_tsym;
00808         int nfields;
00809         long max_value;
00810         struct field *f;
00811 
00812     case stStruct:              /* Start a block defining a struct type.  */
00813         type_code = TYPE_CODE_STRUCT;
00814         goto structured_common;
00815 
00816     case stUnion:               /* Start a block defining a union type.  */
00817         type_code = TYPE_CODE_UNION;
00818         goto structured_common;
00819 
00820     case stEnum:                /* Start a block defining an enum type.  */
00821         type_code = TYPE_CODE_ENUM;
00822         goto structured_common;
00823 
00824     case stBlock:               /* Either a lexical block, or some type.  */
00825         if (sh->sc != scInfo && !SC_IS_COMMON (sh->sc))
00826           goto case_stBlock_code;       /* Lexical block */
00827 
00828         type_code = TYPE_CODE_UNDEF;    /* We have a type.  */
00829 
00830         /* Common code for handling struct, union, enum, and/or as-yet-
00831            unknown-type blocks of info about structured data.  `type_code'
00832            has been set to the proper TYPE_CODE, if we know it.  */
00833       structured_common:
00834         found_ecoff_debugging_info = 1;
00835         push_parse_stack ();
00836         top_stack->blocktype = stBlock;
00837 
00838         /* First count the number of fields and the highest value.  */
00839         nfields = 0;
00840         max_value = 0;
00841         for (ext_tsym = ext_sh + external_sym_size;
00842              ;
00843              ext_tsym += external_sym_size)
00844           {
00845             SYMR tsym;
00846 
00847             (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
00848 
00849             switch (tsym.st)
00850               {
00851               case stEnd:
00852                 /* C++ encodes class types as structures where there the
00853                    methods are encoded as stProc.  The scope of stProc
00854                    symbols also ends with stEnd, thus creating a risk of
00855                    taking the wrong stEnd symbol record as the end of
00856                    the current struct, which would cause GDB to undercount
00857                    the real number of fields in this struct.  To make sure
00858                    we really reached the right stEnd symbol record, we
00859                    check the associated name, and match it against the
00860                    struct name.  Since method names are mangled while
00861                    the class name is not, there is no risk of having a
00862                    method whose name is identical to the class name
00863                    (in particular constructor method names are different
00864                    from the class name).  There is therefore no risk that
00865                    this check stops the count on the StEnd of a method.
00866                    
00867                    Also, assume that we're really at the end when tsym.iss
00868                    is 0 (issNull).  */
00869                 if (tsym.iss == issNull
00870                     || strcmp (debug_info->ss + cur_fdr->issBase + tsym.iss,
00871                                name) == 0)
00872                   goto end_of_fields;
00873                 break;
00874 
00875               case stMember:
00876                 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
00877                   {
00878                     /* If the type of the member is Nil (or Void),
00879                        without qualifiers, assume the tag is an
00880                        enumeration.
00881                        Alpha cc -migrate enums are recognized by a zero
00882                        index and a zero symbol value.
00883                        DU 4.0 cc enums are recognized by a member type of
00884                        btEnum without qualifiers and a zero symbol value.  */
00885                     if (tsym.index == indexNil
00886                         || (tsym.index == 0 && sh->value == 0))
00887                       type_code = TYPE_CODE_ENUM;
00888                     else
00889                       {
00890                         (*debug_swap->swap_tir_in) (bigend,
00891                                                     &ax[tsym.index].a_ti,
00892                                                     &tir);
00893                         if ((tir.bt == btNil || tir.bt == btVoid
00894                              || (tir.bt == btEnum && sh->value == 0))
00895                             && tir.tq0 == tqNil)
00896                           type_code = TYPE_CODE_ENUM;
00897                       }
00898                   }
00899                 nfields++;
00900                 if (tsym.value > max_value)
00901                   max_value = tsym.value;
00902                 break;
00903 
00904               case stBlock:
00905               case stUnion:
00906               case stEnum:
00907               case stStruct:
00908                 {
00909 #if 0
00910                   /* This is a no-op; is it trying to tell us something
00911                      we should be checking?  */
00912                   if (tsym.sc == scVariant);    /*UNIMPLEMENTED */
00913 #endif
00914                   if (tsym.index != 0)
00915                     {
00916                       /* This is something like a struct within a
00917                          struct.  Skip over the fields of the inner
00918                          struct.  The -1 is because the for loop will
00919                          increment ext_tsym.  */
00920                       ext_tsym = ((char *) debug_info->external_sym
00921                                   + ((cur_fdr->isymBase + tsym.index - 1)
00922                                      * external_sym_size));
00923                     }
00924                 }
00925                 break;
00926 
00927               case stTypedef:
00928                 /* mips cc puts out a typedef for struct x if it is not yet
00929                    defined when it encounters
00930                    struct y { struct x *xp; };
00931                    Just ignore it.  */
00932                 break;
00933 
00934               case stIndirect:
00935                 /* Irix5 cc puts out a stIndirect for struct x if it is not
00936                    yet defined when it encounters
00937                    struct y { struct x *xp; };
00938                    Just ignore it.  */
00939                 break;
00940 
00941               default:
00942                 complaint (&symfile_complaints,
00943                            _("declaration block contains "
00944                              "unhandled symbol type %d"),
00945                            tsym.st);
00946               }
00947           }
00948       end_of_fields:
00949 
00950         /* In an stBlock, there is no way to distinguish structs,
00951            unions, and enums at this point.  This is a bug in the
00952            original design (that has been fixed with the recent
00953            addition of the stStruct, stUnion, and stEnum symbol
00954            types.)  The way you can tell is if/when you see a variable
00955            or field of that type.  In that case the variable's type
00956            (in the AUX table) says if the type is struct, union, or
00957            enum, and points back to the stBlock here.  So you can
00958            patch the tag kind up later - but only if there actually is
00959            a variable or field of that type.
00960 
00961            So until we know for sure, we will guess at this point.
00962            The heuristic is:
00963            If the first member has index==indexNil or a void type,
00964            assume we have an enumeration.
00965            Otherwise, if there is more than one member, and all
00966            the members have offset 0, assume we have a union.
00967            Otherwise, assume we have a struct.
00968 
00969            The heuristic could guess wrong in the case of of an
00970            enumeration with no members or a union with one (or zero)
00971            members, or when all except the last field of a struct have
00972            width zero.  These are uncommon and/or illegal situations,
00973            and in any case guessing wrong probably doesn't matter
00974            much.
00975 
00976            But if we later do find out we were wrong, we fixup the tag
00977            kind.  Members of an enumeration must be handled
00978            differently from struct/union fields, and that is harder to
00979            patch up, but luckily we shouldn't need to.  (If there are
00980            any enumeration members, we can tell for sure it's an enum
00981            here.)  */
00982 
00983         if (type_code == TYPE_CODE_UNDEF)
00984           {
00985             if (nfields > 1 && max_value == 0)
00986               type_code = TYPE_CODE_UNION;
00987             else
00988               type_code = TYPE_CODE_STRUCT;
00989           }
00990 
00991         /* Create a new type or use the pending type.  */
00992         pend = is_pending_symbol (cur_fdr, ext_sh);
00993         if (pend == (struct mdebug_pending *) NULL)
00994           {
00995             t = new_type (NULL);
00996             add_pending (cur_fdr, ext_sh, t);
00997           }
00998         else
00999           t = pend->t;
01000 
01001         /* Do not set the tag name if it is a compiler generated tag name
01002            (.Fxx or .xxfake or empty) for unnamed struct/union/enums.
01003            Alpha cc puts out an sh->iss of zero for those.  */
01004         if (sh->iss == 0 || name[0] == '.' || name[0] == '\0')
01005           TYPE_TAG_NAME (t) = NULL;
01006         else
01007           TYPE_TAG_NAME (t) = obconcat (&mdebugread_objfile->objfile_obstack,
01008                                         name, (char *) NULL);
01009 
01010         TYPE_CODE (t) = type_code;
01011         TYPE_LENGTH (t) = sh->value;
01012         TYPE_NFIELDS (t) = nfields;
01013         TYPE_FIELDS (t) = f = ((struct field *)
01014                                TYPE_ALLOC (t,
01015                                            nfields * sizeof (struct field)));
01016 
01017         if (type_code == TYPE_CODE_ENUM)
01018           {
01019             int unsigned_enum = 1;
01020 
01021             /* This is a non-empty enum.  */
01022 
01023             /* DEC c89 has the number of enumerators in the sh.value field,
01024                not the type length, so we have to compensate for that
01025                incompatibility quirk.
01026                This might do the wrong thing for an enum with one or two
01027                enumerators and gcc -gcoff -fshort-enums, but these cases
01028                are hopefully rare enough.
01029                Alpha cc -migrate has a sh.value field of zero, we adjust
01030                that too.  */
01031             if (TYPE_LENGTH (t) == TYPE_NFIELDS (t)
01032                 || TYPE_LENGTH (t) == 0)
01033               TYPE_LENGTH (t) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
01034             for (ext_tsym = ext_sh + external_sym_size;
01035                  ;
01036                  ext_tsym += external_sym_size)
01037               {
01038                 SYMR tsym;
01039                 struct symbol *enum_sym;
01040 
01041                 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
01042 
01043                 if (tsym.st != stMember)
01044                   break;
01045 
01046                 SET_FIELD_ENUMVAL (*f, tsym.value);
01047                 FIELD_TYPE (*f) = t;
01048                 FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss;
01049                 FIELD_BITSIZE (*f) = 0;
01050 
01051                 enum_sym = allocate_symbol (mdebugread_objfile);
01052                 SYMBOL_SET_LINKAGE_NAME
01053                   (enum_sym,
01054                    obstack_copy0 (&mdebugread_objfile->objfile_obstack,
01055                                   f->name, strlen (f->name)));
01056                 SYMBOL_ACLASS_INDEX (enum_sym) = LOC_CONST;
01057                 SYMBOL_TYPE (enum_sym) = t;
01058                 SYMBOL_DOMAIN (enum_sym) = VAR_DOMAIN;
01059                 SYMBOL_VALUE (enum_sym) = tsym.value;
01060                 if (SYMBOL_VALUE (enum_sym) < 0)
01061                   unsigned_enum = 0;
01062                 add_symbol (enum_sym, top_stack->cur_st, top_stack->cur_block);
01063 
01064                 /* Skip the stMembers that we've handled.  */
01065                 count++;
01066                 f++;
01067               }
01068             if (unsigned_enum)
01069               TYPE_UNSIGNED (t) = 1;
01070           }
01071         /* Make this the current type.  */
01072         top_stack->cur_type = t;
01073         top_stack->cur_field = 0;
01074 
01075         /* Do not create a symbol for alpha cc unnamed structs.  */
01076         if (sh->iss == 0)
01077           break;
01078 
01079         /* gcc puts out an empty struct for an opaque struct definitions,
01080            do not create a symbol for it either.  */
01081         if (TYPE_NFIELDS (t) == 0)
01082           {
01083             TYPE_STUB (t) = 1;
01084             break;
01085           }
01086 
01087         s = new_symbol (name);
01088         SYMBOL_DOMAIN (s) = STRUCT_DOMAIN;
01089         SYMBOL_ACLASS_INDEX (s) = LOC_TYPEDEF;
01090         SYMBOL_VALUE (s) = 0;
01091         SYMBOL_TYPE (s) = t;
01092         add_symbol (s, top_stack->cur_st, top_stack->cur_block);
01093         break;
01094 
01095         /* End of local variables shared by struct, union, enum, and
01096            block (as yet unknown struct/union/enum) processing.  */
01097       }
01098 
01099     case_stBlock_code:
01100       found_ecoff_debugging_info = 1;
01101       /* Beginnning of (code) block.  Value of symbol
01102          is the displacement from procedure start.  */
01103       push_parse_stack ();
01104 
01105       /* Do not start a new block if this is the outermost block of a
01106          procedure.  This allows the LOC_BLOCK symbol to point to the
01107          block with the local variables, so funcname::var works.  */
01108       if (top_stack->blocktype == stProc
01109           || top_stack->blocktype == stStaticProc)
01110         {
01111           top_stack->blocktype = stNil;
01112           break;
01113         }
01114 
01115       top_stack->blocktype = stBlock;
01116       b = new_block (NON_FUNCTION_BLOCK);
01117       BLOCK_START (b) = sh->value + top_stack->procadr;
01118       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
01119       top_stack->cur_block = b;
01120       add_block (b, top_stack->cur_st);
01121       break;
01122 
01123     case stEnd:         /* end (of anything) */
01124       if (sh->sc == scInfo || SC_IS_COMMON (sh->sc))
01125         {
01126           /* Finished with type */
01127           top_stack->cur_type = 0;
01128         }
01129       else if (sh->sc == scText &&
01130                (top_stack->blocktype == stProc ||
01131                 top_stack->blocktype == stStaticProc))
01132         {
01133           /* Finished with procedure */
01134           struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
01135           struct mdebug_extra_func_info *e;
01136           struct block *b = top_stack->cur_block;
01137           struct type *ftype = top_stack->cur_type;
01138           int i;
01139 
01140           BLOCK_END (top_stack->cur_block) += sh->value;        /* size */
01141 
01142           /* Make up special symbol to contain procedure specific info.  */
01143           s = new_symbol (MDEBUG_EFI_SYMBOL_NAME);
01144           SYMBOL_DOMAIN (s) = LABEL_DOMAIN;
01145           SYMBOL_ACLASS_INDEX (s) = LOC_CONST;
01146           SYMBOL_TYPE (s) = objfile_type (mdebugread_objfile)->builtin_void;
01147           e = ((struct mdebug_extra_func_info *)
01148                obstack_alloc (&mdebugread_objfile->objfile_obstack,
01149                               sizeof (struct mdebug_extra_func_info)));
01150           memset (e, 0, sizeof (struct mdebug_extra_func_info));
01151           SYMBOL_VALUE_BYTES (s) = (gdb_byte *) e;
01152           e->numargs = top_stack->numargs;
01153           e->pdr.framereg = -1;
01154           add_symbol (s, top_stack->cur_st, top_stack->cur_block);
01155 
01156           /* f77 emits proc-level with address bounds==[0,0],
01157              So look for such child blocks, and patch them.  */
01158           for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
01159             {
01160               struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
01161 
01162               if (BLOCK_SUPERBLOCK (b_bad) == b
01163                   && BLOCK_START (b_bad) == top_stack->procadr
01164                   && BLOCK_END (b_bad) == top_stack->procadr)
01165                 {
01166                   BLOCK_START (b_bad) = BLOCK_START (b);
01167                   BLOCK_END (b_bad) = BLOCK_END (b);
01168                 }
01169             }
01170 
01171           if (TYPE_NFIELDS (ftype) <= 0)
01172             {
01173               /* No parameter type information is recorded with the function's
01174                  type.  Set that from the type of the parameter symbols.  */
01175               int nparams = top_stack->numargs;
01176               int iparams;
01177               struct symbol *sym;
01178 
01179               if (nparams > 0)
01180                 {
01181                   struct block_iterator iter;
01182 
01183                   TYPE_NFIELDS (ftype) = nparams;
01184                   TYPE_FIELDS (ftype) = (struct field *)
01185                     TYPE_ALLOC (ftype, nparams * sizeof (struct field));
01186 
01187                   iparams = 0;
01188                   ALL_BLOCK_SYMBOLS (b, iter, sym)
01189                     {
01190                       if (iparams == nparams)
01191                         break;
01192 
01193                       if (SYMBOL_IS_ARGUMENT (sym))
01194                         {
01195                           TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
01196                           TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
01197                           iparams++;
01198                         }
01199                     }
01200                 }
01201             }
01202         }
01203       else if (sh->sc == scText && top_stack->blocktype == stBlock)
01204         {
01205           /* End of (code) block.  The value of the symbol is the
01206              displacement from the procedure`s start address of the
01207              end of this block.  */
01208           BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
01209         }
01210       else if (sh->sc == scText && top_stack->blocktype == stNil)
01211         {
01212           /* End of outermost block.  Pop parse stack and ignore.  The
01213              following stEnd of stProc will take care of the block.  */
01214           ;
01215         }
01216       else if (sh->sc == scText && top_stack->blocktype == stFile)
01217         {
01218           /* End of file.  Pop parse stack and ignore.  Higher
01219              level code deals with this.  */
01220           ;
01221         }
01222       else
01223         complaint (&symfile_complaints,
01224                    _("stEnd with storage class %d not handled"), sh->sc);
01225 
01226       pop_parse_stack ();       /* Restore previous lexical context.  */
01227       break;
01228 
01229     case stMember:              /* member of struct or union */
01230       f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++];
01231       FIELD_NAME (*f) = name;
01232       SET_FIELD_BITPOS (*f, sh->value);
01233       bitsize = 0;
01234       FIELD_TYPE (*f) = parse_type (cur_fd, ax, sh->index,
01235                                     &bitsize, bigend, name);
01236       FIELD_BITSIZE (*f) = bitsize;
01237       break;
01238 
01239     case stIndirect:            /* forward declaration on Irix5 */
01240       /* Forward declarations from Irix5 cc are handled by cross_ref,
01241          skip them.  */
01242       break;
01243 
01244     case stTypedef:             /* type definition */
01245       found_ecoff_debugging_info = 1;
01246 
01247       /* Typedefs for forward declarations and opaque structs from alpha cc
01248          are handled by cross_ref, skip them.  */
01249       if (sh->iss == 0)
01250         break;
01251 
01252       /* Parse the type or use the pending type.  */
01253       pend = is_pending_symbol (cur_fdr, ext_sh);
01254       if (pend == (struct mdebug_pending *) NULL)
01255         {
01256           t = parse_type (cur_fd, ax, sh->index, (int *) NULL, bigend, name);
01257           add_pending (cur_fdr, ext_sh, t);
01258         }
01259       else
01260         t = pend->t;
01261 
01262       /* Mips cc puts out a typedef with the name of the struct for forward
01263          declarations.  These should not go into the symbol table and
01264          TYPE_NAME should not be set for them.
01265          They can't be distinguished from an intentional typedef to
01266          the same name however:
01267          x.h:
01268          struct x { int ix; int jx; };
01269          struct xx;
01270          x.c:
01271          typedef struct x x;
01272          struct xx {int ixx; int jxx; };
01273          generates a cross referencing stTypedef for x and xx.
01274          The user visible effect of this is that the type of a pointer
01275          to struct foo sometimes is given as `foo *' instead of `struct foo *'.
01276          The problem is fixed with alpha cc and Irix5 cc.  */
01277 
01278       /* However if the typedef cross references to an opaque aggregate, it
01279          is safe to omit it from the symbol table.  */
01280 
01281       if (has_opaque_xref (cur_fdr, sh))
01282         break;
01283       s = new_symbol (name);
01284       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
01285       SYMBOL_ACLASS_INDEX (s) = LOC_TYPEDEF;
01286       SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
01287       SYMBOL_TYPE (s) = t;
01288       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
01289 
01290       /* Incomplete definitions of structs should not get a name.  */
01291       if (TYPE_NAME (SYMBOL_TYPE (s)) == NULL
01292           && (TYPE_NFIELDS (SYMBOL_TYPE (s)) != 0
01293               || (TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_STRUCT
01294                   && TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_UNION)))
01295         {
01296           if (TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_PTR
01297               || TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_FUNC)
01298             {
01299               /* If we are giving a name to a type such as "pointer to
01300                  foo" or "function returning foo", we better not set
01301                  the TYPE_NAME.  If the program contains "typedef char
01302                  *caddr_t;", we don't want all variables of type char
01303                  * to print as caddr_t.  This is not just a
01304                  consequence of GDB's type management; CC and GCC (at
01305                  least through version 2.4) both output variables of
01306                  either type char * or caddr_t with the type
01307                  refering to the stTypedef symbol for caddr_t.  If a future
01308                  compiler cleans this up it GDB is not ready for it
01309                  yet, but if it becomes ready we somehow need to
01310                  disable this check (without breaking the PCC/GCC2.4
01311                  case).
01312 
01313                  Sigh.
01314 
01315                  Fortunately, this check seems not to be necessary
01316                  for anything except pointers or functions.  */
01317             }
01318           else
01319             TYPE_NAME (SYMBOL_TYPE (s)) = SYMBOL_LINKAGE_NAME (s);
01320         }
01321       break;
01322 
01323     case stFile:                /* file name */
01324       push_parse_stack ();
01325       top_stack->blocktype = sh->st;
01326       break;
01327 
01328       /* I`ve never seen these for C */
01329     case stRegReloc:
01330       break;                    /* register relocation */
01331     case stForward:
01332       break;                    /* forwarding address */
01333     case stConstant:
01334       break;                    /* constant */
01335     default:
01336       complaint (&symfile_complaints, _("unknown symbol type 0x%x"), sh->st);
01337       break;
01338     }
01339 
01340   return count;
01341 }
01342 
01343 /* Basic types.  */
01344 
01345 static const struct objfile_data *basic_type_data;
01346 
01347 static struct type *
01348 basic_type (int bt, struct objfile *objfile)
01349 {
01350   struct gdbarch *gdbarch = get_objfile_arch (objfile);
01351   struct type **map_bt = objfile_data (objfile, basic_type_data);
01352   struct type *tp;
01353 
01354   if (bt >= btMax)
01355     return NULL;
01356 
01357   if (!map_bt)
01358     {
01359       map_bt = OBSTACK_CALLOC (&objfile->objfile_obstack,
01360                                btMax, struct type *);
01361       set_objfile_data (objfile, basic_type_data, map_bt);
01362     }
01363 
01364   if (map_bt[bt])
01365     return map_bt[bt];
01366 
01367   switch (bt)
01368     {
01369     case btNil:
01370       tp = objfile_type (objfile)->builtin_void;
01371       break;
01372 
01373     case btAdr:
01374       tp = init_type (TYPE_CODE_PTR, 4, TYPE_FLAG_UNSIGNED,
01375                       "adr_32", objfile);
01376       TYPE_TARGET_TYPE (tp) = objfile_type (objfile)->builtin_void;
01377       break;
01378 
01379     case btChar:
01380       tp = init_type (TYPE_CODE_INT, 1, 0,
01381                       "char", objfile);
01382       break;
01383 
01384     case btUChar:
01385       tp = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
01386                       "unsigned char", objfile);
01387       break;
01388 
01389     case btShort:
01390       tp = init_type (TYPE_CODE_INT, 2, 0,
01391                       "short", objfile);
01392       break;
01393 
01394     case btUShort:
01395       tp = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
01396                       "unsigned short", objfile);
01397       break;
01398 
01399     case btInt:
01400       tp = init_type (TYPE_CODE_INT, 4, 0,
01401                       "int", objfile);
01402       break;
01403 
01404    case btUInt:
01405       tp = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
01406                       "unsigned int", objfile);
01407       break;
01408 
01409     case btLong:
01410       tp = init_type (TYPE_CODE_INT, 4, 0,
01411                       "long", objfile);
01412       break;
01413 
01414     case btULong:
01415       tp = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
01416                       "unsigned long", objfile);
01417       break;
01418 
01419     case btFloat:
01420       tp = init_type (TYPE_CODE_FLT,
01421                       gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT, 0,
01422                       "float", objfile);
01423       break;
01424 
01425     case btDouble:
01426       tp = init_type (TYPE_CODE_FLT,
01427                       gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, 0,
01428                       "double", objfile);
01429       break;
01430 
01431     case btComplex:
01432       tp = init_type (TYPE_CODE_COMPLEX,
01433                       2 * gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT, 0,
01434                       "complex", objfile);
01435       TYPE_TARGET_TYPE (tp) = basic_type (btFloat, objfile);
01436       break;
01437 
01438     case btDComplex:
01439       tp = init_type (TYPE_CODE_COMPLEX,
01440                       2 * gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, 0,
01441                       "double complex", objfile);
01442       TYPE_TARGET_TYPE (tp) = basic_type (btDouble, objfile);
01443       break;
01444 
01445     case btFixedDec:
01446       /* We use TYPE_CODE_INT to print these as integers.  Does this do any
01447          good?  Would we be better off with TYPE_CODE_ERROR?  Should
01448          TYPE_CODE_ERROR print things in hex if it knows the size?  */
01449       tp = init_type (TYPE_CODE_INT,
01450                       gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT, 0,
01451                       "fixed decimal", objfile);
01452       break;
01453 
01454     case btFloatDec:
01455       tp = init_type (TYPE_CODE_ERROR,
01456                       gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, 0,
01457                       "floating decimal", objfile);
01458       break;
01459 
01460     case btString:
01461       /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
01462          FIXME.  */
01463       tp = init_type (TYPE_CODE_STRING, 1, 0,
01464                       "string", objfile);
01465       break;
01466 
01467     case btVoid:
01468       tp = objfile_type (objfile)->builtin_void;
01469       break;
01470 
01471     case btLong64:
01472       tp = init_type (TYPE_CODE_INT, 8, 0,
01473                       "long", objfile);
01474       break;
01475 
01476     case btULong64:
01477       tp = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
01478                       "unsigned long", objfile);
01479       break;
01480 
01481     case btLongLong64:
01482       tp = init_type (TYPE_CODE_INT, 8, 0,
01483                       "long long", objfile);
01484       break;
01485 
01486     case btULongLong64:
01487       tp = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
01488                       "unsigned long long", objfile);
01489       break;
01490 
01491     case btAdr64:
01492       tp = init_type (TYPE_CODE_PTR, 8, TYPE_FLAG_UNSIGNED,
01493                       "adr_64", objfile);
01494       TYPE_TARGET_TYPE (tp) = objfile_type (objfile)->builtin_void;
01495       break;
01496 
01497     case btInt64:
01498       tp = init_type (TYPE_CODE_INT, 8, 0,
01499                       "int", objfile);
01500       break;
01501 
01502     case btUInt64:
01503       tp = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
01504                       "unsigned int", objfile);
01505       break;
01506 
01507     default:
01508       tp = NULL;
01509       break;
01510     }
01511 
01512   map_bt[bt] = tp;
01513   return tp;
01514 }
01515 
01516 /* Parse the type information provided in the raw AX entries for
01517    the symbol SH.  Return the bitfield size in BS, in case.
01518    We must byte-swap the AX entries before we use them; BIGEND says whether
01519    they are big-endian or little-endian (from fh->fBigendian).  */
01520 
01521 static struct type *
01522 parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
01523             int bigend, char *sym_name)
01524 {
01525   TIR t[1];
01526   struct type *tp = 0;
01527   enum type_code type_code = TYPE_CODE_UNDEF;
01528 
01529   /* Handle undefined types, they have indexNil.  */
01530   if (aux_index == indexNil)
01531     return basic_type (btInt, mdebugread_objfile);
01532 
01533   /* Handle corrupt aux indices.  */
01534   if (aux_index >= (debug_info->fdr + fd)->caux)
01535     {
01536       index_complaint (sym_name);
01537       return basic_type (btInt, mdebugread_objfile);
01538     }
01539   ax += aux_index;
01540 
01541   /* Use aux as a type information record, map its basic type.  */
01542   (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
01543   tp = basic_type (t->bt, mdebugread_objfile);
01544   if (tp == NULL)
01545     {
01546       /* Cannot use builtin types -- build our own.  */
01547       switch (t->bt)
01548         {
01549         case btStruct:
01550           type_code = TYPE_CODE_STRUCT;
01551           break;
01552         case btUnion:
01553           type_code = TYPE_CODE_UNION;
01554           break;
01555         case btEnum:
01556           type_code = TYPE_CODE_ENUM;
01557           break;
01558         case btRange:
01559           type_code = TYPE_CODE_RANGE;
01560           break;
01561         case btSet:
01562           type_code = TYPE_CODE_SET;
01563           break;
01564         case btIndirect:
01565           /* alpha cc -migrate uses this for typedefs.  The true type will
01566              be obtained by crossreferencing below.  */
01567           type_code = TYPE_CODE_ERROR;
01568           break;
01569         case btTypedef:
01570           /* alpha cc uses this for typedefs.  The true type will be
01571              obtained by crossreferencing below.  */
01572           type_code = TYPE_CODE_ERROR;
01573           break;
01574         default:
01575           basic_type_complaint (t->bt, sym_name);
01576           return basic_type (btInt, mdebugread_objfile);
01577         }
01578     }
01579 
01580   /* Move on to next aux.  */
01581   ax++;
01582 
01583   if (t->fBitfield)
01584     {
01585       int width = AUX_GET_WIDTH (bigend, ax);
01586 
01587       /* Inhibit core dumps if TIR is corrupted.  */
01588       if (bs == (int *) NULL)
01589         {
01590           /* Alpha cc -migrate encodes char and unsigned char types
01591              as short and unsigned short types with a field width of 8.
01592              Enum types also have a field width which we ignore for now.  */
01593           if (t->bt == btShort && width == 8)
01594             tp = basic_type (btChar, mdebugread_objfile);
01595           else if (t->bt == btUShort && width == 8)
01596             tp = basic_type (btUChar, mdebugread_objfile);
01597           else if (t->bt == btEnum)
01598             ;
01599           else
01600             complaint (&symfile_complaints,
01601                        _("can't handle TIR fBitfield for %s"),
01602                        sym_name);
01603         }
01604       else
01605         *bs = width;
01606       ax++;
01607     }
01608 
01609   /* A btIndirect entry cross references to an aux entry containing
01610      the type.  */
01611   if (t->bt == btIndirect)
01612     {
01613       RNDXR rn[1];
01614       int rf;
01615       FDR *xref_fh;
01616       int xref_fd;
01617 
01618       (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
01619       ax++;
01620       if (rn->rfd == 0xfff)
01621         {
01622           rf = AUX_GET_ISYM (bigend, ax);
01623           ax++;
01624         }
01625       else
01626         rf = rn->rfd;
01627 
01628       if (rf == -1)
01629         {
01630           complaint (&symfile_complaints,
01631                      _("unable to cross ref btIndirect for %s"), sym_name);
01632           return basic_type (btInt, mdebugread_objfile);
01633         }
01634       xref_fh = get_rfd (fd, rf);
01635       xref_fd = xref_fh - debug_info->fdr;
01636       tp = parse_type (xref_fd, debug_info->external_aux + xref_fh->iauxBase,
01637                     rn->index, (int *) NULL, xref_fh->fBigendian, sym_name);
01638     }
01639 
01640   /* All these types really point to some (common) MIPS type
01641      definition, and only the type-qualifiers fully identify
01642      them.  We'll make the same effort at sharing.  */
01643   if (t->bt == btStruct ||
01644       t->bt == btUnion ||
01645       t->bt == btEnum ||
01646 
01647   /* btSet (I think) implies that the name is a tag name, not a typedef
01648      name.  This apparently is a MIPS extension for C sets.  */
01649       t->bt == btSet)
01650     {
01651       char *name;
01652 
01653       /* Try to cross reference this type, build new type on failure.  */
01654       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
01655       if (tp == (struct type *) NULL)
01656         tp = init_type (type_code, 0, 0, (char *) NULL, mdebugread_objfile);
01657 
01658       /* DEC c89 produces cross references to qualified aggregate types,
01659          dereference them.  */
01660       while (TYPE_CODE (tp) == TYPE_CODE_PTR
01661              || TYPE_CODE (tp) == TYPE_CODE_ARRAY)
01662         tp = TYPE_TARGET_TYPE (tp);
01663 
01664       /* Make sure that TYPE_CODE(tp) has an expected type code.
01665          Any type may be returned from cross_ref if file indirect entries
01666          are corrupted.  */
01667       if (TYPE_CODE (tp) != TYPE_CODE_STRUCT
01668           && TYPE_CODE (tp) != TYPE_CODE_UNION
01669           && TYPE_CODE (tp) != TYPE_CODE_ENUM)
01670         {
01671           unexpected_type_code_complaint (sym_name);
01672         }
01673       else
01674         {
01675           /* Usually, TYPE_CODE(tp) is already type_code.  The main
01676              exception is if we guessed wrong re struct/union/enum.
01677              But for struct vs. union a wrong guess is harmless, so
01678              don't complain().  */
01679           if ((TYPE_CODE (tp) == TYPE_CODE_ENUM
01680                && type_code != TYPE_CODE_ENUM)
01681               || (TYPE_CODE (tp) != TYPE_CODE_ENUM
01682                   && type_code == TYPE_CODE_ENUM))
01683             {
01684               bad_tag_guess_complaint (sym_name);
01685             }
01686 
01687           if (TYPE_CODE (tp) != type_code)
01688             {
01689               TYPE_CODE (tp) = type_code;
01690             }
01691 
01692           /* Do not set the tag name if it is a compiler generated tag name
01693              (.Fxx or .xxfake or empty) for unnamed struct/union/enums.  */
01694           if (name[0] == '.' || name[0] == '\0')
01695             TYPE_TAG_NAME (tp) = NULL;
01696           else if (TYPE_TAG_NAME (tp) == NULL
01697                    || strcmp (TYPE_TAG_NAME (tp), name) != 0)
01698             TYPE_TAG_NAME (tp)
01699               = obstack_copy0 (&mdebugread_objfile->objfile_obstack,
01700                                name, strlen (name));
01701         }
01702     }
01703 
01704   /* All these types really point to some (common) MIPS type
01705      definition, and only the type-qualifiers fully identify
01706      them.  We'll make the same effort at sharing.
01707      FIXME: We are not doing any guessing on range types.  */
01708   if (t->bt == btRange)
01709     {
01710       char *name;
01711 
01712       /* Try to cross reference this type, build new type on failure.  */
01713       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
01714       if (tp == (struct type *) NULL)
01715         tp = init_type (type_code, 0, 0, (char *) NULL, mdebugread_objfile);
01716 
01717       /* Make sure that TYPE_CODE(tp) has an expected type code.
01718          Any type may be returned from cross_ref if file indirect entries
01719          are corrupted.  */
01720       if (TYPE_CODE (tp) != TYPE_CODE_RANGE)
01721         {
01722           unexpected_type_code_complaint (sym_name);
01723         }
01724       else
01725         {
01726           /* Usually, TYPE_CODE(tp) is already type_code.  The main
01727              exception is if we guessed wrong re struct/union/enum.  */
01728           if (TYPE_CODE (tp) != type_code)
01729             {
01730               bad_tag_guess_complaint (sym_name);
01731               TYPE_CODE (tp) = type_code;
01732             }
01733           if (TYPE_NAME (tp) == NULL
01734               || strcmp (TYPE_NAME (tp), name) != 0)
01735             TYPE_NAME (tp)
01736               = obstack_copy0 (&mdebugread_objfile->objfile_obstack,
01737                                name, strlen (name));
01738         }
01739     }
01740   if (t->bt == btTypedef)
01741     {
01742       char *name;
01743 
01744       /* Try to cross reference this type, it should succeed.  */
01745       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
01746       if (tp == (struct type *) NULL)
01747         {
01748           complaint (&symfile_complaints,
01749                      _("unable to cross ref btTypedef for %s"), sym_name);
01750           tp = basic_type (btInt, mdebugread_objfile);
01751         }
01752     }
01753 
01754   /* Deal with range types.  */
01755   if (t->bt == btRange)
01756     {
01757       TYPE_NFIELDS (tp) = 0;
01758       TYPE_RANGE_DATA (tp) = ((struct range_bounds *)
01759                           TYPE_ZALLOC (tp, sizeof (struct range_bounds)));
01760       TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
01761       ax++;
01762       TYPE_HIGH_BOUND (tp) = AUX_GET_DNHIGH (bigend, ax);
01763       ax++;
01764     }
01765 
01766   /* Parse all the type qualifiers now.  If there are more
01767      than 6 the game will continue in the next aux.  */
01768 
01769   while (1)
01770     {
01771 #define PARSE_TQ(tq) \
01772       if (t->tq != tqNil) \
01773         ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
01774       else \
01775         break;
01776 
01777       PARSE_TQ (tq0);
01778       PARSE_TQ (tq1);
01779       PARSE_TQ (tq2);
01780       PARSE_TQ (tq3);
01781       PARSE_TQ (tq4);
01782       PARSE_TQ (tq5);
01783 #undef  PARSE_TQ
01784 
01785       /* mips cc 2.x and gcc never put out continued aux entries.  */
01786       if (!t->continued)
01787         break;
01788 
01789       (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
01790       ax++;
01791     }
01792 
01793   /* Complain for illegal continuations due to corrupt aux entries.  */
01794   if (t->continued)
01795     complaint (&symfile_complaints,
01796                _("illegal TIR continued for %s"), sym_name);
01797 
01798   return tp;
01799 }
01800 
01801 /* Make up a complex type from a basic one.  Type is passed by
01802    reference in TPP and side-effected as necessary.  The type
01803    qualifier TQ says how to handle the aux symbols at AX for
01804    the symbol SX we are currently analyzing.  BIGEND says whether
01805    aux symbols are big-endian or little-endian.
01806    Returns the number of aux symbols we parsed.  */
01807 
01808 static int
01809 upgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend,
01810               char *sym_name)
01811 {
01812   int off;
01813   struct type *t;
01814 
01815   /* Used in array processing.  */
01816   int rf, id;
01817   FDR *fh;
01818   struct type *range;
01819   struct type *indx;
01820   int lower, upper;
01821   RNDXR rndx;
01822 
01823   switch (tq)
01824     {
01825     case tqPtr:
01826       t = lookup_pointer_type (*tpp);
01827       *tpp = t;
01828       return 0;
01829 
01830     case tqProc:
01831       t = lookup_function_type (*tpp);
01832       *tpp = t;
01833       return 0;
01834 
01835     case tqArray:
01836       off = 0;
01837 
01838       /* Determine and record the domain type (type of index).  */
01839       (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, &rndx);
01840       id = rndx.index;
01841       rf = rndx.rfd;
01842       if (rf == 0xfff)
01843         {
01844           ax++;
01845           rf = AUX_GET_ISYM (bigend, ax);
01846           off++;
01847         }
01848       fh = get_rfd (fd, rf);
01849 
01850       indx = parse_type (fh - debug_info->fdr,
01851                          debug_info->external_aux + fh->iauxBase,
01852                          id, (int *) NULL, bigend, sym_name);
01853 
01854       /* The bounds type should be an integer type, but might be anything
01855          else due to corrupt aux entries.  */
01856       if (TYPE_CODE (indx) != TYPE_CODE_INT)
01857         {
01858           complaint (&symfile_complaints,
01859                      _("illegal array index type for %s, assuming int"),
01860                      sym_name);
01861           indx = objfile_type (mdebugread_objfile)->builtin_int;
01862         }
01863 
01864       /* Get the bounds, and create the array type.  */
01865       ax++;
01866       lower = AUX_GET_DNLOW (bigend, ax);
01867       ax++;
01868       upper = AUX_GET_DNHIGH (bigend, ax);
01869       ax++;
01870       rf = AUX_GET_WIDTH (bigend, ax);  /* bit size of array element */
01871 
01872       range = create_range_type ((struct type *) NULL, indx,
01873                                  lower, upper);
01874 
01875       t = create_array_type ((struct type *) NULL, *tpp, range);
01876 
01877       /* We used to fill in the supplied array element bitsize
01878          here if the TYPE_LENGTH of the target type was zero.
01879          This happens for a `pointer to an array of anonymous structs',
01880          but in this case the array element bitsize is also zero,
01881          so nothing is gained.
01882          And we used to check the TYPE_LENGTH of the target type against
01883          the supplied array element bitsize.
01884          gcc causes a mismatch for `pointer to array of object',
01885          since the sdb directives it uses do not have a way of
01886          specifying the bitsize, but it does no harm (the
01887          TYPE_LENGTH should be correct) and we should be able to
01888          ignore the erroneous bitsize from the auxiliary entry safely.
01889          dbx seems to ignore it too.  */
01890 
01891       /* TYPE_TARGET_STUB now takes care of the zero TYPE_LENGTH problem.  */
01892       if (TYPE_LENGTH (*tpp) == 0)
01893         TYPE_TARGET_STUB (t) = 1;
01894 
01895       *tpp = t;
01896       return 4 + off;
01897 
01898     case tqVol:
01899       /* Volatile -- currently ignored */
01900       return 0;
01901 
01902     case tqConst:
01903       /* Const -- currently ignored */
01904       return 0;
01905 
01906     default:
01907       complaint (&symfile_complaints, _("unknown type qualifier 0x%x"), tq);
01908       return 0;
01909     }
01910 }
01911 
01912 
01913 /* Parse a procedure descriptor record PR.  Note that the procedure is
01914    parsed _after_ the local symbols, now we just insert the extra
01915    information we need into a MDEBUG_EFI_SYMBOL_NAME symbol that has
01916    already been placed in the procedure's main block.  Note also that
01917    images that have been partially stripped (ld -x) have been deprived
01918    of local symbols, and we have to cope with them here.  FIRST_OFF is
01919    the offset of the first procedure for this FDR; we adjust the
01920    address by this amount, but I don't know why.  SEARCH_SYMTAB is the symtab
01921    to look for the function which contains the MDEBUG_EFI_SYMBOL_NAME symbol
01922    in question, or NULL to use top_stack->cur_block.  */
01923 
01924 static void parse_procedure (PDR *, struct symtab *, struct partial_symtab *);
01925 
01926 static void
01927 parse_procedure (PDR *pr, struct symtab *search_symtab,
01928                  struct partial_symtab *pst)
01929 {
01930   struct symbol *s, *i;
01931   struct block *b;
01932   char *sh_name;
01933 
01934   /* Simple rule to find files linked "-x".  */
01935   if (cur_fdr->rss == -1)
01936     {
01937       if (pr->isym == -1)
01938         {
01939           /* Static procedure at address pr->adr.  Sigh.  */
01940           /* FIXME-32x64.  assuming pr->adr fits in long.  */
01941           complaint (&symfile_complaints,
01942                      _("can't handle PDR for static proc at 0x%lx"),
01943                      (unsigned long) pr->adr);
01944           return;
01945         }
01946       else
01947         {
01948           /* external */
01949           EXTR she;
01950 
01951           (*debug_swap->swap_ext_in) (cur_bfd,
01952                                       ((char *) debug_info->external_ext
01953                                        + (pr->isym
01954                                           * debug_swap->external_ext_size)),
01955                                       &she);
01956           sh_name = debug_info->ssext + she.asym.iss;
01957         }
01958     }
01959   else
01960     {
01961       /* Full symbols */
01962       SYMR sh;
01963 
01964       (*debug_swap->swap_sym_in) (cur_bfd,
01965                                   ((char *) debug_info->external_sym
01966                                    + ((cur_fdr->isymBase + pr->isym)
01967                                       * debug_swap->external_sym_size)),
01968                                   &sh);
01969       sh_name = debug_info->ss + cur_fdr->issBase + sh.iss;
01970     }
01971 
01972   if (search_symtab != NULL)
01973     {
01974 #if 0
01975       /* This loses both in the case mentioned (want a static, find a global),
01976          but also if we are looking up a non-mangled name which happens to
01977          match the name of a mangled function.  */
01978       /* We have to save the cur_fdr across the call to lookup_symbol.
01979          If the pdr is for a static function and if a global function with
01980          the same name exists, lookup_symbol will eventually read in the symtab
01981          for the global function and clobber cur_fdr.  */
01982       FDR *save_cur_fdr = cur_fdr;
01983 
01984       s = lookup_symbol (sh_name, NULL, VAR_DOMAIN, 0);
01985       cur_fdr = save_cur_fdr;
01986 #else
01987       s = mylookup_symbol
01988         (sh_name,
01989          BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab), STATIC_BLOCK),
01990          VAR_DOMAIN,
01991          LOC_BLOCK);
01992 #endif
01993     }
01994   else
01995     s = mylookup_symbol (sh_name, top_stack->cur_block,
01996                          VAR_DOMAIN, LOC_BLOCK);
01997 
01998   if (s != 0)
01999     {
02000       b = SYMBOL_BLOCK_VALUE (s);
02001     }
02002   else
02003     {
02004       complaint (&symfile_complaints, _("PDR for %s, but no symbol"), sh_name);
02005 #if 1
02006       return;
02007 #else
02008 /* FIXME -- delete.  We can't do symbol allocation now; it's all done.  */
02009       s = new_symbol (sh_name);
02010       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
02011       SYMBOL_CLASS (s) = LOC_BLOCK;
02012       /* Donno its type, hope int is ok.  */
02013       SYMBOL_TYPE (s)
02014         = lookup_function_type (objfile_type (pst->objfile)->builtin_int);
02015       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
02016       /* Won't have symbols for this one.  */
02017       b = new_block (2);
02018       SYMBOL_BLOCK_VALUE (s) = b;
02019       BLOCK_FUNCTION (b) = s;
02020       BLOCK_START (b) = pr->adr;
02021       /* BOUND used to be the end of procedure's text, but the
02022          argument is no longer passed in.  */
02023       BLOCK_END (b) = bound;
02024       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
02025       add_block (b, top_stack->cur_st);
02026 #endif
02027     }
02028 
02029   i = mylookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, LOC_CONST);
02030 
02031   if (i)
02032     {
02033       struct mdebug_extra_func_info *e;
02034       
02035       e = (struct mdebug_extra_func_info *) SYMBOL_VALUE_BYTES (i);
02036       e->pdr = *pr;
02037 
02038       /* GDB expects the absolute function start address for the
02039          procedure descriptor in e->pdr.adr.
02040          As the address in the procedure descriptor is usually relative,
02041          we would have to relocate e->pdr.adr with cur_fdr->adr and
02042          ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile)).
02043          Unfortunately cur_fdr->adr and e->pdr.adr are both absolute
02044          in shared libraries on some systems, and on other systems
02045          e->pdr.adr is sometimes offset by a bogus value.
02046          To work around these problems, we replace e->pdr.adr with
02047          the start address of the function.  */
02048       e->pdr.adr = BLOCK_START (b);
02049     }
02050 
02051   /* It would be reasonable that functions that have been compiled
02052      without debugging info have a btNil type for their return value,
02053      and functions that are void and are compiled with debugging info
02054      have btVoid.
02055      gcc and DEC f77 put out btNil types for both cases, so btNil is mapped
02056      to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info'
02057      case right.
02058      The glevel field in cur_fdr could be used to determine the presence
02059      of debugging info, but GCC doesn't always pass the -g switch settings
02060      to the assembler and GAS doesn't set the glevel field from the -g switch
02061      settings.
02062      To work around these problems, the return value type of a TYPE_CODE_VOID
02063      function is adjusted accordingly if no debugging info was found in the
02064      compilation unit.  */
02065 
02066   if (processing_gcc_compilation == 0
02067       && found_ecoff_debugging_info == 0
02068       && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (s))) == TYPE_CODE_VOID)
02069     SYMBOL_TYPE (s) = objfile_type (mdebugread_objfile)->nodebug_text_symbol;
02070 }
02071 
02072 /* Parse the external symbol ES.  Just call parse_symbol() after
02073    making sure we know where the aux are for it.
02074    BIGEND says whether aux entries are big-endian or little-endian.
02075 
02076    This routine clobbers top_stack->cur_block and ->cur_st.  */
02077 
02078 static void parse_external (EXTR *, int, struct section_offsets *,
02079                             struct objfile *);
02080 
02081 static void
02082 parse_external (EXTR *es, int bigend, struct section_offsets *section_offsets,
02083                 struct objfile *objfile)
02084 {
02085   union aux_ext *ax;
02086 
02087   if (es->ifd != ifdNil)
02088     {
02089       cur_fd = es->ifd;
02090       cur_fdr = debug_info->fdr + cur_fd;
02091       ax = debug_info->external_aux + cur_fdr->iauxBase;
02092     }
02093   else
02094     {
02095       cur_fdr = debug_info->fdr;
02096       ax = 0;
02097     }
02098 
02099   /* Reading .o files */
02100   if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil)
02101     {
02102       char *what;
02103       switch (es->asym.st)
02104         {
02105         case stNil:
02106           /* These are generated for static symbols in .o files,
02107              ignore them.  */
02108           return;
02109         case stStaticProc:
02110         case stProc:
02111           what = "procedure";
02112           n_undef_procs++;
02113           break;
02114         case stGlobal:
02115           what = "variable";
02116           n_undef_vars++;
02117           break;
02118         case stLabel:
02119           what = "label";
02120           n_undef_labels++;
02121           break;
02122         default:
02123           what = "symbol";
02124           break;
02125         }
02126       n_undef_symbols++;
02127       /* FIXME:  Turn this into a complaint?  */
02128       if (info_verbose)
02129         printf_filtered (_("Warning: %s `%s' is undefined (in %s)\n"),
02130                          what, debug_info->ssext + es->asym.iss,
02131                          fdr_name (cur_fdr));
02132       return;
02133     }
02134 
02135   switch (es->asym.st)
02136     {
02137     case stProc:
02138     case stStaticProc:
02139       /* There is no need to parse the external procedure symbols.
02140          If they are from objects compiled without -g, their index will
02141          be indexNil, and the symbol definition from the minimal symbol
02142          is preferrable (yielding a function returning int instead of int).
02143          If the index points to a local procedure symbol, the local
02144          symbol already provides the correct type.
02145          Note that the index of the external procedure symbol points
02146          to the local procedure symbol in the local symbol table, and
02147          _not_ to the auxiliary symbol info.  */
02148       break;
02149     case stGlobal:
02150     case stLabel:
02151       /* Global common symbols are resolved by the runtime loader,
02152          ignore them.  */
02153       if (SC_IS_COMMON (es->asym.sc))
02154         break;
02155 
02156       /* Note that the case of a symbol with indexNil must be handled
02157          anyways by parse_symbol().  */
02158       parse_symbol (&es->asym, ax, (char *) NULL,
02159                     bigend, section_offsets, objfile);
02160       break;
02161     default:
02162       break;
02163     }
02164 }
02165 
02166 /* Parse the line number info for file descriptor FH into
02167    GDB's linetable LT.  MIPS' encoding requires a little bit
02168    of magic to get things out.  Note also that MIPS' line
02169    numbers can go back and forth, apparently we can live
02170    with that and do not need to reorder our linetables.  */
02171 
02172 static void parse_lines (FDR *, PDR *, struct linetable *, int,
02173                          struct partial_symtab *, CORE_ADDR);
02174 
02175 static void
02176 parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
02177              struct partial_symtab *pst, CORE_ADDR lowest_pdr_addr)
02178 {
02179   unsigned char *base;
02180   int j, k;
02181   int delta, count, lineno = 0;
02182 
02183   if (fh->cbLine == 0)
02184     return;
02185 
02186   /* Scan by procedure descriptors.  */
02187   k = 0;
02188   for (j = 0; j < fh->cpd; j++, pr++)
02189     {
02190       CORE_ADDR l;
02191       CORE_ADDR adr;
02192       unsigned char *halt;
02193 
02194       /* No code for this one.  */
02195       if (pr->iline == ilineNil ||
02196           pr->lnLow == -1 || pr->lnHigh == -1)
02197         continue;
02198 
02199       /* Determine start and end address of compressed line bytes for
02200          this procedure.  */
02201       base = debug_info->line + fh->cbLineOffset;
02202       if (j != (fh->cpd - 1))
02203         halt = base + pr[1].cbLineOffset;
02204       else
02205         halt = base + fh->cbLine;
02206       base += pr->cbLineOffset;
02207 
02208       adr = pst->textlow + pr->adr - lowest_pdr_addr;
02209 
02210       l = adr >> 2;             /* in words */
02211       for (lineno = pr->lnLow; base < halt;)
02212         {
02213           count = *base & 0x0f;
02214           delta = *base++ >> 4;
02215           if (delta >= 8)
02216             delta -= 16;
02217           if (delta == -8)
02218             {
02219               delta = (base[0] << 8) | base[1];
02220               if (delta >= 0x8000)
02221                 delta -= 0x10000;
02222               base += 2;
02223             }
02224           lineno += delta;      /* first delta is 0 */
02225 
02226           /* Complain if the line table overflows.  Could happen
02227              with corrupt binaries.  */
02228           if (lt->nitems >= maxlines)
02229             {
02230               complaint (&symfile_complaints,
02231                          _("guessed size of linetable for %s incorrectly"),
02232                          fdr_name (fh));
02233               break;
02234             }
02235           k = add_line (lt, lineno, l, k);
02236           l += count + 1;
02237         }
02238     }
02239 }
02240 
02241 static void
02242 function_outside_compilation_unit_complaint (const char *arg1)
02243 {
02244   complaint (&symfile_complaints,
02245              _("function `%s' appears to be defined "
02246                "outside of all compilation units"),
02247              arg1);
02248 }
02249 
02250 /* Use the STORAGE_CLASS to compute which section the given symbol
02251    belongs to, and then records this new minimal symbol.  */
02252 
02253 static void
02254 record_minimal_symbol (const char *name, const CORE_ADDR address,
02255                        enum minimal_symbol_type ms_type, int storage_class,
02256                        struct objfile *objfile)
02257 {
02258   int section;
02259 
02260   switch (storage_class)
02261     {
02262       case scText:
02263         section = SECT_OFF_TEXT (objfile);
02264         break;
02265       case scData:
02266         section = SECT_OFF_DATA (objfile);
02267         break;
02268       case scBss:
02269         section = SECT_OFF_BSS (objfile);
02270         break;
02271       case scSData:
02272         section = get_section_index (objfile, ".sdata");
02273         break;
02274       case scSBss:
02275         section = get_section_index (objfile, ".sbss");
02276         break;
02277       case scRData:
02278         section = get_section_index (objfile, ".rdata");
02279         break;
02280       case scInit:
02281         section = get_section_index (objfile, ".init");
02282         break;
02283       case scXData:
02284         section = get_section_index (objfile, ".xdata");
02285         break;
02286       case scPData:
02287         section = get_section_index (objfile, ".pdata");
02288         break;
02289       case scFini:
02290         section = get_section_index (objfile, ".fini");
02291         break;
02292       case scRConst:
02293         section = get_section_index (objfile, ".rconst");
02294         break;
02295 #ifdef scTlsData
02296       case scTlsData:
02297         section = get_section_index (objfile, ".tlsdata");
02298         break;
02299 #endif
02300 #ifdef scTlsBss
02301       case scTlsBss:
02302         section = get_section_index (objfile, ".tlsbss");
02303         break;
02304 #endif
02305       default:
02306         /* This kind of symbol is not associated to a section.  */
02307         section = -1;
02308     }
02309 
02310   prim_record_minimal_symbol_and_info (name, address, ms_type,
02311                                        section, objfile);
02312 }
02313 
02314 /* Master parsing procedure for first-pass reading of file symbols
02315    into a partial_symtab.  */
02316 
02317 static void
02318 parse_partial_symbols (struct objfile *objfile)
02319 {
02320   struct gdbarch *gdbarch = get_objfile_arch (objfile);
02321   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
02322   const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
02323   const bfd_size_type external_ext_size = debug_swap->external_ext_size;
02324   void (*const swap_ext_in) (bfd *, void *, EXTR *) = debug_swap->swap_ext_in;
02325   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
02326   void (*const swap_rfd_in) (bfd *, void *, RFDT *) = debug_swap->swap_rfd_in;
02327   int f_idx, s_idx;
02328   HDRR *hdr = &debug_info->symbolic_header;
02329   /* Running pointers */
02330   FDR *fh;
02331   char *ext_out;
02332   char *ext_out_end;
02333   EXTR *ext_block;
02334   EXTR *ext_in;
02335   EXTR *ext_in_end;
02336   SYMR sh;
02337   struct partial_symtab *pst;
02338   int textlow_not_set = 1;
02339   int past_first_source_file = 0;
02340 
02341   /* List of current psymtab's include files.  */
02342   const char **psymtab_include_list;
02343   int includes_allocated;
02344   int includes_used;
02345   EXTR *extern_tab;
02346   struct pst_map *fdr_to_pst;
02347   /* Index within current psymtab dependency list.  */
02348   struct partial_symtab **dependency_list;
02349   int dependencies_used, dependencies_allocated;
02350   struct cleanup *old_chain;
02351   char *name;
02352   enum language prev_language;
02353   asection *text_sect;
02354   int relocatable = 0;
02355 
02356   /* Irix 5.2 shared libraries have a fh->adr field of zero, but
02357      the shared libraries are prelinked at a high memory address.
02358      We have to adjust the start address of the object file for this case,
02359      by setting it to the start address of the first procedure in the file.
02360      But we should do no adjustments if we are debugging a .o file, where
02361      the text section (and fh->adr) really starts at zero.  */
02362   text_sect = bfd_get_section_by_name (cur_bfd, ".text");
02363   if (text_sect != NULL
02364       && (bfd_get_section_flags (cur_bfd, text_sect) & SEC_RELOC))
02365     relocatable = 1;
02366 
02367   extern_tab = (EXTR *) obstack_alloc (&objfile->objfile_obstack,
02368                                        sizeof (EXTR) * hdr->iextMax);
02369 
02370   includes_allocated = 30;
02371   includes_used = 0;
02372   psymtab_include_list = (const char **) alloca (includes_allocated *
02373                                                  sizeof (const char *));
02374   next_symbol_text_func = mdebug_next_symbol_text;
02375 
02376   dependencies_allocated = 30;
02377   dependencies_used = 0;
02378   dependency_list =
02379     (struct partial_symtab **) alloca (dependencies_allocated *
02380                                        sizeof (struct partial_symtab *));
02381 
02382   set_last_source_file (NULL);
02383 
02384   /*
02385    * Big plan:
02386    *
02387    * Only parse the Local and External symbols, and the Relative FDR.
02388    * Fixup enough of the loader symtab to be able to use it.
02389    * Allocate space only for the file's portions we need to
02390    * look at.  (XXX)
02391    */
02392 
02393   max_gdbinfo = 0;
02394   max_glevel = MIN_GLEVEL;
02395 
02396   /* Allocate the map FDR -> PST.
02397      Minor hack: -O3 images might claim some global data belongs
02398      to FDR -1.  We`ll go along with that.  */
02399   fdr_to_pst = (struct pst_map *)
02400     xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst);
02401   old_chain = make_cleanup (xfree, fdr_to_pst);
02402   fdr_to_pst++;
02403   {
02404     struct partial_symtab *pst = new_psymtab ("", objfile);
02405 
02406     fdr_to_pst[-1].pst = pst;
02407     FDR_IDX (pst) = -1;
02408   }
02409 
02410   /* Allocate the global pending list.  */
02411   pending_list =
02412     ((struct mdebug_pending **)
02413      obstack_alloc (&objfile->objfile_obstack,
02414                     hdr->ifdMax * sizeof (struct mdebug_pending *)));
02415   memset (pending_list, 0,
02416           hdr->ifdMax * sizeof (struct mdebug_pending *));
02417 
02418   /* Pass 0 over external syms: swap them in.  */
02419   ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR));
02420   make_cleanup (xfree, ext_block);
02421 
02422   ext_out = (char *) debug_info->external_ext;
02423   ext_out_end = ext_out + hdr->iextMax * external_ext_size;
02424   ext_in = ext_block;
02425   for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++)
02426     (*swap_ext_in) (cur_bfd, ext_out, ext_in);
02427 
02428   /* Pass 1 over external syms: Presize and partition the list.  */
02429   ext_in = ext_block;
02430   ext_in_end = ext_in + hdr->iextMax;
02431   for (; ext_in < ext_in_end; ext_in++)
02432     {
02433       /* See calls to complain below.  */
02434       if (ext_in->ifd >= -1
02435           && ext_in->ifd < hdr->ifdMax
02436           && ext_in->asym.iss >= 0
02437           && ext_in->asym.iss < hdr->issExtMax)
02438         fdr_to_pst[ext_in->ifd].n_globals++;
02439     }
02440 
02441   /* Pass 1.5 over files:  partition out global symbol space.  */
02442   s_idx = 0;
02443   for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
02444     {
02445       fdr_to_pst[f_idx].globals_offset = s_idx;
02446       s_idx += fdr_to_pst[f_idx].n_globals;
02447       fdr_to_pst[f_idx].n_globals = 0;
02448     }
02449 
02450   /* ECOFF in ELF:
02451 
02452      For ECOFF in ELF, we skip the creation of the minimal symbols.
02453      The ECOFF symbols should be a subset of the Elf symbols, and the 
02454      section information of the elf symbols will be more accurate.
02455      FIXME!  What about Irix 5's native linker?
02456 
02457      By default, Elf sections which don't exist in ECOFF 
02458      get put in ECOFF's absolute section by the gnu linker.
02459      Since absolute sections don't get relocated, we 
02460      end up calculating an address different from that of 
02461      the symbol's minimal symbol (created earlier from the
02462      Elf symtab).
02463 
02464      To fix this, either :
02465      1) don't create the duplicate symbol
02466      (assumes ECOFF symtab is a subset of the ELF symtab;
02467      assumes no side-effects result from ignoring ECOFF symbol)
02468      2) create it, only if lookup for existing symbol in ELF's minimal 
02469      symbols fails
02470      (inefficient; 
02471      assumes no side-effects result from ignoring ECOFF symbol)
02472      3) create it, but lookup ELF's minimal symbol and use it's section
02473      during relocation, then modify "uniqify" phase to merge and 
02474      eliminate the duplicate symbol
02475      (highly inefficient)
02476 
02477      I've implemented #1 here...
02478      Skip the creation of the minimal symbols based on the ECOFF 
02479      symbol table.  */
02480 
02481   /* Pass 2 over external syms: fill in external symbols.  */
02482   ext_in = ext_block;
02483   ext_in_end = ext_in + hdr->iextMax;
02484   for (; ext_in < ext_in_end; ext_in++)
02485     {
02486       enum minimal_symbol_type ms_type = mst_text;
02487       CORE_ADDR svalue = ext_in->asym.value;
02488 
02489       /* The Irix 5 native tools seem to sometimes generate bogus
02490          external symbols.  */
02491       if (ext_in->ifd < -1 || ext_in->ifd >= hdr->ifdMax)
02492         {
02493           complaint (&symfile_complaints,
02494                      _("bad ifd for external symbol: %d (max %ld)"),
02495                      ext_in->ifd, hdr->ifdMax);
02496           continue;
02497         }
02498       if (ext_in->asym.iss < 0 || ext_in->asym.iss >= hdr->issExtMax)
02499         {
02500           complaint (&symfile_complaints,
02501                      _("bad iss for external symbol: %ld (max %ld)"),
02502                      ext_in->asym.iss, hdr->issExtMax);
02503           continue;
02504         }
02505 
02506       extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
02507                  + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
02508 
02509 
02510       if (SC_IS_UNDEF (ext_in->asym.sc) || ext_in->asym.sc == scNil)
02511         continue;
02512 
02513 
02514       /* Pass 3 over files, over local syms: fill in static symbols.  */
02515       name = debug_info->ssext + ext_in->asym.iss;
02516 
02517       /* Process ECOFF Symbol Types and Storage Classes.  */
02518       switch (ext_in->asym.st)
02519         {
02520         case stProc:
02521           /* Beginnning of Procedure */
02522           svalue += ANOFFSET (objfile->section_offsets,
02523                               SECT_OFF_TEXT (objfile));
02524           break;
02525         case stStaticProc:
02526           /* Load time only static procs */
02527           ms_type = mst_file_text;
02528           svalue += ANOFFSET (objfile->section_offsets,
02529                               SECT_OFF_TEXT (objfile));
02530           break;
02531         case stGlobal:
02532           /* External symbol */
02533           if (SC_IS_COMMON (ext_in->asym.sc))
02534             {
02535               /* The value of a common symbol is its size, not its address.
02536                  Ignore it.  */
02537               continue;
02538             }
02539           else if (SC_IS_DATA (ext_in->asym.sc))
02540             {
02541               ms_type = mst_data;
02542               svalue += ANOFFSET (objfile->section_offsets,
02543                                   SECT_OFF_DATA (objfile));
02544             }
02545           else if (SC_IS_BSS (ext_in->asym.sc))
02546             {
02547               ms_type = mst_bss;
02548               svalue += ANOFFSET (objfile->section_offsets,
02549                                   SECT_OFF_BSS (objfile));
02550             }
02551           else if (SC_IS_SBSS (ext_in->asym.sc))
02552             {
02553               ms_type = mst_bss;
02554               svalue += ANOFFSET (objfile->section_offsets, 
02555                                   get_section_index (objfile, ".sbss"));
02556             }
02557           else
02558             ms_type = mst_abs;
02559           break;
02560         case stLabel:
02561           /* Label */
02562 
02563           /* On certain platforms, some extra label symbols can be
02564              generated by the linker.  One possible usage for this kind
02565              of symbols is to represent the address of the begining of a
02566              given section.  For instance, on Tru64 5.1, the address of
02567              the _ftext label is the start address of the .text section.
02568 
02569              The storage class of these symbols is usually directly
02570              related to the section to which the symbol refers.  For
02571              instance, on Tru64 5.1, the storage class for the _fdata
02572              label is scData, refering to the .data section.
02573 
02574              It is actually possible that the section associated to the
02575              storage class of the label does not exist.  On True64 5.1
02576              for instance, the libm.so shared library does not contain
02577              any .data section, although it contains a _fpdata label
02578              which storage class is scData...  Since these symbols are
02579              usually useless for the debugger user anyway, we just
02580              discard these symbols.  */
02581           
02582           if (SC_IS_TEXT (ext_in->asym.sc))
02583             {
02584               if (objfile->sect_index_text == -1)
02585                 continue;
02586                 
02587               ms_type = mst_file_text;
02588               svalue += ANOFFSET (objfile->section_offsets,
02589                                   SECT_OFF_TEXT (objfile));
02590             }
02591           else if (SC_IS_DATA (ext_in->asym.sc))
02592             {
02593               if (objfile->sect_index_data == -1)
02594                 continue;
02595 
02596               ms_type = mst_file_data;
02597               svalue += ANOFFSET (objfile->section_offsets,
02598                                   SECT_OFF_DATA (objfile));
02599             }
02600           else if (SC_IS_BSS (ext_in->asym.sc))
02601             {
02602               if (objfile->sect_index_bss == -1)
02603                 continue;
02604 
02605               ms_type = mst_file_bss;
02606               svalue += ANOFFSET (objfile->section_offsets,
02607                                   SECT_OFF_BSS (objfile));
02608             }
02609           else if (SC_IS_SBSS (ext_in->asym.sc))
02610             {
02611               const int sbss_sect_index = get_section_index (objfile, ".sbss");
02612 
02613               if (sbss_sect_index == -1)
02614                 continue;
02615 
02616               ms_type = mst_file_bss;
02617               svalue += ANOFFSET (objfile->section_offsets, sbss_sect_index);
02618             }
02619           else
02620             ms_type = mst_abs;
02621           break;
02622         case stLocal:
02623         case stNil:
02624           /* The alpha has the section start addresses in stLocal symbols
02625              whose name starts with a `.'.  Skip those but complain for all
02626              other stLocal symbols.
02627              Irix6 puts the section start addresses in stNil symbols, skip
02628              those too.  */
02629           if (name[0] == '.')
02630             continue;
02631           /* Fall through.  */
02632         default:
02633           ms_type = mst_unknown;
02634           unknown_ext_complaint (name);
02635         }
02636       if (!ECOFF_IN_ELF (cur_bfd))
02637         record_minimal_symbol (name, svalue, ms_type, ext_in->asym.sc,
02638                                objfile);
02639     }
02640 
02641   /* Pass 3 over files, over local syms: fill in static symbols.  */
02642   for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
02643     {
02644       struct partial_symtab *save_pst;
02645       EXTR *ext_ptr;
02646       CORE_ADDR textlow;
02647 
02648       cur_fdr = fh = debug_info->fdr + f_idx;
02649 
02650       if (fh->csym == 0)
02651         {
02652           fdr_to_pst[f_idx].pst = NULL;
02653           continue;
02654         }
02655 
02656       /* Determine the start address for this object file from the
02657          file header and relocate it, except for Irix 5.2 zero fh->adr.  */
02658       if (fh->cpd)
02659         {
02660           textlow = fh->adr;
02661           if (relocatable || textlow != 0)
02662             textlow += ANOFFSET (objfile->section_offsets,
02663                                  SECT_OFF_TEXT (objfile));
02664         }
02665       else
02666         textlow = 0;
02667       pst = start_psymtab_common (objfile, objfile->section_offsets,
02668                                   fdr_name (fh),
02669                                   textlow,
02670                                   objfile->global_psymbols.next,
02671                                   objfile->static_psymbols.next);
02672       pst->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
02673                                                 sizeof (struct symloc));
02674       memset (pst->read_symtab_private, 0, sizeof (struct symloc));
02675 
02676       save_pst = pst;
02677       FDR_IDX (pst) = f_idx;
02678       CUR_BFD (pst) = cur_bfd;
02679       DEBUG_SWAP (pst) = debug_swap;
02680       DEBUG_INFO (pst) = debug_info;
02681       PENDING_LIST (pst) = pending_list;
02682 
02683       /* The way to turn this into a symtab is to call...  */
02684       pst->read_symtab = mdebug_read_symtab;
02685 
02686       /* Set up language for the pst.
02687          The language from the FDR is used if it is unambigious (e.g. cfront
02688          with native cc and g++ will set the language to C).
02689          Otherwise we have to deduce the language from the filename.
02690          Native ecoff has every header file in a separate FDR, so
02691          deduce_language_from_filename will return language_unknown for
02692          a header file, which is not what we want.
02693          But the FDRs for the header files are after the FDR for the source
02694          file, so we can assign the language of the source file to the
02695          following header files.  Then we save the language in the private
02696          pst data so that we can reuse it when building symtabs.  */
02697       prev_language = psymtab_language;
02698 
02699       switch (fh->lang)
02700         {
02701         case langCplusplusV2:
02702           psymtab_language = language_cplus;
02703           break;
02704         default:
02705           psymtab_language = deduce_language_from_filename (fdr_name (fh));
02706           break;
02707         }
02708       if (psymtab_language == language_unknown)
02709         psymtab_language = prev_language;
02710       PST_PRIVATE (pst)->pst_language = psymtab_language;
02711 
02712       pst->texthigh = pst->textlow;
02713 
02714       /* For stabs-in-ecoff files, the second symbol must be @stab.
02715          This symbol is emitted by mips-tfile to signal that the
02716          current object file uses encapsulated stabs instead of mips
02717          ecoff for local symbols.  (It is the second symbol because
02718          the first symbol is the stFile used to signal the start of a
02719          file).  */
02720       processing_gcc_compilation = 0;
02721       if (fh->csym >= 2)
02722         {
02723           (*swap_sym_in) (cur_bfd,
02724                           ((char *) debug_info->external_sym
02725                            + (fh->isymBase + 1) * external_sym_size),
02726                           &sh);
02727           if (strcmp (debug_info->ss + fh->issBase + sh.iss,
02728                       stabs_symbol) == 0)
02729             processing_gcc_compilation = 2;
02730         }
02731 
02732       if (processing_gcc_compilation != 0)
02733         {
02734           for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
02735             {
02736               int type_code;
02737               const char *namestring;
02738 
02739               (*swap_sym_in) (cur_bfd,
02740                               (((char *) debug_info->external_sym)
02741                             + (fh->isymBase + cur_sdx) * external_sym_size),
02742                               &sh);
02743               type_code = ECOFF_UNMARK_STAB (sh.index);
02744               if (!ECOFF_IS_STAB (&sh))
02745                 {
02746                   if (sh.st == stProc || sh.st == stStaticProc)
02747                     {
02748                       CORE_ADDR procaddr;
02749                       long isym;
02750 
02751                       sh.value += ANOFFSET (objfile->section_offsets,
02752                                             SECT_OFF_TEXT (objfile));
02753                       if (sh.st == stStaticProc)
02754                         {
02755                           namestring = debug_info->ss + fh->issBase + sh.iss;
02756                           record_minimal_symbol (namestring, sh.value,
02757                                                  mst_file_text, sh.sc,
02758                                                  objfile);
02759                         }
02760                       procaddr = sh.value;
02761 
02762                       isym = AUX_GET_ISYM (fh->fBigendian,
02763                                            (debug_info->external_aux
02764                                             + fh->iauxBase
02765                                             + sh.index));
02766                       (*swap_sym_in) (cur_bfd,
02767                                       ((char *) debug_info->external_sym
02768                                        + ((fh->isymBase + isym - 1)
02769                                           * external_sym_size)),
02770                                       &sh);
02771                       if (sh.st == stEnd)
02772                         {
02773                           CORE_ADDR high = procaddr + sh.value;
02774 
02775                           /* Kludge for Irix 5.2 zero fh->adr.  */
02776                           if (!relocatable
02777                           && (pst->textlow == 0 || procaddr < pst->textlow))
02778                             pst->textlow = procaddr;
02779                           if (high > pst->texthigh)
02780                             pst->texthigh = high;
02781                         }
02782                     }
02783                   else if (sh.st == stStatic)
02784                     {
02785                       switch (sh.sc)
02786                         {
02787                         case scUndefined:
02788                         case scSUndefined:
02789                         case scNil:
02790                         case scAbs:
02791                           break;
02792 
02793                         case scData:
02794                         case scSData:
02795                         case scRData:
02796                         case scPData:
02797                         case scXData:
02798                           namestring = debug_info->ss + fh->issBase + sh.iss;
02799                           sh.value += ANOFFSET (objfile->section_offsets,
02800                                                 SECT_OFF_DATA (objfile));
02801                           record_minimal_symbol (namestring, sh.value,
02802                                                  mst_file_data, sh.sc,
02803                                                  objfile);
02804                           break;
02805 
02806                         default:
02807                           /* FIXME!  Shouldn't this use cases for bss, 
02808                              then have the default be abs?  */
02809                           namestring = debug_info->ss + fh->issBase + sh.iss;
02810                           sh.value += ANOFFSET (objfile->section_offsets,
02811                                                 SECT_OFF_BSS (objfile));
02812                           record_minimal_symbol (namestring, sh.value,
02813                                                  mst_file_bss, sh.sc,
02814                                                  objfile);
02815                           break;
02816                         }
02817                     }
02818                   continue;
02819                 }
02820               /* Handle stabs continuation.  */
02821               {
02822                 char *stabstring = debug_info->ss + fh->issBase + sh.iss;
02823                 int len = strlen (stabstring);
02824 
02825                 while (stabstring[len - 1] == '\\')
02826                   {
02827                     SYMR sh2;
02828                     char *stabstring1 = stabstring;
02829                     char *stabstring2;
02830                     int len2;
02831 
02832                     /* Ignore continuation char from 1st string.  */
02833                     len--;
02834 
02835                     /* Read next stabstring.  */
02836                     cur_sdx++;
02837                     (*swap_sym_in) (cur_bfd,
02838                                     (((char *) debug_info->external_sym)
02839                                      + (fh->isymBase + cur_sdx)
02840                                      * external_sym_size),
02841                                     &sh2);
02842                     stabstring2 = debug_info->ss + fh->issBase + sh2.iss;
02843                     len2 = strlen (stabstring2);
02844 
02845                     /* Concatinate stabstring2 with stabstring1.  */
02846                     if (stabstring
02847                      && stabstring != debug_info->ss + fh->issBase + sh.iss)
02848                       stabstring = xrealloc (stabstring, len + len2 + 1);
02849                     else
02850                       {
02851                         stabstring = xmalloc (len + len2 + 1);
02852                         strcpy (stabstring, stabstring1);
02853                       }
02854                     strcpy (stabstring + len, stabstring2);
02855                     len += len2;
02856                   }
02857 
02858                 switch (type_code)
02859                   {
02860                     char *p;
02861 
02862                     /* Standard, external, non-debugger, symbols.  */
02863 
02864                   case N_TEXT | N_EXT:
02865                   case N_NBTEXT | N_EXT:
02866                     sh.value += ANOFFSET (objfile->section_offsets,
02867                                           SECT_OFF_TEXT (objfile));
02868                     goto record_it;
02869 
02870                   case N_DATA | N_EXT:
02871                   case N_NBDATA | N_EXT:
02872                     sh.value += ANOFFSET (objfile->section_offsets,
02873                                           SECT_OFF_DATA (objfile));
02874                     goto record_it;
02875 
02876                   case N_BSS:
02877                   case N_BSS | N_EXT:
02878                   case N_NBBSS | N_EXT:
02879                   case N_SETV | N_EXT:          /* FIXME, is this in BSS?  */
02880                     sh.value += ANOFFSET (objfile->section_offsets,
02881                                           SECT_OFF_BSS (objfile));
02882                     goto record_it;
02883 
02884                   case N_ABS | N_EXT:
02885                   record_it:
02886                     continue;
02887 
02888                   /* Standard, local, non-debugger, symbols.  */
02889 
02890                   case N_NBTEXT:
02891 
02892                     /* We need to be able to deal with both N_FN or
02893                        N_TEXT, because we have no way of knowing
02894                        whether the sys-supplied ld or GNU ld was used
02895                        to make the executable.  Sequents throw in
02896                        another wrinkle -- they renumbered N_FN.  */
02897 
02898                   case N_FN:
02899                   case N_FN_SEQ:
02900                   case N_TEXT:
02901                     continue;
02902 
02903                   case N_DATA:
02904                     sh.value += ANOFFSET (objfile->section_offsets,
02905                                           SECT_OFF_DATA (objfile));
02906                     goto record_it;
02907 
02908                   case N_UNDF | N_EXT:
02909                     continue;           /* Just undefined, not COMMON.  */
02910 
02911                   case N_UNDF:
02912                     continue;
02913 
02914                     /* Lots of symbol types we can just ignore.  */
02915 
02916                   case N_ABS:
02917                   case N_NBDATA:
02918                   case N_NBBSS:
02919                     continue;
02920 
02921                     /* Keep going . . .  */
02922 
02923                     /*
02924                      * Special symbol types for GNU
02925                      */
02926                   case N_INDR:
02927                   case N_INDR | N_EXT:
02928                   case N_SETA:
02929                   case N_SETA | N_EXT:
02930                   case N_SETT:
02931                   case N_SETT | N_EXT:
02932                   case N_SETD:
02933                   case N_SETD | N_EXT:
02934                   case N_SETB:
02935                   case N_SETB | N_EXT:
02936                   case N_SETV:
02937                     continue;
02938 
02939                     /*
02940                      * Debugger symbols
02941                      */
02942 
02943                   case N_SO:
02944                     {
02945                       CORE_ADDR valu;
02946                       static int prev_so_symnum = -10;
02947                       static int first_so_symnum;
02948                       const char *p;
02949                       int prev_textlow_not_set;
02950 
02951                       valu = sh.value + ANOFFSET (objfile->section_offsets,
02952                                                   SECT_OFF_TEXT (objfile));
02953 
02954                       prev_textlow_not_set = textlow_not_set;
02955 
02956                       /* A zero value is probably an indication for the
02957                          SunPRO 3.0 compiler.  end_psymtab explicitly tests
02958                          for zero, so don't relocate it.  */
02959 
02960                       if (sh.value == 0
02961                           && gdbarch_sofun_address_maybe_missing (gdbarch))
02962                         {
02963                           textlow_not_set = 1;
02964                           valu = 0;
02965                         }
02966                       else
02967                         textlow_not_set = 0;
02968 
02969                       past_first_source_file = 1;
02970 
02971                       if (prev_so_symnum != symnum - 1)
02972                         {               /* Here if prev stab wasn't N_SO.  */
02973                           first_so_symnum = symnum;
02974 
02975                           if (pst)
02976                             {
02977                               pst = (struct partial_symtab *) 0;
02978                               includes_used = 0;
02979                               dependencies_used = 0;
02980                             }
02981                         }
02982 
02983                       prev_so_symnum = symnum;
02984 
02985                       /* End the current partial symtab and start a
02986                          new one.  */
02987 
02988                       /* SET_NAMESTRING ();*/
02989                       namestring = stabstring;
02990 
02991                       /* Null name means end of .o file.  Don't start a new
02992                          one.  */
02993                       if (*namestring == '\000')
02994                         continue;
02995 
02996                       /* Some compilers (including gcc) emit a pair of
02997                          initial N_SOs.  The first one is a directory name;
02998                          the second the file name.  If pst exists, is
02999                          empty, and has a filename ending in '/', we assume
03000                          the previous N_SO was a directory name.  */
03001                       p = lbasename (namestring);
03002                       if (p != namestring && *p == '\000')
03003                         continue;               /* Simply ignore directory
03004                                                    name SOs.  */
03005 
03006                       /* Some other compilers (C++ ones in particular) emit
03007                          useless SOs for non-existant .c files.  We ignore
03008                          all subsequent SOs that immediately follow the
03009                          first.  */
03010 
03011                       if (!pst)
03012                         pst = save_pst;
03013                       continue;
03014                     }
03015 
03016                   case N_BINCL:
03017                     continue;
03018 
03019                   case N_SOL:
03020                     {
03021                       enum language tmp_language;
03022 
03023                       /* Mark down an include file in the current psymtab.  */
03024 
03025                       /* SET_NAMESTRING (); */
03026                       namestring = stabstring;
03027 
03028                       tmp_language
03029                         = deduce_language_from_filename (namestring);
03030 
03031                       /* Only change the psymtab's language if we've
03032                          learned something useful (eg. tmp_language is not
03033                          language_unknown).  In addition, to match what
03034                          start_subfile does, never change from C++ to
03035                          C.  */
03036                       if (tmp_language != language_unknown
03037                           && (tmp_language != language_c
03038                               || psymtab_language != language_cplus))
03039                         psymtab_language = tmp_language;
03040 
03041                       /* In C++, one may expect the same filename to come
03042                          round many times, when code is coming alternately
03043                          from the main file and from inline functions in
03044                          other files.  So I check to see if this is a file
03045                          we've seen before -- either the main source file,
03046                          or a previously included file.
03047 
03048                          This seems to be a lot of time to be spending on
03049                          N_SOL, but things like "break c-exp.y:435" need to
03050                          work (I suppose the psymtab_include_list could be
03051                          hashed or put in a binary tree, if profiling shows
03052                          this is a major hog).  */
03053                       if (pst && filename_cmp (namestring, pst->filename) == 0)
03054                         continue;
03055 
03056                       {
03057                         int i;
03058 
03059                         for (i = 0; i < includes_used; i++)
03060                           if (filename_cmp (namestring,
03061                                             psymtab_include_list[i]) == 0)
03062                             {
03063                               i = -1;
03064                               break;
03065                             }
03066                         if (i == -1)
03067                           continue;
03068                       }
03069 
03070                       psymtab_include_list[includes_used++] = namestring;
03071                       if (includes_used >= includes_allocated)
03072                         {
03073                           const char **orig = psymtab_include_list;
03074 
03075                           psymtab_include_list = (const char **)
03076                             alloca ((includes_allocated *= 2) *
03077                                     sizeof (const char *));
03078                           memcpy (psymtab_include_list, orig,
03079                                   includes_used * sizeof (const char *));
03080                         }
03081                       continue;
03082                     }
03083                   case N_LSYM:      /* Typedef or automatic variable.  */
03084                   case N_STSYM:     /* Data seg var -- static  */
03085                   case N_LCSYM:     /* BSS      "  */
03086                   case N_ROSYM:     /* Read-only data seg var -- static.  */
03087                   case N_NBSTS:     /* Gould nobase.  */
03088                   case N_NBLCS:     /* symbols.  */
03089                   case N_FUN:
03090                   case N_GSYM:      /* Global (extern) variable; can be
03091                                        data or bss (sigh FIXME).  */
03092 
03093                     /* Following may probably be ignored; I'll leave them here
03094                        for now (until I do Pascal and Modula 2 extensions).  */
03095 
03096                   case N_PC:        /* I may or may not need this; I
03097                                        suspect not.  */
03098                   case N_M2C:       /* I suspect that I can ignore this
03099                                        here.  */
03100                   case N_SCOPE:     /* Same.  */
03101 
03102                     /*    SET_NAMESTRING (); */
03103                     namestring = stabstring;
03104                     p = (char *) strchr (namestring, ':');
03105                     if (!p)
03106                       continue;     /* Not a debugging symbol.  */
03107 
03108 
03109 
03110                     /* Main processing section for debugging symbols which
03111                        the initial read through the symbol tables needs to
03112                        worry about.  If we reach this point, the symbol
03113                        which we are considering is definitely one we are
03114                        interested in.  p must also contain the (valid)
03115                        index into the namestring which indicates the
03116                        debugging type symbol.  */
03117 
03118                     switch (p[1])
03119                       {
03120                       case 'S':
03121                         sh.value += ANOFFSET (objfile->section_offsets,
03122                                               SECT_OFF_DATA (objfile));
03123 
03124                         if (gdbarch_static_transform_name_p (gdbarch))
03125                           namestring = gdbarch_static_transform_name
03126                                          (gdbarch, namestring);
03127 
03128                         add_psymbol_to_list (namestring, p - namestring, 1,
03129                                              VAR_DOMAIN, LOC_STATIC,
03130                                              &objfile->static_psymbols,
03131                                              0, sh.value,
03132                                              psymtab_language, objfile);
03133                         continue;
03134                       case 'G':
03135                         sh.value += ANOFFSET (objfile->section_offsets,
03136                                               SECT_OFF_DATA (objfile));
03137                         /* The addresses in these entries are reported
03138                            to be wrong.  See the code that reads 'G's
03139                            for symtabs.  */
03140                         add_psymbol_to_list (namestring, p - namestring, 1,
03141                                              VAR_DOMAIN, LOC_STATIC,
03142                                              &objfile->global_psymbols,
03143                                              0, sh.value,
03144                                              psymtab_language, objfile);
03145                         continue;
03146 
03147                       case 'T':
03148                         /* When a 'T' entry is defining an anonymous enum, it
03149                            may have a name which is the empty string, or a
03150                            single space.  Since they're not really defining a
03151                            symbol, those shouldn't go in the partial symbol
03152                            table.  We do pick up the elements of such enums at
03153                            'check_enum:', below.  */
03154                         if (p >= namestring + 2
03155                             || (p == namestring + 1
03156                                 && namestring[0] != ' '))
03157                           {
03158                             add_psymbol_to_list (namestring, p - namestring, 1,
03159                                                  STRUCT_DOMAIN, LOC_TYPEDEF,
03160                                                  &objfile->static_psymbols,
03161                                                  sh.value, 0,
03162                                                  psymtab_language, objfile);
03163                             if (p[2] == 't')
03164                               {
03165                                 /* Also a typedef with the same name.  */
03166                                 add_psymbol_to_list (namestring,
03167                                                      p - namestring, 1,
03168                                                      VAR_DOMAIN, LOC_TYPEDEF,
03169                                                      &objfile->static_psymbols,
03170                                                      sh.value, 0,
03171                                                      psymtab_language,
03172                                                      objfile);
03173                                 p += 1;
03174                               }
03175                           }
03176                         goto check_enum;
03177                       case 't':
03178                         if (p != namestring)    /* a name is there, not
03179                                                    just :T...  */
03180                           {
03181                             add_psymbol_to_list (namestring, p - namestring, 1,
03182                                                  VAR_DOMAIN, LOC_TYPEDEF,
03183                                                  &objfile->static_psymbols,
03184                                                  sh.value, 0,
03185                                                  psymtab_language, objfile);
03186                           }
03187                       check_enum:
03188                         /* If this is an enumerated type, we need to add
03189                            all the enum constants to the partial symbol
03190                            table.  This does not cover enums without names,
03191                            e.g. "enum {a, b} c;" in C, but fortunately
03192                            those are rare.  There is no way for GDB to find
03193                            those from the enum type without spending too
03194                            much time on it.  Thus to solve this problem,
03195                            the compiler needs to put out the enum in a
03196                            nameless type.  GCC2 does this.  */
03197 
03198                         /* We are looking for something of the form
03199                            <name> ":" ("t" | "T") [<number> "="] "e"
03200                            {<constant> ":" <value> ","} ";".  */
03201 
03202                         /* Skip over the colon and the 't' or 'T'.  */
03203                         p += 2;
03204                         /* This type may be given a number.  Also, numbers
03205                            can come in pairs like (0,26).  Skip over it.  */
03206                         while ((*p >= '0' && *p <= '9')
03207                                || *p == '(' || *p == ',' || *p == ')'
03208                                || *p == '=')
03209                           p++;
03210 
03211                         if (*p++ == 'e')
03212                           {
03213                             /* The aix4 compiler emits extra crud before
03214                                the members.  */
03215                             if (*p == '-')
03216                               {
03217                                 /* Skip over the type (?).  */
03218                                 while (*p != ':')
03219                                   p++;
03220 
03221                                 /* Skip over the colon.  */
03222                                 p++;
03223                               }
03224 
03225                             /* We have found an enumerated type.  */
03226                             /* According to comments in read_enum_type
03227                                a comma could end it instead of a semicolon.
03228                                I don't know where that happens.
03229                                Accept either.  */
03230                             while (*p && *p != ';' && *p != ',')
03231                               {
03232                                 char *q;
03233 
03234                                 /* Check for and handle cretinous dbx
03235                                    symbol name continuation!  */
03236                                 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
03237                                   p = next_symbol_text (objfile);
03238 
03239                                 /* Point to the character after the name
03240                                    of the enum constant.  */
03241                                 for (q = p; *q && *q != ':'; q++)
03242                                   ;
03243                                 /* Note that the value doesn't matter for
03244                                    enum constants in psymtabs, just in
03245                                    symtabs.  */
03246                                 add_psymbol_to_list (p, q - p, 1,
03247                                                      VAR_DOMAIN, LOC_CONST,
03248                                                      &objfile->static_psymbols,
03249                                                      0, 0, psymtab_language,
03250                                                      objfile);
03251                                 /* Point past the name.  */
03252                                 p = q;
03253                                 /* Skip over the value.  */
03254                                 while (*p && *p != ',')
03255                                   p++;
03256                                 /* Advance past the comma.  */
03257                                 if (*p)
03258                                   p++;
03259                               }
03260                           }
03261                         continue;
03262                       case 'c':
03263                         /* Constant, e.g. from "const" in Pascal.  */
03264                         add_psymbol_to_list (namestring, p - namestring, 1,
03265                                              VAR_DOMAIN, LOC_CONST,
03266                                              &objfile->static_psymbols,
03267                                              sh.value, 0, psymtab_language,
03268                                              objfile);
03269                         continue;
03270 
03271                       case 'f':
03272                         if (! pst)
03273                           {
03274                             int name_len = p - namestring;
03275                             char *name = xmalloc (name_len + 1);
03276 
03277                             memcpy (name, namestring, name_len);
03278                             name[name_len] = '\0';
03279                             function_outside_compilation_unit_complaint (name);
03280                             xfree (name);
03281                           }
03282                         sh.value += ANOFFSET (objfile->section_offsets,
03283                                               SECT_OFF_TEXT (objfile));
03284                         add_psymbol_to_list (namestring, p - namestring, 1,
03285                                              VAR_DOMAIN, LOC_BLOCK,
03286                                              &objfile->static_psymbols,
03287                                              0, sh.value,
03288                                              psymtab_language, objfile);
03289                         continue;
03290 
03291                         /* Global functions were ignored here, but now they
03292                            are put into the global psymtab like one would
03293                            expect.  They're also in the minimal symbol
03294                            table.  */
03295                       case 'F':
03296                         if (! pst)
03297                           {
03298                             int name_len = p - namestring;
03299                             char *name = xmalloc (name_len + 1);
03300 
03301                             memcpy (name, namestring, name_len);
03302                             name[name_len] = '\0';
03303                             function_outside_compilation_unit_complaint (name);
03304                             xfree (name);
03305                           }
03306                         sh.value += ANOFFSET (objfile->section_offsets,
03307                                               SECT_OFF_TEXT (objfile));
03308                         add_psymbol_to_list (namestring, p - namestring, 1,
03309                                              VAR_DOMAIN, LOC_BLOCK,
03310                                              &objfile->global_psymbols,
03311                                              0, sh.value,
03312                                              psymtab_language, objfile);
03313                         continue;
03314 
03315                         /* Two things show up here (hopefully); static
03316                            symbols of local scope (static used inside
03317                            braces) or extensions of structure symbols.  We
03318                            can ignore both.  */
03319                       case 'V':
03320                       case '(':
03321                       case '0':
03322                       case '1':
03323                       case '2':
03324                       case '3':
03325                       case '4':
03326                       case '5':
03327                       case '6':
03328                       case '7':
03329                       case '8':
03330                       case '9':
03331                       case '-':
03332                       case '#':         /* For symbol identification (used
03333                                            in live ranges).  */
03334                         continue;
03335 
03336                       case ':':
03337                         /* It is a C++ nested symbol.  We don't need to
03338                            record it (I don't think); if we try to look up
03339                            foo::bar::baz, then symbols for the symtab
03340                            containing foo should get read in, I think.  */
03341                         /* Someone says sun cc puts out symbols like
03342                            /foo/baz/maclib::/usr/local/bin/maclib,
03343                            which would get here with a symbol type of ':'.  */
03344                         continue;
03345 
03346                       default:
03347                         /* Unexpected symbol descriptor.  The second and
03348                            subsequent stabs of a continued stab can show up
03349                            here.  The question is whether they ever can
03350                            mimic a normal stab--it would be nice if not,
03351                            since we certainly don't want to spend the time
03352                            searching to the end of every string looking for
03353                            a backslash.  */
03354 
03355                         complaint (&symfile_complaints,
03356                                    _("unknown symbol descriptor `%c'"), p[1]);
03357 
03358                         /* Ignore it; perhaps it is an extension that we don't
03359                            know about.  */
03360                         continue;
03361                       }
03362 
03363                   case N_EXCL:
03364                     continue;
03365 
03366                   case N_ENDM:
03367                     /* Solaris 2 end of module, finish current partial
03368                        symbol table.  END_PSYMTAB will set
03369                        pst->texthigh to the proper value, which is
03370                        necessary if a module compiled without
03371                        debugging info follows this module.  */
03372                     if (pst
03373                         && gdbarch_sofun_address_maybe_missing (gdbarch))
03374                       {
03375                         pst = (struct partial_symtab *) 0;
03376                         includes_used = 0;
03377                         dependencies_used = 0;
03378                       }
03379                     continue;
03380 
03381                   case N_RBRAC:
03382                     if (sh.value > save_pst->texthigh)
03383                       save_pst->texthigh = sh.value;
03384                     continue;
03385                   case N_EINCL:
03386                   case N_DSLINE:
03387                   case N_BSLINE:
03388                   case N_SSYM:          /* Claim: Structure or union
03389                                            element.  Hopefully, I can
03390                                            ignore this.  */
03391                   case N_ENTRY:         /* Alternate entry point; can
03392                                            ignore.  */
03393                   case N_MAIN:          /* Can definitely ignore this.   */
03394                   case N_CATCH:         /* These are GNU C++ extensions.  */
03395                   case N_EHDECL:        /* that can safely be ignored here.  */
03396                   case N_LENG:
03397                   case N_BCOMM:
03398                   case N_ECOMM:
03399                   case N_ECOML:
03400                   case N_FNAME:
03401                   case N_SLINE:
03402                   case N_RSYM:
03403                   case N_PSYM:
03404                   case N_LBRAC:
03405                   case N_NSYMS:         /* Ultrix 4.0: symbol count */
03406                   case N_DEFD:                  /* GNU Modula-2 */
03407                   case N_ALIAS:         /* SunPro F77: alias name, ignore
03408                                            for now.  */
03409 
03410                   case N_OBJ:           /* Useless types from Solaris.  */
03411                   case N_OPT:
03412                     /* These symbols aren't interesting; don't worry about
03413                        them.  */
03414 
03415                     continue;
03416 
03417                   default:
03418                     /* If we haven't found it yet, ignore it.  It's
03419                        probably some new type we don't know about yet.  */
03420                     complaint (&symfile_complaints,
03421                                _("unknown symbol type %s"),
03422                                hex_string (type_code)); /* CUR_SYMBOL_TYPE */
03423                     continue;
03424                   }
03425                 if (stabstring
03426                     && stabstring != debug_info->ss + fh->issBase + sh.iss)
03427                   xfree (stabstring);
03428               }
03429               /* end - Handle continuation */
03430             }
03431         }
03432       else
03433         {
03434           for (cur_sdx = 0; cur_sdx < fh->csym;)
03435             {
03436               char *name;
03437               enum address_class class;
03438 
03439               (*swap_sym_in) (cur_bfd,
03440                               ((char *) debug_info->external_sym
03441                                + ((fh->isymBase + cur_sdx)
03442                                   * external_sym_size)),
03443                               &sh);
03444 
03445               if (ECOFF_IS_STAB (&sh))
03446                 {
03447                   cur_sdx++;
03448                   continue;
03449                 }
03450 
03451               /* Non absolute static symbols go into the minimal table.  */
03452               if (SC_IS_UNDEF (sh.sc) || sh.sc == scNil
03453                   || (sh.index == indexNil
03454                       && (sh.st != stStatic || sh.sc == scAbs)))
03455                 {
03456                   /* FIXME, premature?  */
03457                   cur_sdx++;
03458                   continue;
03459                 }
03460 
03461               name = debug_info->ss + fh->issBase + sh.iss;
03462 
03463               switch (sh.sc)
03464                 {
03465                 case scText:
03466                 case scRConst:
03467                   /* The value of a stEnd symbol is the displacement from the
03468                      corresponding start symbol value, do not relocate it.  */
03469                   if (sh.st != stEnd)
03470                     sh.value += ANOFFSET (objfile->section_offsets,
03471                                           SECT_OFF_TEXT (objfile));
03472                   break;
03473                 case scData:
03474                 case scSData:
03475                 case scRData:
03476                 case scPData:
03477                 case scXData:
03478                   sh.value += ANOFFSET (objfile->section_offsets,
03479                                         SECT_OFF_DATA (objfile));
03480                   break;
03481                 case scBss:
03482                 case scSBss:
03483                   sh.value += ANOFFSET (objfile->section_offsets,
03484                                         SECT_OFF_BSS (objfile));
03485                   break;
03486                 }
03487 
03488               switch (sh.st)
03489                 {
03490                   CORE_ADDR high;
03491                   CORE_ADDR procaddr;
03492                   int new_sdx;
03493 
03494                 case stStaticProc:
03495                   prim_record_minimal_symbol_and_info (name, sh.value,
03496                                                        mst_file_text,
03497                                                        SECT_OFF_TEXT (objfile),
03498                                                        objfile);
03499 
03500                   /* FALLTHROUGH */
03501 
03502                 case stProc:
03503                   /* Ignore all parameter symbol records.  */
03504                   if (sh.index >= hdr->iauxMax)
03505                     {
03506                       /* Should not happen, but does when cross-compiling
03507                          with the MIPS compiler.  FIXME -- pull later.  */
03508                       index_complaint (name);
03509                       new_sdx = cur_sdx + 1;    /* Don't skip at all.  */
03510                     }
03511                   else
03512                     new_sdx = AUX_GET_ISYM (fh->fBigendian,
03513                                             (debug_info->external_aux
03514                                              + fh->iauxBase
03515                                              + sh.index));
03516 
03517                   if (new_sdx <= cur_sdx)
03518                     {
03519                       /* This should not happen either... FIXME.  */
03520                       complaint (&symfile_complaints,
03521                                  _("bad proc end in aux found from symbol %s"),
03522                                  name);
03523                       new_sdx = cur_sdx + 1;    /* Don't skip backward.  */
03524                     }
03525 
03526                   /* For stProc symbol records, we need to check the
03527                      storage class as well, as only (stProc, scText)
03528                      entries represent "real" procedures - See the
03529                      Compaq document titled "Object File / Symbol Table
03530                      Format Specification" for more information.  If the
03531                      storage class is not scText, we discard the whole
03532                      block of symbol records for this stProc.  */
03533                   if (sh.st == stProc && sh.sc != scText)
03534                     goto skip;
03535 
03536                   /* Usually there is a local and a global stProc symbol
03537                      for a function.  This means that the function name
03538                      has already been entered into the mimimal symbol table
03539                      while processing the global symbols in pass 2 above.
03540                      One notable exception is the PROGRAM name from
03541                      f77 compiled executables, it is only put out as
03542                      local stProc symbol, and a global MAIN__ stProc symbol
03543                      points to it.  It doesn't matter though, as gdb is
03544                      still able to find the PROGRAM name via the partial
03545                      symbol table, and the MAIN__ symbol via the minimal
03546                      symbol table.  */
03547                   if (sh.st == stProc)
03548                     add_psymbol_to_list (name, strlen (name), 1,
03549                                          VAR_DOMAIN, LOC_BLOCK,
03550                                          &objfile->global_psymbols,
03551                                     0, sh.value, psymtab_language, objfile);
03552                   else
03553                     add_psymbol_to_list (name, strlen (name), 1,
03554                                          VAR_DOMAIN, LOC_BLOCK,
03555                                          &objfile->static_psymbols,
03556                                     0, sh.value, psymtab_language, objfile);
03557 
03558                   procaddr = sh.value;
03559 
03560                   cur_sdx = new_sdx;
03561                   (*swap_sym_in) (cur_bfd,
03562                                   ((char *) debug_info->external_sym
03563                                    + ((fh->isymBase + cur_sdx - 1)
03564                                       * external_sym_size)),
03565                                   &sh);
03566                   if (sh.st != stEnd)
03567                     continue;
03568 
03569                   /* Kludge for Irix 5.2 zero fh->adr.  */
03570                   if (!relocatable
03571                       && (pst->textlow == 0 || procaddr < pst->textlow))
03572                     pst->textlow = procaddr;
03573 
03574                   high = procaddr + sh.value;
03575                   if (high > pst->texthigh)
03576                     pst->texthigh = high;
03577                   continue;
03578 
03579                 case stStatic:  /* Variable */
03580                   if (SC_IS_DATA (sh.sc))
03581                     prim_record_minimal_symbol_and_info (name, sh.value,
03582                                                          mst_file_data,
03583                                                          SECT_OFF_DATA (objfile),
03584                                                          objfile);
03585                   else
03586                     prim_record_minimal_symbol_and_info (name, sh.value,
03587                                                          mst_file_bss,
03588                                                          SECT_OFF_BSS (objfile),
03589                                                          objfile);
03590                   class = LOC_STATIC;
03591                   break;
03592 
03593                 case stIndirect:        /* Irix5 forward declaration */
03594                   /* Skip forward declarations from Irix5 cc.  */
03595                   goto skip;
03596 
03597                 case stTypedef: /* Typedef */
03598                   /* Skip typedefs for forward declarations and opaque
03599                      structs from alpha and mips cc.  */
03600                   if (sh.iss == 0 || has_opaque_xref (fh, &sh))
03601                     goto skip;
03602                   class = LOC_TYPEDEF;
03603                   break;
03604 
03605                 case stConstant:        /* Constant decl */
03606                   class = LOC_CONST;
03607                   break;
03608 
03609                 case stUnion:
03610                 case stStruct:
03611                 case stEnum:
03612                 case stBlock:   /* { }, str, un, enum */
03613                   /* Do not create a partial symbol for cc unnamed aggregates
03614                      and gcc empty aggregates.  */
03615                   if ((sh.sc == scInfo
03616                        || SC_IS_COMMON (sh.sc))
03617                       && sh.iss != 0
03618                       && sh.index != cur_sdx + 2)
03619                     {
03620                       add_psymbol_to_list (name, strlen (name), 1,
03621                                            STRUCT_DOMAIN, LOC_TYPEDEF,
03622                                            &objfile->static_psymbols,
03623                                            0, (CORE_ADDR) 0,
03624                                            psymtab_language, objfile);
03625                     }
03626                   handle_psymbol_enumerators (objfile, fh, sh.st, sh.value);
03627 
03628                   /* Skip over the block.  */
03629                   new_sdx = sh.index;
03630                   if (new_sdx <= cur_sdx)
03631                     {
03632                       /* This happens with the Ultrix kernel.  */
03633                       complaint (&symfile_complaints,
03634                                  _("bad aux index at block symbol %s"), name);
03635                       new_sdx = cur_sdx + 1;    /* Don't skip backward.  */
03636                     }
03637                   cur_sdx = new_sdx;
03638                   continue;
03639 
03640                 case stFile:    /* File headers */
03641                 case stLabel:   /* Labels */
03642                 case stEnd:     /* Ends of files */
03643                   goto skip;
03644 
03645                 case stLocal:   /* Local variables */
03646                   /* Normally these are skipped because we skip over
03647                      all blocks we see.  However, these can occur
03648                      as visible symbols in a .h file that contains code.  */
03649                   goto skip;
03650 
03651                 default:
03652                   /* Both complaints are valid:  one gives symbol name,
03653                      the other the offending symbol type.  */
03654                   complaint (&symfile_complaints, _("unknown local symbol %s"),
03655                              name);
03656                   complaint (&symfile_complaints, _("with type %d"), sh.st);
03657                   cur_sdx++;
03658                   continue;
03659                 }
03660               /* Use this gdb symbol.  */
03661               add_psymbol_to_list (name, strlen (name), 1,
03662                                    VAR_DOMAIN, class,
03663                                    &objfile->static_psymbols,
03664                                    0, sh.value, psymtab_language, objfile);
03665             skip:
03666               cur_sdx++;        /* Go to next file symbol.  */
03667             }
03668 
03669           /* Now do enter the external symbols.  */
03670           ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
03671           cur_sdx = fdr_to_pst[f_idx].n_globals;
03672           PST_PRIVATE (save_pst)->extern_count = cur_sdx;
03673           PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
03674           for (; --cur_sdx >= 0; ext_ptr++)
03675             {
03676               enum address_class class;
03677               SYMR *psh;
03678               char *name;
03679               CORE_ADDR svalue;
03680 
03681               if (ext_ptr->ifd != f_idx)
03682                 internal_error (__FILE__, __LINE__,
03683                                 _("failed internal consistency check"));
03684               psh = &ext_ptr->asym;
03685 
03686               /* Do not add undefined symbols to the partial symbol table.  */
03687               if (SC_IS_UNDEF (psh->sc) || psh->sc == scNil)
03688                 continue;
03689 
03690               svalue = psh->value;
03691               switch (psh->sc)
03692                 {
03693                 case scText:
03694                 case scRConst:
03695                   svalue += ANOFFSET (objfile->section_offsets,
03696                                       SECT_OFF_TEXT (objfile));
03697                   break;
03698                 case scData:
03699                 case scSData:
03700                 case scRData:
03701                 case scPData:
03702                 case scXData:
03703                   svalue += ANOFFSET (objfile->section_offsets,
03704                                       SECT_OFF_DATA (objfile));
03705                   break;
03706                 case scBss:
03707                 case scSBss:
03708                   svalue += ANOFFSET (objfile->section_offsets,
03709                                       SECT_OFF_BSS (objfile));
03710                   break;
03711                 }
03712 
03713               switch (psh->st)
03714                 {
03715                 case stNil:
03716                   /* These are generated for static symbols in .o files,
03717                      ignore them.  */
03718                   continue;
03719                 case stProc:
03720                 case stStaticProc:
03721                   /* External procedure symbols have been entered
03722                      into the minimal symbol table in pass 2 above.
03723                      Ignore them, as parse_external will ignore them too.  */
03724                   continue;
03725                 case stLabel:
03726                   class = LOC_LABEL;
03727                   break;
03728                 default:
03729                   unknown_ext_complaint (debug_info->ssext + psh->iss);
03730                   /* Fall through, pretend it's global.  */
03731                 case stGlobal:
03732                   /* Global common symbols are resolved by the runtime loader,
03733                      ignore them.  */
03734                   if (SC_IS_COMMON (psh->sc))
03735                     continue;
03736 
03737                   class = LOC_STATIC;
03738                   break;
03739                 }
03740               name = debug_info->ssext + psh->iss;
03741               add_psymbol_to_list (name, strlen (name), 1,
03742                                    VAR_DOMAIN, class,
03743                                    &objfile->global_psymbols,
03744                                    0, svalue,
03745                                    psymtab_language, objfile);
03746             }
03747         }
03748 
03749       /* Link pst to FDR.  end_psymtab returns NULL if the psymtab was
03750          empty and put on the free list.  */
03751       fdr_to_pst[f_idx].pst = end_psymtab (objfile, save_pst,
03752                                         psymtab_include_list, includes_used,
03753                                            -1, save_pst->texthigh,
03754                        dependency_list, dependencies_used, textlow_not_set);
03755       includes_used = 0;
03756       dependencies_used = 0;
03757 
03758       /* The objfile has its functions reordered if this partial symbol
03759          table overlaps any other partial symbol table.
03760          We cannot assume a reordered objfile if a partial symbol table
03761          is contained within another partial symbol table, as partial symbol
03762          tables for include files with executable code are contained
03763          within the partial symbol table for the including source file,
03764          and we do not want to flag the objfile reordered for these cases.
03765 
03766          This strategy works well for Irix-5.2 shared libraries, but we
03767          might have to use a more elaborate (and slower) algorithm for
03768          other cases.  */
03769       save_pst = fdr_to_pst[f_idx].pst;
03770       if (save_pst != NULL
03771           && save_pst->textlow != 0
03772           && !(objfile->flags & OBJF_REORDERED))
03773         {
03774           ALL_OBJFILE_PSYMTABS (objfile, pst)
03775           {
03776             if (save_pst != pst
03777                 && save_pst->textlow >= pst->textlow
03778                 && save_pst->textlow < pst->texthigh
03779                 && save_pst->texthigh > pst->texthigh)
03780               {
03781                 objfile->flags |= OBJF_REORDERED;
03782                 break;
03783               }
03784           }
03785         }
03786     }
03787 
03788   /* Now scan the FDRs for dependencies.  */
03789   for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
03790     {
03791       fh = f_idx + debug_info->fdr;
03792       pst = fdr_to_pst[f_idx].pst;
03793 
03794       if (pst == (struct partial_symtab *) NULL)
03795         continue;
03796 
03797       /* This should catch stabs-in-ecoff.  */
03798       if (fh->crfd <= 1)
03799         continue;
03800 
03801       /* Skip the first file indirect entry as it is a self dependency for
03802          source files or a reverse .h -> .c dependency for header files.  */
03803       pst->number_of_dependencies = 0;
03804       pst->dependencies =
03805         ((struct partial_symtab **)
03806          obstack_alloc (&objfile->objfile_obstack,
03807                         ((fh->crfd - 1)
03808                          * sizeof (struct partial_symtab *))));
03809       for (s_idx = 1; s_idx < fh->crfd; s_idx++)
03810         {
03811           RFDT rh;
03812 
03813           (*swap_rfd_in) (cur_bfd,
03814                           ((char *) debug_info->external_rfd
03815                            + (fh->rfdBase + s_idx) * external_rfd_size),
03816                           &rh);
03817           if (rh < 0 || rh >= hdr->ifdMax)
03818             {
03819               complaint (&symfile_complaints, _("bad file number %ld"), rh);
03820               continue;
03821             }
03822 
03823           /* Skip self dependencies of header files.  */
03824           if (rh == f_idx)
03825             continue;
03826 
03827           /* Do not add to dependeny list if psymtab was empty.  */
03828           if (fdr_to_pst[rh].pst == (struct partial_symtab *) NULL)
03829             continue;
03830           pst->dependencies[pst->number_of_dependencies++]
03831             = fdr_to_pst[rh].pst;
03832         }
03833     }
03834 
03835   /* Remove the dummy psymtab created for -O3 images above, if it is
03836      still empty, to enable the detection of stripped executables.  */
03837   if (objfile->psymtabs->next == NULL
03838       && objfile->psymtabs->number_of_dependencies == 0
03839       && objfile->psymtabs->n_global_syms == 0
03840       && objfile->psymtabs->n_static_syms == 0)
03841     objfile->psymtabs = NULL;
03842   do_cleanups (old_chain);
03843 }
03844 
03845 /* If the current psymbol has an enumerated type, we need to add
03846    all the enum constants to the partial symbol table.  */
03847 
03848 static void
03849 handle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype,
03850                             CORE_ADDR svalue)
03851 {
03852   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
03853   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
03854   char *ext_sym = ((char *) debug_info->external_sym
03855                    + ((fh->isymBase + cur_sdx + 1) * external_sym_size));
03856   SYMR sh;
03857   TIR tir;
03858 
03859   switch (stype)
03860     {
03861     case stEnum:
03862       break;
03863 
03864     case stBlock:
03865       /* It is an enumerated type if the next symbol entry is a stMember
03866          and its auxiliary index is indexNil or its auxiliary entry
03867          is a plain btNil or btVoid.
03868          Alpha cc -migrate enums are recognized by a zero index and
03869          a zero symbol value.
03870          DU 4.0 cc enums are recognized by a member type of btEnum without
03871          qualifiers and a zero symbol value.  */
03872       (*swap_sym_in) (cur_bfd, ext_sym, &sh);
03873       if (sh.st != stMember)
03874         return;
03875 
03876       if (sh.index == indexNil
03877           || (sh.index == 0 && svalue == 0))
03878         break;
03879       (*debug_swap->swap_tir_in) (fh->fBigendian,
03880                                   &(debug_info->external_aux
03881                                     + fh->iauxBase + sh.index)->a_ti,
03882                                   &tir);
03883       if ((tir.bt != btNil
03884            && tir.bt != btVoid
03885            && (tir.bt != btEnum || svalue != 0))
03886           || tir.tq0 != tqNil)
03887         return;
03888       break;
03889 
03890     default:
03891       return;
03892     }
03893 
03894   for (;;)
03895     {
03896       char *name;
03897 
03898       (*swap_sym_in) (cur_bfd, ext_sym, &sh);
03899       if (sh.st != stMember)
03900         break;
03901       name = debug_info->ss + cur_fdr->issBase + sh.iss;
03902 
03903       /* Note that the value doesn't matter for enum constants
03904          in psymtabs, just in symtabs.  */
03905       add_psymbol_to_list (name, strlen (name), 1,
03906                            VAR_DOMAIN, LOC_CONST,
03907                            &objfile->static_psymbols, 0,
03908                            (CORE_ADDR) 0, psymtab_language, objfile);
03909       ext_sym += external_sym_size;
03910     }
03911 }
03912 
03913 /* Get the next symbol.  OBJFILE is unused.  */
03914 
03915 static char *
03916 mdebug_next_symbol_text (struct objfile *objfile)
03917 {
03918   SYMR sh;
03919 
03920   cur_sdx++;
03921   (*debug_swap->swap_sym_in) (cur_bfd,
03922                               ((char *) debug_info->external_sym
03923                                + ((cur_fdr->isymBase + cur_sdx)
03924                                   * debug_swap->external_sym_size)),
03925                               &sh);
03926   return debug_info->ss + cur_fdr->issBase + sh.iss;
03927 }
03928 
03929 /* Ancillary function to psymtab_to_symtab().  Does all the work
03930    for turning the partial symtab PST into a symtab, recurring
03931    first on all dependent psymtabs.  The argument FILENAME is
03932    only passed so we can see in debug stack traces what file
03933    is being read.
03934 
03935    This function has a split personality, based on whether the
03936    symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
03937    The flow of control and even the memory allocation differs.  FIXME.  */
03938 
03939 static void
03940 psymtab_to_symtab_1 (struct objfile *objfile,
03941                      struct partial_symtab *pst, const char *filename)
03942 {
03943   bfd_size_type external_sym_size;
03944   bfd_size_type external_pdr_size;
03945   void (*swap_sym_in) (bfd *, void *, SYMR *);
03946   void (*swap_pdr_in) (bfd *, void *, PDR *);
03947   int i;
03948   struct symtab *st = NULL;
03949   FDR *fh;
03950   struct linetable *lines;
03951   CORE_ADDR lowest_pdr_addr = 0;
03952   int last_symtab_ended = 0;
03953 
03954   if (pst->readin)
03955     return;
03956   pst->readin = 1;
03957 
03958   /* Read in all partial symbtabs on which this one is dependent.
03959      NOTE that we do have circular dependencies, sigh.  We solved
03960      that by setting pst->readin before this point.  */
03961 
03962   for (i = 0; i < pst->number_of_dependencies; i++)
03963     if (!pst->dependencies[i]->readin)
03964       {
03965         /* Inform about additional files to be read in.  */
03966         if (info_verbose)
03967           {
03968             fputs_filtered (" ", gdb_stdout);
03969             wrap_here ("");
03970             fputs_filtered ("and ", gdb_stdout);
03971             wrap_here ("");
03972             printf_filtered ("%s...",
03973                              pst->dependencies[i]->filename);
03974             wrap_here ("");     /* Flush output */
03975             gdb_flush (gdb_stdout);
03976           }
03977         /* We only pass the filename for debug purposes.  */
03978         psymtab_to_symtab_1 (objfile, pst->dependencies[i],
03979                              pst->dependencies[i]->filename);
03980       }
03981 
03982   /* Do nothing if this is a dummy psymtab.  */
03983 
03984   if (pst->n_global_syms == 0 && pst->n_static_syms == 0
03985       && pst->textlow == 0 && pst->texthigh == 0)
03986     return;
03987 
03988   /* Now read the symbols for this symtab.  */
03989 
03990   cur_bfd = CUR_BFD (pst);
03991   debug_swap = DEBUG_SWAP (pst);
03992   debug_info = DEBUG_INFO (pst);
03993   pending_list = PENDING_LIST (pst);
03994   external_sym_size = debug_swap->external_sym_size;
03995   external_pdr_size = debug_swap->external_pdr_size;
03996   swap_sym_in = debug_swap->swap_sym_in;
03997   swap_pdr_in = debug_swap->swap_pdr_in;
03998   mdebugread_objfile = objfile;
03999   cur_fd = FDR_IDX (pst);
04000   fh = ((cur_fd == -1)
04001         ? (FDR *) NULL
04002         : debug_info->fdr + cur_fd);
04003   cur_fdr = fh;
04004 
04005   /* See comment in parse_partial_symbols about the @stabs sentinel.  */
04006   processing_gcc_compilation = 0;
04007   if (fh != (FDR *) NULL && fh->csym >= 2)
04008     {
04009       SYMR sh;
04010 
04011       (*swap_sym_in) (cur_bfd,
04012                       ((char *) debug_info->external_sym
04013                        + (fh->isymBase + 1) * external_sym_size),
04014                       &sh);
04015       if (strcmp (debug_info->ss + fh->issBase + sh.iss,
04016                   stabs_symbol) == 0)
04017         {
04018           /* We indicate that this is a GCC compilation so that certain
04019              features will be enabled in stabsread/dbxread.  */
04020           processing_gcc_compilation = 2;
04021         }
04022     }
04023 
04024   if (processing_gcc_compilation != 0)
04025     {
04026       struct gdbarch *gdbarch = get_objfile_arch (objfile);
04027 
04028       /* This symbol table contains stabs-in-ecoff entries.  */
04029 
04030       /* Parse local symbols first.  */
04031 
04032       if (fh->csym <= 2)        /* FIXME, this blows psymtab->symtab ptr.  */
04033         {
04034           mdebugread_objfile = NULL;
04035           return;
04036         }
04037       for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
04038         {
04039           SYMR sh;
04040           char *name;
04041           CORE_ADDR valu;
04042 
04043           (*swap_sym_in) (cur_bfd,
04044                           (((char *) debug_info->external_sym)
04045                            + (fh->isymBase + cur_sdx) * external_sym_size),
04046                           &sh);
04047           name = debug_info->ss + fh->issBase + sh.iss;
04048           valu = sh.value;
04049           /* XXX This is a hack.  It will go away!  */
04050           if (ECOFF_IS_STAB (&sh) || (name[0] == '#'))
04051             {
04052               int type_code = ECOFF_UNMARK_STAB (sh.index);
04053 
04054               /* We should never get non N_STAB symbols here, but they
04055                  should be harmless, so keep process_one_symbol from
04056                  complaining about them.  */
04057               if (type_code & N_STAB)
04058                 {
04059                   /* If we found a trailing N_SO with no name, process
04060                      it here instead of in process_one_symbol, so we
04061                      can keep a handle to its symtab.  The symtab
04062                      would otherwise be ended twice, once in
04063                      process_one_symbol, and once after this loop.  */
04064                   if (type_code == N_SO
04065                       && get_last_source_file ()
04066                       && previous_stab_code != (unsigned char) N_SO
04067                       && *name == '\000')
04068                     {
04069                       valu += ANOFFSET (pst->section_offsets,
04070                                         SECT_OFF_TEXT (objfile));
04071                       previous_stab_code = N_SO;
04072                       st = end_symtab (valu, objfile,
04073                                        SECT_OFF_TEXT (objfile));
04074                       end_stabs ();
04075                       last_symtab_ended = 1;
04076                     }
04077                   else
04078                     {
04079                       last_symtab_ended = 0;
04080                       process_one_symbol (type_code, 0, valu, name,
04081                                           pst->section_offsets, objfile);
04082                     }
04083                 }
04084               /* Similarly a hack.  */
04085               else if (name[0] == '#')
04086                 {
04087                   process_one_symbol (N_SLINE, 0, valu, name,
04088                                       pst->section_offsets, objfile);
04089                 }
04090               if (type_code == N_FUN)
04091                 {
04092                   /* Make up special symbol to contain
04093                      procedure specific info.  */
04094                   struct mdebug_extra_func_info *e =
04095                     ((struct mdebug_extra_func_info *)
04096                      obstack_alloc (&mdebugread_objfile->objfile_obstack,
04097                                     sizeof (struct mdebug_extra_func_info)));
04098                   struct symbol *s = new_symbol (MDEBUG_EFI_SYMBOL_NAME);
04099 
04100                   memset (e, 0, sizeof (struct mdebug_extra_func_info));
04101                   SYMBOL_DOMAIN (s) = LABEL_DOMAIN;
04102                   SYMBOL_ACLASS_INDEX (s) = LOC_CONST;
04103                   SYMBOL_TYPE (s) = objfile_type (objfile)->builtin_void;
04104                   SYMBOL_VALUE_BYTES (s) = (gdb_byte *) e;
04105                   e->pdr.framereg = -1;
04106                   add_symbol_to_list (s, &local_symbols);
04107                 }
04108             }
04109           else if (sh.st == stLabel)
04110             {
04111               if (sh.index == indexNil)
04112                 {
04113                   /* This is what the gcc2_compiled and __gnu_compiled_*
04114                      show up as.  So don't complain.  */
04115                   ;
04116                 }
04117               else
04118                 {
04119                   /* Handle encoded stab line number.  */
04120                   valu += ANOFFSET (pst->section_offsets,
04121                                     SECT_OFF_TEXT (objfile));
04122                   record_line (current_subfile, sh.index,
04123                                gdbarch_addr_bits_remove (gdbarch, valu));
04124                 }
04125             }
04126           else if (sh.st == stProc || sh.st == stStaticProc
04127                    || sh.st == stStatic || sh.st == stEnd)
04128             /* These are generated by gcc-2.x, do not complain.  */
04129             ;
04130           else
04131             complaint (&symfile_complaints,
04132                        _("unknown stabs symbol %s"), name);
04133         }
04134 
04135       if (! last_symtab_ended)
04136         {
04137           st = end_symtab (pst->texthigh, objfile,
04138                            SECT_OFF_TEXT (objfile));
04139           end_stabs ();
04140         }
04141 
04142       /* There used to be a call to sort_blocks here, but this should not
04143          be necessary for stabs symtabs.  And as sort_blocks modifies the
04144          start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK,
04145          it did the wrong thing if the first procedure in a file was
04146          generated via asm statements.  */
04147 
04148       /* Fill in procedure info next.  */
04149       if (fh->cpd > 0)
04150         {
04151           PDR *pr_block;
04152           struct cleanup *old_chain;
04153           char *pdr_ptr;
04154           char *pdr_end;
04155           PDR *pdr_in;
04156           PDR *pdr_in_end;
04157 
04158           pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
04159           old_chain = make_cleanup (xfree, pr_block);
04160 
04161           pdr_ptr = ((char *) debug_info->external_pdr
04162                      + fh->ipdFirst * external_pdr_size);
04163           pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
04164           pdr_in = pr_block;
04165           for (;
04166                pdr_ptr < pdr_end;
04167                pdr_ptr += external_pdr_size, pdr_in++)
04168             {
04169               (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
04170 
04171               /* Determine lowest PDR address, the PDRs are not always
04172                  sorted.  */
04173               if (pdr_in == pr_block)
04174                 lowest_pdr_addr = pdr_in->adr;
04175               else if (pdr_in->adr < lowest_pdr_addr)
04176                 lowest_pdr_addr = pdr_in->adr;
04177             }
04178 
04179           pdr_in = pr_block;
04180           pdr_in_end = pdr_in + fh->cpd;
04181           for (; pdr_in < pdr_in_end; pdr_in++)
04182             parse_procedure (pdr_in, st, pst);
04183 
04184           do_cleanups (old_chain);
04185         }
04186     }
04187   else
04188     {
04189       /* This symbol table contains ordinary ecoff entries.  */
04190 
04191       int maxlines, size;
04192       EXTR *ext_ptr;
04193 
04194       if (fh == 0)
04195         {
04196           maxlines = 0;
04197           st = new_symtab ("unknown", 0, objfile);
04198         }
04199       else
04200         {
04201           maxlines = 2 * fh->cline;
04202           st = new_symtab (pst->filename, maxlines, objfile);
04203 
04204           /* The proper language was already determined when building
04205              the psymtab, use it.  */
04206           st->language = PST_PRIVATE (pst)->pst_language;
04207         }
04208 
04209       psymtab_language = st->language;
04210 
04211       lines = LINETABLE (st);
04212 
04213       /* Get a new lexical context.  */
04214 
04215       push_parse_stack ();
04216       top_stack->cur_st = st;
04217       top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st),
04218                                                 STATIC_BLOCK);
04219       BLOCK_START (top_stack->cur_block) = pst->textlow;
04220       BLOCK_END (top_stack->cur_block) = 0;
04221       top_stack->blocktype = stFile;
04222       top_stack->cur_type = 0;
04223       top_stack->procadr = 0;
04224       top_stack->numargs = 0;
04225       found_ecoff_debugging_info = 0;
04226 
04227       if (fh)
04228         {
04229           char *sym_ptr;
04230           char *sym_end;
04231 
04232           /* Parse local symbols first.  */
04233           sym_ptr = ((char *) debug_info->external_sym
04234                      + fh->isymBase * external_sym_size);
04235           sym_end = sym_ptr + fh->csym * external_sym_size;
04236           while (sym_ptr < sym_end)
04237             {
04238               SYMR sh;
04239               int c;
04240 
04241               (*swap_sym_in) (cur_bfd, sym_ptr, &sh);
04242               c = parse_symbol (&sh,
04243                                 debug_info->external_aux + fh->iauxBase,
04244                                 sym_ptr, fh->fBigendian,
04245                                 pst->section_offsets, objfile);
04246               sym_ptr += c * external_sym_size;
04247             }
04248 
04249           /* Linenumbers.  At the end, check if we can save memory.
04250              parse_lines has to look ahead an arbitrary number of PDR
04251              structures, so we swap them all first.  */
04252           if (fh->cpd > 0)
04253             {
04254               PDR *pr_block;
04255               struct cleanup *old_chain;
04256               char *pdr_ptr;
04257               char *pdr_end;
04258               PDR *pdr_in;
04259               PDR *pdr_in_end;
04260 
04261               pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
04262 
04263               old_chain = make_cleanup (xfree, pr_block);
04264 
04265               pdr_ptr = ((char *) debug_info->external_pdr
04266                          + fh->ipdFirst * external_pdr_size);
04267               pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
04268               pdr_in = pr_block;
04269               for (;
04270                    pdr_ptr < pdr_end;
04271                    pdr_ptr += external_pdr_size, pdr_in++)
04272                 {
04273                   (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
04274 
04275                   /* Determine lowest PDR address, the PDRs are not always
04276                      sorted.  */
04277                   if (pdr_in == pr_block)
04278                     lowest_pdr_addr = pdr_in->adr;
04279                   else if (pdr_in->adr < lowest_pdr_addr)
04280                     lowest_pdr_addr = pdr_in->adr;
04281                 }
04282 
04283               parse_lines (fh, pr_block, lines, maxlines,
04284                            pst, lowest_pdr_addr);
04285               if (lines->nitems < fh->cline)
04286                 lines = shrink_linetable (lines);
04287 
04288               /* Fill in procedure info next.  */
04289               pdr_in = pr_block;
04290               pdr_in_end = pdr_in + fh->cpd;
04291               for (; pdr_in < pdr_in_end; pdr_in++)
04292                 parse_procedure (pdr_in, 0, pst);
04293 
04294               do_cleanups (old_chain);
04295             }
04296         }
04297 
04298       size = lines->nitems;
04299       if (size > 1)
04300         --size;
04301       LINETABLE (st) = obstack_copy (&mdebugread_objfile->objfile_obstack,
04302                                      lines,
04303                                      (sizeof (struct linetable)
04304                                       + size * sizeof (lines->item)));
04305       xfree (lines);
04306 
04307       /* .. and our share of externals.
04308          XXX use the global list to speed up things here.  How?
04309          FIXME, Maybe quit once we have found the right number of ext's?  */
04310       top_stack->cur_st = st;
04311       top_stack->cur_block
04312         = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
04313                              GLOBAL_BLOCK);
04314       top_stack->blocktype = stFile;
04315 
04316       ext_ptr = PST_PRIVATE (pst)->extern_tab;
04317       for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
04318         parse_external (ext_ptr, fh->fBigendian,
04319                         pst->section_offsets, objfile);
04320 
04321       /* If there are undefined symbols, tell the user.
04322          The alpha has an undefined symbol for every symbol that is
04323          from a shared library, so tell the user only if verbose is on.  */
04324       if (info_verbose && n_undef_symbols)
04325         {
04326           printf_filtered (_("File %s contains %d unresolved references:"),
04327                            symtab_to_filename_for_display (st),
04328                            n_undef_symbols);
04329           printf_filtered ("\n\t%4d variables\n\t%4d "
04330                            "procedures\n\t%4d labels\n",
04331                            n_undef_vars, n_undef_procs, n_undef_labels);
04332           n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
04333 
04334         }
04335       pop_parse_stack ();
04336 
04337       st->primary = 1;
04338 
04339       sort_blocks (st);
04340     }
04341 
04342   /* Now link the psymtab and the symtab.  */
04343   pst->symtab = st;
04344 
04345   mdebugread_objfile = NULL;
04346 }
04347 
04348 /* Ancillary parsing procedures.  */
04349 
04350 /* Return 1 if the symbol pointed to by SH has a cross reference
04351    to an opaque aggregate type, else 0.  */
04352 
04353 static int
04354 has_opaque_xref (FDR *fh, SYMR *sh)
04355 {
04356   TIR tir;
04357   union aux_ext *ax;
04358   RNDXR rn[1];
04359   unsigned int rf;
04360 
04361   if (sh->index == indexNil)
04362     return 0;
04363 
04364   ax = debug_info->external_aux + fh->iauxBase + sh->index;
04365   (*debug_swap->swap_tir_in) (fh->fBigendian, &ax->a_ti, &tir);
04366   if (tir.bt != btStruct && tir.bt != btUnion && tir.bt != btEnum)
04367     return 0;
04368 
04369   ax++;
04370   (*debug_swap->swap_rndx_in) (fh->fBigendian, &ax->a_rndx, rn);
04371   if (rn->rfd == 0xfff)
04372     rf = AUX_GET_ISYM (fh->fBigendian, ax + 1);
04373   else
04374     rf = rn->rfd;
04375   if (rf != -1)
04376     return 0;
04377   return 1;
04378 }
04379 
04380 /* Lookup the type at relative index RN.  Return it in TPP
04381    if found and in any event come up with its name PNAME.
04382    BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
04383    Return value says how many aux symbols we ate.  */
04384 
04385 static int
04386 cross_ref (int fd, union aux_ext *ax, struct type **tpp,
04387            enum type_code type_code,
04388            /* Use to alloc new type if none is found.  */
04389            char **pname, int bigend, char *sym_name)
04390 {
04391   RNDXR rn[1];
04392   unsigned int rf;
04393   int result = 1;
04394   FDR *fh;
04395   char *esh;
04396   SYMR sh;
04397   int xref_fd;
04398   struct mdebug_pending *pend;
04399 
04400   *tpp = (struct type *) NULL;
04401 
04402   (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
04403 
04404   /* Escape index means 'the next one'.  */
04405   if (rn->rfd == 0xfff)
04406     {
04407       result++;
04408       rf = AUX_GET_ISYM (bigend, ax + 1);
04409     }
04410   else
04411     {
04412       rf = rn->rfd;
04413     }
04414 
04415   /* mips cc uses a rf of -1 for opaque struct definitions.
04416      Set TYPE_FLAG_STUB for these types so that check_typedef will
04417      resolve them if the struct gets defined in another compilation unit.  */
04418   if (rf == -1)
04419     {
04420       *pname = "<undefined>";
04421       *tpp = init_type (type_code, 0, TYPE_FLAG_STUB,
04422                         (char *) NULL, mdebugread_objfile);
04423       return result;
04424     }
04425 
04426   /* mips cc uses an escaped rn->index of 0 for struct return types
04427      of procedures that were compiled without -g.  These will always remain
04428      undefined.  */
04429   if (rn->rfd == 0xfff && rn->index == 0)
04430     {
04431       *pname = "<undefined>";
04432       return result;
04433     }
04434 
04435   /* Find the relative file descriptor and the symbol in it.  */
04436   fh = get_rfd (fd, rf);
04437   xref_fd = fh - debug_info->fdr;
04438 
04439   if (rn->index >= fh->csym)
04440     {
04441       /* File indirect entry is corrupt.  */
04442       *pname = "<illegal>";
04443       bad_rfd_entry_complaint (sym_name, xref_fd, rn->index);
04444       return result;
04445     }
04446 
04447   /* If we have processed this symbol then we left a forwarding
04448      pointer to the type in the pending list.  If not, we`ll put
04449      it in a list of pending types, to be processed later when
04450      the file will be.  In any event, we collect the name for the
04451      type here.  */
04452 
04453   esh = ((char *) debug_info->external_sym
04454          + ((fh->isymBase + rn->index)
04455             * debug_swap->external_sym_size));
04456   (*debug_swap->swap_sym_in) (cur_bfd, esh, &sh);
04457 
04458   /* Make sure that this type of cross reference can be handled.  */
04459   if ((sh.sc != scInfo
04460        || (sh.st != stBlock && sh.st != stTypedef && sh.st != stIndirect
04461            && sh.st != stStruct && sh.st != stUnion
04462            && sh.st != stEnum))
04463       && (sh.st != stBlock || !SC_IS_COMMON (sh.sc)))
04464     {
04465       /* File indirect entry is corrupt.  */
04466       *pname = "<illegal>";
04467       bad_rfd_entry_complaint (sym_name, xref_fd, rn->index);
04468       return result;
04469     }
04470 
04471   *pname = debug_info->ss + fh->issBase + sh.iss;
04472 
04473   pend = is_pending_symbol (fh, esh);
04474   if (pend)
04475     *tpp = pend->t;
04476   else
04477     {
04478       /* We have not yet seen this type.  */
04479 
04480       if ((sh.iss == 0 && sh.st == stTypedef) || sh.st == stIndirect)
04481         {
04482           TIR tir;
04483 
04484           /* alpha cc puts out a stTypedef with a sh.iss of zero for
04485              two cases:
04486              a) forward declarations of structs/unions/enums which are not
04487              defined in this compilation unit.
04488              For these the type will be void.  This is a bad design decision
04489              as cross referencing across compilation units is impossible
04490              due to the missing name.
04491              b) forward declarations of structs/unions/enums/typedefs which
04492              are defined later in this file or in another file in the same
04493              compilation unit.  Irix5 cc uses a stIndirect symbol for this.
04494              Simply cross reference those again to get the true type.
04495              The forward references are not entered in the pending list and
04496              in the symbol table.  */
04497 
04498           (*debug_swap->swap_tir_in) (bigend,
04499                                       &(debug_info->external_aux
04500                                         + fh->iauxBase + sh.index)->a_ti,
04501                                       &tir);
04502           if (tir.tq0 != tqNil)
04503             complaint (&symfile_complaints,
04504                        _("illegal tq0 in forward typedef for %s"), sym_name);
04505           switch (tir.bt)
04506             {
04507             case btVoid:
04508               *tpp = init_type (type_code, 0, 0, (char *) NULL,
04509                                 mdebugread_objfile);
04510               *pname = "<undefined>";
04511               break;
04512 
04513             case btStruct:
04514             case btUnion:
04515             case btEnum:
04516               cross_ref (xref_fd,
04517                          (debug_info->external_aux
04518                           + fh->iauxBase + sh.index + 1),
04519                          tpp, type_code, pname,
04520                          fh->fBigendian, sym_name);
04521               break;
04522 
04523             case btTypedef:
04524               /* Follow a forward typedef.  This might recursively
04525                  call cross_ref till we get a non typedef'ed type.
04526                  FIXME: This is not correct behaviour, but gdb currently
04527                  cannot handle typedefs without type copying.  Type
04528                  copying is impossible as we might have mutual forward
04529                  references between two files and the copied type would not
04530                  get filled in when we later parse its definition.  */
04531               *tpp = parse_type (xref_fd,
04532                                  debug_info->external_aux + fh->iauxBase,
04533                                  sh.index,
04534                                  (int *) NULL,
04535                                  fh->fBigendian,
04536                                  debug_info->ss + fh->issBase + sh.iss);
04537               add_pending (fh, esh, *tpp);
04538               break;
04539 
04540             default:
04541               complaint (&symfile_complaints,
04542                          _("illegal bt %d in forward typedef for %s"), tir.bt,
04543                          sym_name);
04544               *tpp = init_type (type_code, 0, 0, (char *) NULL,
04545                                 mdebugread_objfile);
04546               break;
04547             }
04548           return result;
04549         }
04550       else if (sh.st == stTypedef)
04551         {
04552           /* Parse the type for a normal typedef.  This might recursively call
04553              cross_ref till we get a non typedef'ed type.
04554              FIXME: This is not correct behaviour, but gdb currently
04555              cannot handle typedefs without type copying.  But type copying is
04556              impossible as we might have mutual forward references between
04557              two files and the copied type would not get filled in when
04558              we later parse its definition.   */
04559           *tpp = parse_type (xref_fd,
04560                              debug_info->external_aux + fh->iauxBase,
04561                              sh.index,
04562                              (int *) NULL,
04563                              fh->fBigendian,
04564                              debug_info->ss + fh->issBase + sh.iss);
04565         }
04566       else
04567         {
04568           /* Cross reference to a struct/union/enum which is defined
04569              in another file in the same compilation unit but that file
04570              has not been parsed yet.
04571              Initialize the type only, it will be filled in when
04572              it's definition is parsed.  */
04573           *tpp = init_type (type_code, 0, 0, (char *) NULL, mdebugread_objfile);
04574         }
04575       add_pending (fh, esh, *tpp);
04576     }
04577 
04578   /* We used one auxent normally, two if we got a "next one" rf.  */
04579   return result;
04580 }
04581 
04582 
04583 /* Quick&dirty lookup procedure, to avoid the MI ones that require
04584    keeping the symtab sorted.  */
04585 
04586 static struct symbol *
04587 mylookup_symbol (char *name, struct block *block,
04588                  domain_enum domain, enum address_class class)
04589 {
04590   struct block_iterator iter;
04591   int inc;
04592   struct symbol *sym;
04593 
04594   inc = name[0];
04595   ALL_BLOCK_SYMBOLS (block, iter, sym)
04596     {
04597       if (SYMBOL_LINKAGE_NAME (sym)[0] == inc
04598           && SYMBOL_DOMAIN (sym) == domain
04599           && SYMBOL_CLASS (sym) == class
04600           && strcmp (SYMBOL_LINKAGE_NAME (sym), name) == 0)
04601         return sym;
04602     }
04603 
04604   block = BLOCK_SUPERBLOCK (block);
04605   if (block)
04606     return mylookup_symbol (name, block, domain, class);
04607   return 0;
04608 }
04609 
04610 
04611 /* Add a new symbol S to a block B.  */
04612 
04613 static void
04614 add_symbol (struct symbol *s, struct symtab *symtab, struct block *b)
04615 {
04616   SYMBOL_SYMTAB (s) = symtab;
04617   dict_add_symbol (BLOCK_DICT (b), s);
04618 }
04619 
04620 /* Add a new block B to a symtab S.  */
04621 
04622 static void
04623 add_block (struct block *b, struct symtab *s)
04624 {
04625   struct blockvector *bv = BLOCKVECTOR (s);
04626 
04627   bv = (struct blockvector *) xrealloc ((void *) bv,
04628                                         (sizeof (struct blockvector)
04629                                          + BLOCKVECTOR_NBLOCKS (bv)
04630                                          * sizeof (bv->block)));
04631   if (bv != BLOCKVECTOR (s))
04632     BLOCKVECTOR (s) = bv;
04633 
04634   BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
04635 }
04636 
04637 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
04638    MIPS' linenumber encoding might need more than one byte
04639    to describe it, LAST is used to detect these continuation lines.
04640 
04641    Combining lines with the same line number seems like a bad idea.
04642    E.g: There could be a line number entry with the same line number after the
04643    prologue and GDB should not ignore it (this is a better way to find
04644    a prologue than mips_skip_prologue).
04645    But due to the compressed line table format there are line number entries
04646    for the same line which are needed to bridge the gap to the next
04647    line number entry.  These entries have a bogus address info with them
04648    and we are unable to tell them from intended duplicate line number
04649    entries.
04650    This is another reason why -ggdb debugging format is preferable.  */
04651 
04652 static int
04653 add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last)
04654 {
04655   /* DEC c89 sometimes produces zero linenos which confuse gdb.
04656      Change them to something sensible.  */
04657   if (lineno == 0)
04658     lineno = 1;
04659   if (last == 0)
04660     last = -2;                  /* Make sure we record first line.  */
04661 
04662   if (last == lineno)           /* Skip continuation lines.  */
04663     return lineno;
04664 
04665   lt->item[lt->nitems].line = lineno;
04666   lt->item[lt->nitems++].pc = adr << 2;
04667   return lineno;
04668 }
04669 
04670 /* Sorting and reordering procedures.  */
04671 
04672 /* Blocks with a smaller low bound should come first.  */
04673 
04674 static int
04675 compare_blocks (const void *arg1, const void *arg2)
04676 {
04677   LONGEST addr_diff;
04678   struct block **b1 = (struct block **) arg1;
04679   struct block **b2 = (struct block **) arg2;
04680 
04681   addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
04682   if (addr_diff == 0)
04683     return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
04684   return addr_diff;
04685 }
04686 
04687 /* Sort the blocks of a symtab S.
04688    Reorder the blocks in the blockvector by code-address,
04689    as required by some MI search routines.  */
04690 
04691 static void
04692 sort_blocks (struct symtab *s)
04693 {
04694   struct blockvector *bv = BLOCKVECTOR (s);
04695 
04696   if (BLOCKVECTOR_NBLOCKS (bv) <= FIRST_LOCAL_BLOCK)
04697     {
04698       /* Cosmetic */
04699       if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
04700         BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
04701       if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
04702         BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
04703       return;
04704     }
04705   /*
04706    * This is very unfortunate: normally all functions are compiled in
04707    * the order they are found, but if the file is compiled -O3 things
04708    * are very different.  It would be nice to find a reliable test
04709    * to detect -O3 images in advance.
04710    */
04711   if (BLOCKVECTOR_NBLOCKS (bv) > FIRST_LOCAL_BLOCK + 1)
04712     qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
04713            BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
04714            sizeof (struct block *),
04715            compare_blocks);
04716 
04717   {
04718     CORE_ADDR high = 0;
04719     int i, j = BLOCKVECTOR_NBLOCKS (bv);
04720 
04721     for (i = FIRST_LOCAL_BLOCK; i < j; i++)
04722       if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
04723         high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
04724     BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
04725   }
04726 
04727   BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
04728     BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
04729 
04730   BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
04731     BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
04732   BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
04733     BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
04734 }
04735 
04736 
04737 /* Constructor/restructor/destructor procedures.  */
04738 
04739 /* Allocate a new symtab for NAME.  Needs an estimate of how many
04740    linenumbers MAXLINES we'll put in it.  */
04741 
04742 static struct symtab *
04743 new_symtab (const char *name, int maxlines, struct objfile *objfile)
04744 {
04745   struct symtab *s = allocate_symtab (name, objfile);
04746 
04747   LINETABLE (s) = new_linetable (maxlines);
04748 
04749   /* All symtabs must have at least two blocks.  */
04750   BLOCKVECTOR (s) = new_bvect (2);
04751   BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK)
04752     = new_block (NON_FUNCTION_BLOCK);
04753   BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
04754     = new_block (NON_FUNCTION_BLOCK);
04755   BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
04756     BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
04757 
04758   s->debugformat = "ECOFF";
04759   return (s);
04760 }
04761 
04762 /* Allocate a new partial_symtab NAME.  */
04763 
04764 static struct partial_symtab *
04765 new_psymtab (char *name, struct objfile *objfile)
04766 {
04767   struct partial_symtab *psymtab;
04768 
04769   psymtab = allocate_psymtab (name, objfile);
04770   psymtab->section_offsets = objfile->section_offsets;
04771 
04772   /* Keep a backpointer to the file's symbols.  */
04773 
04774   psymtab->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
04775                                                 sizeof (struct symloc));
04776   memset (psymtab->read_symtab_private, 0, sizeof (struct symloc));
04777   CUR_BFD (psymtab) = cur_bfd;
04778   DEBUG_SWAP (psymtab) = debug_swap;
04779   DEBUG_INFO (psymtab) = debug_info;
04780   PENDING_LIST (psymtab) = pending_list;
04781 
04782   /* The way to turn this into a symtab is to call...  */
04783   psymtab->read_symtab = mdebug_read_symtab;
04784   return (psymtab);
04785 }
04786 
04787 
04788 /* Allocate a linetable array of the given SIZE.  Since the struct
04789    already includes one item, we subtract one when calculating the
04790    proper size to allocate.  */
04791 
04792 static struct linetable *
04793 new_linetable (int size)
04794 {
04795   struct linetable *l;
04796 
04797   if (size > 1)
04798     --size;
04799   size = size * sizeof (l->item) + sizeof (struct linetable);
04800   l = (struct linetable *) xmalloc (size);
04801   l->nitems = 0;
04802   return l;
04803 }
04804 
04805 /* Oops, too big.  Shrink it.  This was important with the 2.4 linetables,
04806    I am not so sure about the 3.4 ones.
04807 
04808    Since the struct linetable already includes one item, we subtract one when
04809    calculating the proper size to allocate.  */
04810 
04811 static struct linetable *
04812 shrink_linetable (struct linetable *lt)
04813 {
04814   return (struct linetable *) xrealloc ((void *) lt,
04815                                         (sizeof (struct linetable)
04816                                          + ((lt->nitems - 1)
04817                                             * sizeof (lt->item))));
04818 }
04819 
04820 /* Allocate and zero a new blockvector of NBLOCKS blocks.  */
04821 
04822 static struct blockvector *
04823 new_bvect (int nblocks)
04824 {
04825   struct blockvector *bv;
04826   int size;
04827 
04828   size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
04829   bv = (struct blockvector *) xzalloc (size);
04830 
04831   BLOCKVECTOR_NBLOCKS (bv) = nblocks;
04832 
04833   return bv;
04834 }
04835 
04836 /* Allocate and zero a new block, and set its BLOCK_DICT.  If function
04837    is non-zero, assume the block is associated to a function, and make
04838    sure that the symbols are stored linearly; otherwise, store them
04839    hashed.  */
04840 
04841 static struct block *
04842 new_block (enum block_type type)
04843 {
04844   /* FIXME: carlton/2003-09-11: This should use allocate_block to
04845      allocate the block.  Which, in turn, suggests that the block
04846      should be allocated on an obstack.  */
04847   struct block *retval = xzalloc (sizeof (struct block));
04848 
04849   if (type == FUNCTION_BLOCK)
04850     BLOCK_DICT (retval) = dict_create_linear_expandable ();
04851   else
04852     BLOCK_DICT (retval) = dict_create_hashed_expandable ();
04853 
04854   return retval;
04855 }
04856 
04857 /* Create a new symbol with printname NAME.  */
04858 
04859 static struct symbol *
04860 new_symbol (char *name)
04861 {
04862   struct symbol *s = allocate_symbol (mdebugread_objfile);
04863 
04864   SYMBOL_SET_LANGUAGE (s, psymtab_language,
04865                        &mdebugread_objfile->objfile_obstack);
04866   SYMBOL_SET_NAMES (s, name, strlen (name), 1, mdebugread_objfile);
04867   return s;
04868 }
04869 
04870 /* Create a new type with printname NAME.  */
04871 
04872 static struct type *
04873 new_type (char *name)
04874 {
04875   struct type *t;
04876 
04877   t = alloc_type (mdebugread_objfile);
04878   TYPE_NAME (t) = name;
04879   INIT_CPLUS_SPECIFIC (t);
04880   return t;
04881 }
04882 
04883 /* Read ECOFF debugging information from a BFD section.  This is
04884    called from elfread.c.  It parses the section into a
04885    ecoff_debug_info struct, and then lets the rest of the file handle
04886    it as normal.  */
04887 
04888 void
04889 elfmdebug_build_psymtabs (struct objfile *objfile,
04890                           const struct ecoff_debug_swap *swap, asection *sec)
04891 {
04892   bfd *abfd = objfile->obfd;
04893   struct ecoff_debug_info *info;
04894   struct cleanup *back_to;
04895 
04896   /* FIXME: It's not clear whether we should be getting minimal symbol
04897      information from .mdebug in an ELF file, or whether we will.
04898      Re-initialize the minimal symbol reader in case we do.  */
04899 
04900   init_minimal_symbol_collection ();
04901   back_to = make_cleanup_discard_minimal_symbols ();
04902 
04903   info = ((struct ecoff_debug_info *)
04904           obstack_alloc (&objfile->objfile_obstack,
04905                          sizeof (struct ecoff_debug_info)));
04906 
04907   if (!(*swap->read_debug_info) (abfd, sec, info))
04908     error (_("Error reading ECOFF debugging information: %s"),
04909            bfd_errmsg (bfd_get_error ()));
04910 
04911   mdebug_build_psymtabs (objfile, swap, info);
04912 
04913   install_minimal_symbols (objfile);
04914   do_cleanups (back_to);
04915 }
04916 
04917 void
04918 _initialize_mdebugread (void)
04919 {
04920   basic_type_data = register_objfile_data ();
04921 
04922   mdebug_register_index
04923     = register_symbol_register_impl (LOC_REGISTER, &mdebug_register_funcs);
04924   mdebug_regparm_index
04925     = register_symbol_register_impl (LOC_REGPARM_ADDR, &mdebug_register_funcs);
04926 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines