Add missed log entry for som.c.
[deliverable/binutils-gdb.git] / gdb / xcoffread.c
index c20a92ee6c887da273a224bb4184ad5b38866446..34acb06fad31049943ee6a91739d80fea3afcb96 100644 (file)
@@ -1,5 +1,5 @@
 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
-   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
             Free Software Foundation, Inc.
    Derived from coffread.c, dbxread.c, and a lot of hacking.
    Contributed by IBM Corporation.
@@ -29,12 +29,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "defs.h"
 #include "bfd.h"
 
-/* AIX XCOFF names have a preceeding dot `.' */
-#define NAMES_HAVE_DOT 1
-
 #include <sys/types.h>
 #include <fcntl.h>
 #include <ctype.h>
+#include <string.h>
 
 #include "obstack.h"
 #include <sys/param.h>
@@ -44,40 +42,31 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <sys/stat.h>
 #include <sys/debug.h>
 
+#include "coff/internal.h"     /* FIXME, internal data from BFD */
+#include "libcoff.h"           /* FIXME, internal data from BFD */
+#include "coff/rs6000.h"       /* FIXME, raw file-format guts of xcoff */
+
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "buildsym.h"
 #include "stabsread.h"
-#include "gdb-stabs.h"
 #include "complaints.h"
 
-#include "coff/internal.h"     /* FIXME, internal data from BFD */
-#include "libcoff.h"           /* FIXME, internal data from BFD */
-#include "coff/rs6000.h"       /* FIXME, raw file-format guts of xcoff */
-
-
-/* Define this if you want gdb use the old xcoff symbol processing. This
-   way it won't use common `define_symbol()' function and Sun dbx stab
-   string grammar. And likely it won't be able to do G++ debugging. */
-
-/* #define     NO_DEFINE_SYMBOL 1 */
-
-/* Define this if you want gdb to ignore typdef stabs. This was needed for
-   one of Transarc, to reduce the size of the symbol table. Types won't be
-   recognized, but tag names will be. */
+#include "gdb-stabs.h"
 
-/* #define     NO_TYPEDEFS  1 */
+/* For interface with stabsread.c.  */
+#include "aout/stab_gnu.h"
 
 /* Simplified internal version of coff symbol table information */
 
 struct coff_symbol {
   char *c_name;
   int c_symnum;                /* symbol number of this entry */
-  int c_nsyms;         /* 0 if syment only, 1 if syment + auxent */
+  int c_naux;          /* 0 if syment only, 1 if syment + auxent */
   long c_value;
-  int c_sclass;
+  unsigned char c_sclass;
   int c_secnum;
   unsigned int c_type;
 };
@@ -182,12 +171,8 @@ xcoff_symfile_init PARAMS ((struct objfile *));
 static void
 xcoff_new_init PARAMS ((struct objfile *));
 
-#ifdef __STDC__
-struct section_offset;
-#endif
-
 static void
-xcoff_symfile_read PARAMS ((struct objfile *, struct section_offset *, int));
+xcoff_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
 
 static void
 xcoff_symfile_finish PARAMS ((struct objfile *));
@@ -198,9 +183,18 @@ xcoff_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
 static int
 init_lineno PARAMS ((bfd *, file_ptr, int));
 
+static void
+free_linetab PARAMS ((void));
+
 static void
 find_linenos PARAMS ((bfd *, sec_ptr, PTR));
 
+static char *
+coff_getfilename PARAMS ((union internal_auxent *));
+
+static void
+read_symbol PARAMS ((struct internal_syment *, int));
+
 static int
 read_symbol_lineno PARAMS ((int));
 
@@ -216,64 +210,51 @@ read_xcoff_symtab PARAMS ((struct objfile *, int));
 static void
 add_stab_to_list PARAMS ((char *, struct pending_stabs **));
 
-static void
-sort_syms PARAMS ((void));
-
-static int
-compare_symbols PARAMS ((const void *, const void *));
-
-/* Call sort_syms to sort alphabetically
-   the symbols of each block of each symtab.  */
-
-static int
-compare_symbols (s1p, s2p)
-     const PTR s1p;
-     const PTR s2p;
-{
-  /* Names that are less should come first.  */
-  register struct symbol **s1 = (struct symbol **) s1p;
-  register struct symbol **s2 = (struct symbol **) s2p;
-  register int namediff = STRCMP (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2));
-  if (namediff != 0) 
-    return namediff;
-
-  /* For symbols of the same name, registers should come first.  */
-  return ((SYMBOL_CLASS (*s2) == LOC_REGISTER)
-      - (SYMBOL_CLASS (*s1) == LOC_REGISTER));
-}
+\f
+#ifdef STATIC_NODEBUG_VARS
+/* Return the section_offsets* that CS points to.  */
+static int cs_to_section PARAMS ((struct coff_symbol *, struct objfile *));
 
+struct find_targ_sec_arg {
+  int targ_index;
+  int *resultp;
+};
 
-/* Sort a vector of symbols by their value. */
+static void find_targ_sec PARAMS ((bfd *, asection *, void *));
 
-static void
-sort_syms ()
+static void find_targ_sec (abfd, sect, obj)
+     bfd *abfd;
+     asection *sect;
+     PTR obj;
 {
-  register struct symtab *s;
-  register struct objfile *objfile;
-  register int i, nbl;
-  register struct blockvector *bv;
-  register struct block *b;
-
-  for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
+  struct find_targ_sec_arg *args = (struct find_targ_sec_arg *)obj;
+  if (sect->target_index == args->targ_index)
     {
-      for (s = objfile -> symtabs; s != NULL; s = s -> next)
-       {
-         bv = BLOCKVECTOR (s);
-         nbl = BLOCKVECTOR_NBLOCKS (bv);
-         for (i = 0; i < nbl; i++)
-           {
-             b = BLOCKVECTOR_BLOCK (bv, i);
-             if (BLOCK_SHOULD_SORT (b))
-               {
-                 qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
-                        sizeof (struct symbol *), compare_symbols);
-               }
-           }
-       }
+      /* This is the section.  Figure out what SECT_OFF_* code it is.  */
+      if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
+       *args->resultp = SECT_OFF_TEXT;
+      else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
+       *args->resultp = SECT_OFF_DATA;
+      else
+       *args->resultp = SECT_OFF_BSS;
     }
 }
 
-
+/* Return the section number (SECT_OFF_*) that CS points to.  */
+static int
+cs_to_section (cs, objfile)
+     struct coff_symbol *cs;
+     struct objfile *objfile;
+{
+  int off = SECT_OFF_TEXT;
+  struct find_targ_sec_arg args;
+  args.targ_index = cs->c_secnum;
+  args.resultp = &off;
+  bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
+  return off;
+}
+#endif /* STATIC_NODEBUG_VARS */
+\f
 /* add a given stab string into given stab vector. */
 
 static void
@@ -296,54 +277,64 @@ struct pending_stabs **stabvector;
   }
   (*stabvector)->stab [(*stabvector)->count++] = stabname;
 }
+\f
+/* Linenos are processed on a file-by-file basis.
+
+   Two reasons:
+
+    1) xlc (IBM's native c compiler) postpones static function code
+       emission to the end of a compilation unit. This way it can
+       determine if those functions (statics) are needed or not, and
+       can do some garbage collection (I think). This makes line
+       numbers and corresponding addresses unordered, and we end up
+       with a line table like:
+       
+
+               lineno  addr
+        foo()    10    0x100
+                 20    0x200
+                 30    0x300
+
+       foo3()    70    0x400
+                 80    0x500
+                 90    0x600
+
+       static foo2()
+                 40    0x700
+                 50    0x800
+                 60    0x900           
+
+       and that breaks gdb's binary search on line numbers, if the
+       above table is not sorted on line numbers. And that sort
+       should be on function based, since gcc can emit line numbers
+       like:
+       
+               10      0x100   - for the init/test part of a for stmt.
+               20      0x200
+               30      0x300
+               10      0x400   - for the increment part of a for stmt.
 
+       arrange_linetable() will do this sorting.               
 
-#if 0
-/* for all the stabs in a given stab vector, build appropriate types 
-   and fix their symbols in given symbol vector. */
-
-void
-patch_block_stabs (symbols, stabs)
-struct pending *symbols;
-struct pending_stabs *stabs;
-{
-  int ii;
-
-  if (!stabs)
-    return;
-
-  /* for all the stab entries, find their corresponding symbols and 
-     patch their types! */
-
-  for (ii=0; ii < stabs->count; ++ii) {
-    char *name = stabs->stab[ii];
-    char *pp = (char*) index (name, ':');
-    struct symbol *sym = find_symbol_in_list (symbols, name, pp-name);
-    if (!sym) {
-      ;
-      /* printf ("ERROR! stab symbol not found!\n"); */        /* FIXME */
-      /* The above is a false alarm. There are cases the we can have
-         a stab, without its symbol. xlc generates this for the extern
-        definitions in inner blocks. */
-    }
-    else {
-      pp += 2;
+     2)        aix symbol table might look like:
 
-      if (*(pp-1) == 'F' || *(pp-1) == 'f')
-       SYMBOL_TYPE (sym) = lookup_function_type (read_type (&pp, objfile));
-      else
-       SYMBOL_TYPE (sym) = read_type (&pp, objfile);
-    }
-  }
-}
-#endif
+               c_file          // beginning of a new file
+               .bi             // beginning of include file
+               .ei             // end of include file
+               .bi
+               .ei
 
+       basically, .bi/.ei pairs do not necessarily encapsulate
+       their scope. They need to be recorded, and processed later
+       on when we come the end of the compilation unit.
+       Include table (inclTable) and process_linenos() handle
+       that.  */
 
 /* compare line table entry addresses. */
 
-  static int
+static int
 compare_lte (lte1, lte2)
-  struct linetable_entry *lte1, *lte2;
+     struct linetable_entry *lte1, *lte2;
 {
   return lte1->pc - lte2->pc;
 }
@@ -351,6 +342,8 @@ compare_lte (lte1, lte2)
 /* Give a line table with function entries are marked, arrange its functions
    in assending order and strip off function entry markers and return it in
    a newly created table. If the old one is good enough, return the old one. */
+/* FIXME: I think all this stuff can be replaced by just passing
+   sort_linevec = 1 to end_symtab.  */
 
 static struct linetable *
 arrange_linetable (oldLineTb)
@@ -458,40 +451,31 @@ static int          inclIndx;                     /* last entry to table */
 static int       inclLength;                   /* table length */
 static int       inclDepth;                    /* nested include depth */
 
+static void allocate_include_entry PARAMS ((void));
 
 static void
 record_include_begin (cs)
 struct coff_symbol *cs;
 {
-  /* In xcoff, we assume include files cannot be nested (not in .c files
-     of course, but in corresponding .s files.) */
-
   if (inclDepth)
-    fatal ("xcoff internal: pending include file exists.");
+    {
+      /* In xcoff, we assume include files cannot be nested (not in .c files
+        of course, but in corresponding .s files.).  */
 
+      /* This can happen with old versions of GCC.
+        GCC 2.3.3-930426 does not exhibit this on a test case which
+        a user said produced the message for him.  */
+      static struct complaint msg = {"Nested C_BINCL symbols", 0, 0};
+      complain (&msg);
+    }
   ++inclDepth;
 
-  /* allocate an include file, or make room for the new entry */
-  if (inclLength == 0) {
-    inclTable = (InclTable*) 
-       xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
-    bzero (inclTable, sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
-    inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
-    inclIndx = 0;
-  }
-  else if (inclIndx >= inclLength) {
-    inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
-    inclTable = (InclTable*) 
-       xrealloc (inclTable, sizeof (InclTable) * inclLength);
-    bzero (inclTable+inclLength-INITIAL_INCLUDE_TABLE_LENGTH, 
-                       sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH);
-  }
+  allocate_include_entry ();
 
   inclTable [inclIndx].name  = cs->c_name;
   inclTable [inclIndx].begin = cs->c_value;
 }
 
-
 static void
 record_include_end (cs)
 struct coff_symbol *cs;
@@ -499,7 +483,12 @@ struct coff_symbol *cs;
   InclTable *pTbl;  
 
   if (inclDepth == 0)
-    fatal ("xcoff internal: Mismatch C_BINCL/C_EINCL pair found.");
+    {
+      static struct complaint msg = {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
+      complain (&msg);
+    }
+
+  allocate_include_entry ();
 
   pTbl = &inclTable [inclIndx];
   pTbl->end = cs->c_value;
@@ -508,9 +497,30 @@ struct coff_symbol *cs;
   ++inclIndx;
 }
 
+static void
+allocate_include_entry ()
+{
+  if (inclTable == NULL)
+    {
+      inclTable = (InclTable *) 
+       xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
+      memset (inclTable,
+             '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
+      inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
+      inclIndx = 0;
+    }
+  else if (inclIndx >= inclLength)
+    {
+      inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
+      inclTable = (InclTable *) 
+       xrealloc (inclTable, sizeof (InclTable) * inclLength);
+      memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH, 
+             '\0', sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH);
+    }
+}
 
-/* given the start and end addresses of a compilation unit (or a csect, at times)
-   process its lines and create appropriate line vectors. */
+/* given the start and end addresses of a compilation unit (or a csect,
+   at times) process its lines and create appropriate line vectors. */
 
 static void
 process_linenos (start, end)
@@ -536,7 +546,7 @@ process_linenos (start, end)
   if (!(offset = first_fun_line_offset))
     goto return_after_cleanup;
 
-  bzero (&main_subfile, sizeof (main_subfile));
+  memset (&main_subfile, '\0', sizeof (main_subfile));
   first_fun_line_offset = 0;
 
   if (inclIndx == 0)
@@ -565,7 +575,7 @@ process_linenos (start, end)
       tmpSubfile = inclTable[ii].subfile = (struct subfile*) 
                                xmalloc (sizeof (struct subfile));
 
-      bzero (tmpSubfile, sizeof (struct subfile));
+      memset (tmpSubfile, '\0', sizeof (struct subfile));
       firstLine = &(inclTable[ii].funStartLine);
 
       /* enter include file's lines now. */
@@ -665,7 +675,7 @@ return_after_cleanup:
   inclIndx = 0;
 
   /* start with a fresh subfile structure for the next file. */
-  bzero (&main_subfile, sizeof (struct subfile));
+  memset (&main_subfile, '\0', sizeof (struct subfile));
 }
 
 void
@@ -716,7 +726,7 @@ enter_line_range (subfile, beginoffset, endoffset, startaddr, endaddr, firstLine
     addr = P_LINENO(pp) ? 
       P_LINEADDR(pp) : read_symbol_nvalue (P_LINESYM(pp)); 
 
-    if (addr < startaddr || (endaddr && addr > endaddr))
+    if (addr < startaddr || (endaddr && addr >= endaddr))
       return;
 
     if (P_LINENO(pp) == 0) {
@@ -763,7 +773,7 @@ retrieve_tracebackinfo (abfd, textsec, cs)
 
   int functionstart = cs->c_value - textsec->vma;
 
-  bzero (&tbInfo, sizeof (tbInfo));
+  memset (&tbInfo, '\0', sizeof (tbInfo));
 
   /* keep reading blocks of data from the text section, until finding a zero
      word and a traceback table. */
@@ -856,7 +866,7 @@ retrieve_tracebackinfo (abfd, textsec, cs)
                abfd, textsec, buffer, 
                (file_ptr)(functionstart + 
                 bytesread - (buffer + bufferbytes - (char*)pinsn)),MIN_TBTABSIZ))
-         { printf ("Abnormal return!..\n"); return NULL; }
+         { printf_unfiltered ("Abnormal return!..\n"); return NULL; }
 
        ptb = (struct tbtable *)buffer;
       }
@@ -938,7 +948,7 @@ retrieve_traceback (abfd, textsec, cs, size)
                abfd, textsec, buffer, 
                (file_ptr)(functionstart + 
                 bytesread - (buffer + bufferbytes - pinsn)),MIN_TBTABSIZ))
-       /*   abort (); */ { printf ("abort!!!\n"); return NULL; }
+       /*   abort (); */ { printf_unfiltered ("abort!!!\n"); return NULL; }
 
        return (struct tbtable *)buffer;
       }
@@ -972,17 +982,18 @@ retrieve_traceback (abfd, textsec, cs, size)
 /* Reading symbol table has to be fast! Keep the followings as macros, rather
    than functions. */
 
-#define        RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED)        \
+#define        RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED, SECTION, OBJFILE) \
 {                                              \
   char *namestr;                               \
-  if (ALLOCED)                                         \
-    namestr = (NAME) + 1;                      \
-  else {                                       \
+  namestr = (NAME); \
+  if (namestr[0] == '.') ++namestr; \
+  if (!(ALLOCED)) {                            \
     (NAME) = namestr =                                 \
-    obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
+    obstack_copy0 (&objfile->symbol_obstack, namestr, strlen (namestr)); \
     (ALLOCED) = 1;                                             \
   }                                                            \
-  prim_record_minimal_symbol (namestr, (ADDR), (TYPE));                \
+  prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
+                                      (char *)NULL, (SECTION), (OBJFILE)); \
   misc_func_recorded = 1;                                      \
 }
 
@@ -1012,10 +1023,54 @@ static struct symbol parmsym;
    
 static int static_block_base = 0;
 
+/* Section number for the current static block.  */
+
+static int static_block_section = -1;
+
 /* true if space for symbol name has been allocated. */
 
 static int symname_alloced = 0;
 
+/* Next symbol to read.  Pointer into raw seething symbol table.  */
+
+static char *raw_symbol;
+
+/* This is the function which stabsread.c calls to get symbol
+   continuations.  */
+static char *
+xcoff_next_symbol_text ()
+{
+  struct internal_syment symbol;
+  static struct complaint msg =
+    {"Unexpected symbol continuation", 0, 0};
+  char *retval;
+
+  bfd_coff_swap_sym_in (current_objfile->obfd, raw_symbol, &symbol);
+  if (symbol.n_zeroes)
+    {
+      complain (&msg);
+
+      /* Return something which points to '\0' and hope the symbol reading
+        code does something reasonable.  */
+      retval = "";
+    }
+  else if (symbol.n_sclass & 0x80)
+    {
+      retval = debugsec + symbol.n_offset;
+      raw_symbol += coff_data (current_objfile->obfd)->local_symesz;
+      ++symnum;
+    }
+  else
+    {
+      complain (&msg);
+
+      /* Return something which points to '\0' and hope the symbol reading
+        code does something reasonable.  */
+      retval = "";
+    }
+  return retval;
+}
+
 /* read the whole symbol table of a given bfd. */
 
 static void
@@ -1024,13 +1079,12 @@ read_xcoff_symtab (objfile, nsyms)
      int nsyms;                        /* # of symbols */
 {
   bfd *abfd = objfile->obfd;
-  char *raw_symbol;            /* Pointer into raw seething symbol table */
   char *raw_auxptr;            /* Pointer to first raw aux entry for sym */
   sec_ptr  textsec;            /* Pointer to text section */
   TracebackInfo *ptb;          /* Pointer to traceback table */
 
   struct internal_syment symbol[1];
-  union internal_auxent main_aux[1];
+  union internal_auxent main_aux;
   struct coff_symbol cs[1];
   CORE_ADDR file_start_addr = 0;
   CORE_ADDR file_end_addr = 0;
@@ -1056,11 +1110,13 @@ read_xcoff_symtab (objfile, nsyms)
 
   char *last_csect_name;               /* last seen csect's name and value */
   CORE_ADDR last_csect_val;
+  int last_csect_sec;
   int  misc_func_recorded;             /* true if any misc. function */
 
   current_objfile = objfile;
 
-  /* Get the appropriate COFF "constants" related to the file we're handling. */
+  /* Get the appropriate COFF "constants" related to the file we're
+     handling. */
   N_TMASK = coff_data (abfd)->local_n_tmask;
   N_BTSHFT = coff_data (abfd)->local_n_btshft;
   local_symesz = coff_data (abfd)->local_symesz;
@@ -1090,536 +1146,588 @@ read_xcoff_symtab (objfile, nsyms)
   raw_symbol = symtbl;
 
   textsec = bfd_get_section_by_name (abfd, ".text");
-  if (!textsec) {
-    printf ("Unable to locate text section!\n");
-  }
-
-  while (symnum < nsyms) {
-
-    QUIT;                      /* make this command interruptable.  */
-
-    /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
-    /* read one symbol into `cs' structure. After processing the whole symbol
-       table, only string table will be kept in memory, symbol table and debug
-       section of xcoff will be freed. Thus we can mark symbols with names
-       in string table as `alloced'. */
+  if (!textsec)
     {
-      int ii;
-
-      /* Swap and align the symbol into a reasonable C structure.  */
-      bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
-
-      cs->c_symnum = symnum;
-      cs->c_nsyms = symbol->n_numaux;
-      if (symbol->n_zeroes) {
-       symname_alloced = 0;
-       /* We must use the original, unswapped, name here so the name field
-          pointed to by cs->c_name will persist throughout xcoffread.  If
-          we use the new field, it gets overwritten for each symbol.  */
-       cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name;
-      } else if (symbol->n_sclass & 0x80) {
-       cs->c_name = debugsec + symbol->n_offset;
-       symname_alloced = 0;
-      } else { /* in string table */
-       cs->c_name = strtbl + (int)symbol->n_offset;
-       symname_alloced = 1;
-      }
-      cs->c_value = symbol->n_value;
-      /* n_sclass is signed (FIXME), so we had better not mask off any
-        high bits it contains, since the values we will be comparing
-        it to are also signed (FIXME).  Defined in <coff/internal.h>.
-        At this point (3Jun92, gnu@cygnus.com) I think the fix is to
-        make the fields and values unsigned chars, but changing the next
-        line is a simple patch late in the release cycle, for now.  */
-      cs->c_sclass = symbol->n_sclass /* & 0xff */;
-      cs->c_secnum = symbol->n_scnum;
-      cs->c_type = (unsigned)symbol->n_type;
-
-      raw_symbol += coff_data (abfd)->local_symesz;
-      ++symnum;
-
-      raw_auxptr = raw_symbol;         /* Save addr of first aux entry */
-
-      /* Skip all the auxents associated with this symbol.  */
-      for (ii = symbol->n_numaux; ii; --ii ) {
-        raw_symbol += coff_data (abfd)->local_auxesz;
-       ++symnum;
-      }
-    }
-
-    /* if symbol name starts with ".$" or "$", ignore it. */
-    if (cs->c_name[0] == '$' || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
-      continue;
-
-    if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE) {
-      if (last_source_file)
-       {
-         end_symtab (cur_src_end_addr, 1, 0, objfile);
-         end_stabs ();
-       }
-
-      start_stabs ();
-      start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0);
-      cur_src_end_addr = first_object_file_end;
-      /* done with all files, everything from here on is globals */
+      printf_unfiltered ("Unable to locate text section!\n");
     }
 
-    /* if explicitly specified as a function, treat is as one. */
-    if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF) {
-      bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
-                           main_aux);
-      goto function_entry_point;
-    }
+  next_symbol_text_func = xcoff_next_symbol_text;
 
-    if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT) && cs->c_nsyms == 1)
+  while (symnum < nsyms)
     {
-       /* dealing with a symbol with a csect entry. */
 
-#   define     CSECT(PP)       ((PP)->x_csect)
-#   define     CSECT_LEN(PP)   (CSECT(PP).x_scnlen)
-#   define     CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
-#   define     CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
-#   define     CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
+      QUIT;                    /* make this command interruptable.  */
 
-       /* Convert the auxent to something we can access.  */
-        bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
-                             main_aux);
-
-       switch (CSECT_SMTYP (main_aux)) {
+      /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
+      /* read one symbol into `cs' structure. After processing the
+        whole symbol table, only string table will be kept in memory,
+        symbol table and debug section of xcoff will be freed. Thus
+        we can mark symbols with names in string table as
+        `alloced'. */
+      {
+       int ii;
 
-       case XTY_ER :
-         continue;                     /* ignore all external references. */
+       /* Swap and align the symbol into a reasonable C structure.  */
+       bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
 
-       case XTY_SD :                   /* a section description. */
+       cs->c_symnum = symnum;
+       cs->c_naux = symbol->n_numaux;
+       if (symbol->n_zeroes)
          {
-           switch (CSECT_SCLAS (main_aux)) {
-
-           case XMC_PR :                       /* a `.text' csect.     */
+           symname_alloced = 0;
+           /* We must use the original, unswapped, name here so the name field
+              pointed to by cs->c_name will persist throughout xcoffread.  If
+              we use the new field, it gets overwritten for each symbol.  */
+           cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name;
+           /* If it's exactly E_SYMNMLEN characters long it isn't
+              '\0'-terminated.  */
+           if (cs->c_name[E_SYMNMLEN - 1] != '\0')
              {
-
-               /* A program csect is seen.
-                
-                  We have to allocate one symbol table for each program csect. Normally
-                  gdb prefers one symtab for each compilation unit (CU). In case of AIX, one
-                  CU might include more than one prog csect, and they don't have to be
-                  adjacent in terms of the space they occupy in memory. Thus, one single
-                  CU might get fragmented in the memory and gdb's file start and end address
-                  approach does not work!  */
-
-               if (last_csect_name) {
-
-                 /* if no misc. function recorded in the last seen csect, enter
-                    it as a function. This will take care of functions like
-                    strcmp() compiled by xlc. */
-
-                 if (!misc_func_recorded) {
-                    int alloced = 0;
-                    RECORD_MINIMAL_SYMBOL (last_csect_name, last_csect_val,
-                                           mst_text, alloced);
-                 }
-                   
-
-                 complete_symtab (filestring, file_start_addr);
-                 cur_src_end_addr = file_end_addr;
-                 end_symtab (file_end_addr, 1, 0, objfile);
-                 end_stabs ();
-                 start_stabs ();
-                 start_symtab ((char *)NULL, (char *)NULL, (CORE_ADDR)0);
-               }
-
-               /* If this is the very first csect seen, basically `__start'. */
-               if (just_started) {
-                 first_object_file_end = cs->c_value + CSECT_LEN (main_aux);
-                 just_started = 0;
-               }
-
-               file_start_addr = cs->c_value;
-               file_end_addr = cs->c_value + CSECT_LEN (main_aux);
-
-               if (cs->c_name && cs->c_name[0] == '.') {
-                 last_csect_name = cs->c_name;
-                 last_csect_val = cs->c_value;
-               }
+               char *p;
+               p = obstack_alloc (&objfile->symbol_obstack, E_SYMNMLEN + 1);
+               strncpy (p, cs->c_name, E_SYMNMLEN);
+               p[E_SYMNMLEN] = '\0';
+               cs->c_name = p;
+               symname_alloced = 1;
              }
-             misc_func_recorded = 0;
-             continue;
-
-           case XMC_RW :
-             break;
-
-             /* If the section is not a data description, ignore it. Note that
-                uninitialized data will show up as XTY_CM/XMC_RW pair. */
-
-           case XMC_TC0:
-             if (toc_offset)
-               warning ("More than one xmc_tc0 symbol found.");
-             toc_offset = cs->c_value;
-             continue;
-
-           case XMC_TC :               /* ignore toc entries   */
-           default     :               /* any other XMC_XXX    */
-             continue;
-           }
          }
-         break;                        /* switch CSECT_SCLAS() */
+       else if (symbol->n_sclass & 0x80)
+         {
+           cs->c_name = debugsec + symbol->n_offset;
+           symname_alloced = 0;
+         }
+       else
+         {
+           /* in string table */
+           cs->c_name = strtbl + (int)symbol->n_offset;
+           symname_alloced = 1;
+         }
+       cs->c_value = symbol->n_value;
+       cs->c_sclass = symbol->n_sclass;
+       cs->c_secnum = symbol->n_scnum;
+       cs->c_type = (unsigned)symbol->n_type;
 
-       case XTY_LD :
-         
-         /* a function entry point. */
-         if (CSECT_SCLAS (main_aux) == XMC_PR) {
+       raw_symbol += coff_data (abfd)->local_symesz;
+       ++symnum;
 
-function_entry_point:
-           RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text, 
-                                  symname_alloced);
+       /* Save addr of first aux entry.  */
+       raw_auxptr = raw_symbol;
 
-           fcn_line_offset = main_aux->x_sym.x_fcnary.x_fcn.x_lnnoptr;
-           fcn_start_addr = cs->c_value;
+       /* Skip all the auxents associated with this symbol.  */
+       for (ii = symbol->n_numaux; ii; --ii)
+         {
+           raw_symbol += coff_data (abfd)->local_auxesz;
+           ++symnum;
+         }
+      }
 
-           /* save the function header info, which will be used
-              when `.bf' is seen. */
-           fcn_cs_saved = *cs;
-           fcn_aux_saved = *main_aux;
+      /* if symbol name starts with ".$" or "$", ignore it. */
+      if (cs->c_name[0] == '$'
+         || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
+       continue;
 
+      if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
+       {
+         if (last_source_file)
+           {
+             end_symtab (cur_src_end_addr, 1, 0, objfile,
+                         textsec->target_index);
+             end_stabs ();
+           }
 
-           ptb = NULL;
+         start_stabs ();
+         start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0);
+         cur_src_end_addr = first_object_file_end;
+         /* done with all files, everything from here on is globals */
+       }
 
-           /* If function has two auxent, then debugging information is
-              already available for it. Process traceback table for
-              functions with only one auxent. */
+      /* if explicitly specified as a function, treat is as one. */
+      if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF)
+       {
+         bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
+                               0, cs->c_naux, &main_aux);
+         goto function_entry_point;
+       }
 
-           if (cs->c_nsyms == 1)
-             ptb = retrieve_tracebackinfo (abfd, textsec, cs);
+      if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
+         && cs->c_naux == 1)
+       {
+         /* Dealing with a symbol with a csect entry.  */
 
-           else if (cs->c_nsyms != 2)
-             abort ();
+#define        CSECT(PP) ((PP)->x_csect)
+#define        CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
+#define        CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
+#define        CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
+#define        CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
 
-           /* If there is traceback info, create and add parameters for it. */
+         /* Convert the auxent to something we can access.  */
+         bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
+                               0, cs->c_naux, &main_aux);
 
-           if (ptb && (ptb->fixedparms || ptb->floatparms)) {
+         switch (CSECT_SMTYP (&main_aux))
+           {
 
-             int parmcnt = ptb->fixedparms + ptb->floatparms;
-             char *parmcode = (char*) &ptb->parminfo;
-             int parmvalue = ptb->framesize + 0x18;    /* sizeof(LINK AREA) == 0x18 */
-             unsigned int ii, mask;
+           case XTY_ER:
+             /* Ignore all external references.  */
+             continue;
 
-             for (ii=0, mask = 0x80000000; ii <parmcnt; ++ii) {
-               struct symbol *parm;
+           case XTY_SD:
+             /* A section description.  */
+             {
+               switch (CSECT_SCLAS (&main_aux))
+                 {
+
+                 case XMC_PR:
+                   {
+
+                     /* A program csect is seen.  We have to allocate one
+                        symbol table for each program csect.  Normally gdb
+                        prefers one symtab for each source file.  In case
+                        of AIX, one source file might include more than one
+                        [PR] csect, and they don't have to be adjacent in
+                        terms of the space they occupy in memory. Thus, one
+                        single source file might get fragmented in the
+                        memory and gdb's file start and end address
+                        approach does not work!  GCC (and I think xlc) seem
+                        to put all the code in the unnamed program csect.  */
+
+                     if (last_csect_name)
+                       {
+
+                         /* If no misc. function recorded in the last
+                            seen csect, enter it as a function. This
+                            will take care of functions like strcmp()
+                            compiled by xlc.  */
+
+                         if (!misc_func_recorded)
+                           {
+                             int alloced = 0;
+                             RECORD_MINIMAL_SYMBOL
+                               (last_csect_name, last_csect_val,
+                                mst_text, alloced, last_csect_sec,
+                                objfile);
+                           }
+
+                         complete_symtab (filestring, file_start_addr);
+                         cur_src_end_addr = file_end_addr;
+                         end_symtab (file_end_addr, 1, 0, objfile,
+                                     textsec->target_index);
+                         end_stabs ();
+                         start_stabs ();
+                         /* Give all csects for this source file the same
+                            name.  */
+                         start_symtab (filestring, NULL, (CORE_ADDR)0);
+                       }
+
+                     /* If this is the very first csect seen,
+                        basically `__start'. */
+                     if (just_started)
+                       {
+                         first_object_file_end
+                           = cs->c_value + CSECT_LEN (&main_aux);
+                         just_started = 0;
+                       }
+
+                     file_start_addr = cs->c_value;
+                     file_end_addr = cs->c_value + CSECT_LEN (&main_aux);
+
+                     if (cs->c_name && cs->c_name[0] == '.')
+                       {
+                         last_csect_name = cs->c_name;
+                         last_csect_val = cs->c_value;
+                         last_csect_sec = cs->c_secnum;
+                       }
+                   }
+                   misc_func_recorded = 0;
+                   continue;
+
+                 case XMC_RW :
+                   break;
+
+                   /* If the section is not a data description,
+                      ignore it. Note that uninitialized data will
+                      show up as XTY_CM/XMC_RW pair. */
+
+                 case XMC_TC0:
+                   if (toc_offset)
+                     warning ("More than one xmc_tc0 symbol found.");
+                   toc_offset = cs->c_value;
+                   continue;
+
+                 case XMC_TC:
+#ifdef STATIC_NODEBUG_VARS
+                   /* We need to process these symbols if they are C_HIDEXT,
+                      for static variables in files compiled without -g.  */
+                   if (cs->c_sclass == C_HIDEXT)
+                     break;
+                   else
+#endif
+                     continue;
 
-               if (ptb->parminfo & mask) {             /* float or double */
-                 mask = mask >> 1;
-                 if (ptb->parminfo & mask) {           /* double parm */
-                   ADD_PARM_TO_PENDING
-                       (parm, parmvalue, builtin_type_double, local_symbols);
-                   parmvalue += sizeof (double);
-                 }
-                 else {                                /* float parm */
-                   ADD_PARM_TO_PENDING
-                       (parm, parmvalue, builtin_type_float, local_symbols);
-                   parmvalue += sizeof (float);
+                 default:
+                   /* Ignore the symbol.  */
+                   continue;
                  }
-               }
-               else {          /* fixed parm, use (int*) for hex rep. */
-                 ADD_PARM_TO_PENDING (parm, parmvalue,
-                                      lookup_pointer_type (builtin_type_int),
-                                      local_symbols);
-                 parmvalue += sizeof (int);
-               }
-               mask = mask >> 1;
              }
+             break;
+
+           case XTY_LD:
+
+             switch (CSECT_SCLAS (&main_aux))
+               {
+               case XMC_PR:
+                 /* a function entry point. */
+               function_entry_point:
+                 RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text, 
+                                        symname_alloced, cs->c_secnum,
+                                        objfile);
+
+                 fcn_line_offset = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
+                 fcn_start_addr = cs->c_value;
+
+                 /* save the function header info, which will be used
+                    when `.bf' is seen. */
+                 fcn_cs_saved = *cs;
+                 fcn_aux_saved = main_aux;
+
+                 ptb = NULL;
+
+                 /* If function has two auxent, then debugging information is
+                    already available for it. Process traceback table for
+                    functions with only one auxent. */
+
+                 if (cs->c_naux == 1)
+                   ptb = retrieve_tracebackinfo (abfd, textsec, cs);
+
+                 else if (cs->c_naux != 2)
+                   {
+                     static struct complaint msg =
+                       {"Expected one or two auxents for function", 0, 0};
+                     complain (&msg);
+                   }
+
+                 /* If there is traceback info, create and add parameters
+                    for it. */
+
+                 if (ptb && (ptb->fixedparms || ptb->floatparms))
+                   {
+
+                     int parmcnt = ptb->fixedparms + ptb->floatparms;
+                     char *parmcode = (char*) &ptb->parminfo;
+
+                     /* The link area is 0x18 bytes.  */
+                     int parmvalue = ptb->framesize + 0x18;
+                     unsigned int ii, mask;
+
+                     for (ii=0, mask = 0x80000000; ii <parmcnt; ++ii)
+                       {
+                         struct symbol *parm;
+
+                         if (ptb->parminfo & mask)
+                           {
+                             /* float or double */
+                             mask = mask >> 1;
+                             if (ptb->parminfo & mask)
+                               {
+                                 /* double parm */
+                                 ADD_PARM_TO_PENDING
+                                   (parm, parmvalue, builtin_type_double,
+                                    local_symbols);
+                                 parmvalue += sizeof (double);
+                               }
+                             else
+                               {
+                                 /* float parm */
+                                 ADD_PARM_TO_PENDING
+                                   (parm, parmvalue, builtin_type_float,
+                                    local_symbols);
+                                 parmvalue += sizeof (float);
+                               }
+                           }
+                         else
+                           {
+                             /* fixed parm, use (int*) for hex rep. */
+                             ADD_PARM_TO_PENDING
+                               (parm, parmvalue,
+                                lookup_pointer_type (builtin_type_int),
+                                local_symbols);
+                             parmvalue += sizeof (int);
+                           }
+                         mask = mask >> 1;
+                       }
                
-             /* Fake this as a function. Needed in process_xcoff_symbol() */
-             cs->c_type = 32;          
-                                          
-             finish_block(process_xcoff_symbol (cs, objfile), &local_symbols, 
-                          pending_blocks, cs->c_value,
-                          cs->c_value + ptb->fsize, objfile);
+                     /* Fake this as a function.  Needed in
+                         process_xcoff_symbol().  */
+                     cs->c_type = 32;
+
+                     finish_block
+                       (process_xcoff_symbol (cs, objfile), &local_symbols, 
+                        pending_blocks, cs->c_value,
+                        cs->c_value + ptb->fsize, objfile);
+                   }
+                 continue;
+
+               case XMC_GL:
+                 /* shared library function trampoline code entry point. */
+
+                 /* record trampoline code entries as
+                    mst_solib_trampoline symbol.  When we lookup mst
+                    symbols, we will choose mst_text over
+                    mst_solib_trampoline. */
+                 RECORD_MINIMAL_SYMBOL
+                   (cs->c_name, cs->c_value,
+                    mst_solib_trampoline,
+                    symname_alloced, cs->c_secnum, objfile);
+                 continue;
+
+               case XMC_DS:
+                 /* The symbols often have the same names as debug symbols for
+                    functions, and confuse lookup_symbol.  */
+                 continue;
+
+               default:
+                 /* xlc puts each variable in a separate csect, so we get
+                    an XTY_SD for each variable.  But gcc puts several
+                    variables in a csect, so that each variable only gets
+                    an XTY_LD.  We still need to record them.  This will
+                    typically be XMC_RW; I suspect XMC_RO and XMC_BS might
+                    be possible too.  */
+                 break;
+               }
+
+           default:
+             break;
            }
-           continue;
-         }
-         /* shared library function trampoline code entry point. */
-         else if (CSECT_SCLAS (main_aux) == XMC_GL) {
+       }
 
-           /* record trampoline code entries as mst_unknown symbol. When we
-              lookup mst symbols, we will choose mst_text over mst_unknown. */
+      switch (cs->c_sclass)
+       {
 
-#if 1
-           /* After the implementation of incremental loading of shared
-              libraries, we don't want to access trampoline entries. This
-              approach has a consequence of the necessity to bring the whole 
-              shared library at first, in order do anything with it (putting
-              breakpoints, using malloc, etc). On the other side, this is
-              consistient with gdb's behaviour on a SUN platform. */
+       case C_FILE:
 
-           /* Trying to prefer *real* function entry over its trampoline,
-              by assigning `mst_unknown' type to trampoline entries fails.
-              Gdb treats those entries as chars. FIXME. */
+         /* see if the last csect needs to be recorded. */
 
-           /* Recording this entry is necessary. Single stepping relies on
-              this vector to get an idea about function address boundaries. */
+         if (last_csect_name && !misc_func_recorded)
+           {
 
-           prim_record_minimal_symbol ("<trampoline>", cs->c_value,
-                                       mst_unknown);
-#else
+             /* If no misc. function recorded in the last seen csect, enter
+                it as a function.  This will take care of functions like
+                strcmp() compiled by xlc.  */
 
-           /* record trampoline code entries as mst_unknown symbol. When we
-              lookup mst symbols, we will choose mst_text over mst_unknown. */
+             int alloced = 0;
+             RECORD_MINIMAL_SYMBOL
+               (last_csect_name, last_csect_val,
+                mst_text, alloced, last_csect_sec, objfile);
+           }
 
-           RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_unknown,
-                                  symname_alloced);
-#endif
-           continue;
-         }
-         break;
+         /* c_value field contains symnum of next .file entry in table
+            or symnum of first global after last .file. */
 
-       default :               /* all other XTY_XXXs */
-         break;
-       }                       /* switch CSECT_SMTYP() */    }
+         next_file_symnum = cs->c_value;
 
-    switch (cs->c_sclass) {
+         /* Complete symbol table for last object file containing
+            debugging information. */
 
-    case C_FILE:
+         /* Whether or not there was a csect in the previous file, we
+            have to call `end_stabs' and `start_stabs' to reset
+            type_vector, line_vector, etc. structures.  */
 
-      /* see if the last csect needs to be recorded. */
+         complete_symtab (filestring, file_start_addr);
+         cur_src_end_addr = file_end_addr;
+         end_symtab (file_end_addr, 1, 0, objfile, textsec->target_index);
+         end_stabs ();
 
-      if (last_csect_name && !misc_func_recorded) {
+         /* XCOFF, according to the AIX 3.2 documentation, puts the filename
+            in cs->c_name.  But xlc 1.3.0.2 has decided to do things the
+            standard COFF way and put it in the auxent.  We use the auxent if
+            the symbol is ".file" and an auxent exists, otherwise use the symbol
+            itself.  Simple enough.  */
+         if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
+           {
+             bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
+                                   0, cs->c_naux, &main_aux);
+             filestring = coff_getfilename (&main_aux);
+           }
+         else
+           filestring = cs->c_name;
 
-         /* if no misc. function recorded in the last seen csect, enter
-            it as a function. This will take care of functions like
-            strcmp() compiled by xlc. */
+         start_stabs ();
+         start_symtab (filestring, (char *)NULL, (CORE_ADDR)0);
+         last_csect_name = 0;
 
-         int alloced = 0;
-         RECORD_MINIMAL_SYMBOL (last_csect_name, last_csect_val,
-                               mst_text, alloced);
-      }
+         /* reset file start and end addresses. A compilation unit with no text
+            (only data) should have zero file boundaries. */
+         file_start_addr = file_end_addr = 0;
+         break;
 
-      /* c_value field contains symnum of next .file entry in table
-        or symnum of first global after last .file. */
+       case C_FUN:
+         fcn_stab_saved = *cs;
+         break;
 
-      next_file_symnum = cs->c_value;
+       case C_FCN:
+         if (STREQ (cs->c_name, ".bf"))
+           {
 
-      /* complete symbol table for last object file containing
-        debugging information. */
+             bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
+                                   0, cs->c_naux, &main_aux);
 
-      /* Whether or not there was a csect in the previous file, we have to call
-        `end_stabs' and `start_stabs' to reset type_vector, 
-        line_vector, etc. structures. */
+             within_function = 1;
 
-      complete_symtab (filestring, file_start_addr);
-      cur_src_end_addr = file_end_addr;
-      end_symtab (file_end_addr, 1, 0, objfile);
-      end_stabs ();
-      start_stabs ();
-      start_symtab (cs->c_name, (char *)NULL, (CORE_ADDR)0);
-      last_csect_name = 0;
+             mark_first_line (fcn_line_offset, cs->c_symnum);
 
-      /* reset file start and end addresses. A compilation unit with no text
-         (only data) should have zero file boundaries. */
-      file_start_addr = file_end_addr = 0;
+             new = push_context (0, fcn_start_addr);
 
-      filestring = cs->c_name;
-      break;
+             new->name = define_symbol 
+               (fcn_cs_saved.c_value, fcn_stab_saved.c_name, 0, 0, objfile);
+             if (new->name != NULL)
+               SYMBOL_SECTION (new->name) = cs->c_secnum;
+           }
+         else if (STREQ (cs->c_name, ".ef"))
+           {
 
+             bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
+                                   0, cs->c_naux, &main_aux);
+
+             /* The value of .ef is the address of epilogue code;
+                not useful for gdb.  */
+             /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
+                contains number of lines to '}' */
+
+             fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
+             new = pop_context ();
+             if (context_stack_depth != 0)
+               error ("\
+  invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
+                      symnum);
+
+             finish_block (new->name, &local_symbols, new->old_blocks,
+                           new->start_addr,
+                           fcn_cs_saved.c_value +
+                           fcn_aux_saved.x_sym.x_misc.x_fsize, objfile);
+             within_function = 0;
+           }
+         break;
 
-    case C_FUN:
+       case C_BSTAT:
+         /* Begin static block.  */
+         {
+           struct internal_syment symbol;
 
-#ifdef NO_DEFINE_SYMBOL
-      /* For a function stab, just save its type in `fcn_type_saved', and leave
-        it for the `.bf' processing. */
-      {
-       char *pp = (char*) index (cs->c_name, ':');
+           read_symbol (&symbol, cs->c_value);
+           static_block_base = symbol.n_value;
+           static_block_section = symbol.n_scnum;
+         }
+         break;
 
-       if (!pp || ( *(pp+1) != 'F' && *(pp+1) != 'f'))
-         fatal ("Unrecognized stab");
-       pp += 2;
+       case C_ESTAT:
+         /* End of static block.  */
+         static_block_base = 0;
+         static_block_section = -1;
+         break;
 
-       if (fcn_type_saved)
-         fatal ("Unprocessed function type");
+       case C_ARG:
+       case C_REGPARM:
+       case C_TPDEF:
+       case C_STRTAG:
+       case C_UNTAG:
+       case C_ENTAG:
+         printf_unfiltered
+           ("ERROR: Unimplemented storage class: %d.\n", cs->c_sclass);
+         break;
 
-       fcn_type_saved = lookup_function_type (read_type (&pp, objfile));
-      }
-#else
-      fcn_stab_saved = *cs;
-#endif
-      break;
-    
+       case C_LABEL:
+       case C_NULL:
+         /* Ignore these.  */
+         break;
 
-    case C_FCN:
-      if (STREQ (cs->c_name, ".bf")) {
+         /* This is wrong.  These symbols are XMC_TC, which means that
+            the value of the symbol is the address of the TOC entry, not
+            the address of the variable itself.  */
+       case C_HIDEXT:
+#ifdef STATIC_NODEBUG_VARS
+         {
+           /* This is the only place that static variables show up in files
+              compiled without -g.  External variables also have a C_EXT,
+              so that is why we record everything as mst_file_* here.  */
+           enum minimal_symbol_type ms_type;
+           CORE_ADDR tmpaddr;
+           int sec;
 
-        bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
-                             main_aux);
+           sec = cs_to_section (cs, objfile);
+           tmpaddr = cs->c_value;
 
-       within_function = 1;
+           switch (sec)
+             {
+             case SECT_OFF_TEXT:
+             case SECT_OFF_RODATA:
+               ms_type = mst_file_text;
+               break;
+             case SECT_OFF_DATA:
+               ms_type = mst_file_data;
+               break;
+             case SECT_OFF_BSS:
+               ms_type = mst_file_bss;
+               break;
+             default:
+               ms_type = mst_unknown;
+               break;
+             }
+           RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, ms_type,
+                                  symname_alloced, cs->c_secnum, objfile);
+         }
+#endif /* STATIC_NODEBUG_VARS */
+         break;
 
-       /* Linenos are now processed on a file-by-file, not fn-by-fn, basis.
-          Metin did it, I'm not sure why.  FIXME.  -- gnu@cygnus.com */
+       case C_BINCL:
+         /* beginning of include file */
+         /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
+            order. Thus, when wee see them, we might not know enough info
+            to process them. Thus, we'll be saving them into a table 
+            (inclTable) and postpone their processing. */
 
-       /* Two reasons:
-       
-           1) xlc (IBM's native c compiler) postpones static function code
-              emission to the end of a compilation unit. This way it can
-              determine if those functions (statics) are needed or not, and
-              can do some garbage collection (I think). This makes line
-              numbers and corresponding addresses unordered, and we end up
-              with a line table like:
-              
-
-                       lineno  addr
-               foo()     10    0x100
-                         20    0x200
-                         30    0x300
-
-               foo3()    70    0x400
-                         80    0x500
-                         90    0x600
-
-               static foo2()
-                         40    0x700
-                         50    0x800
-                         60    0x900           
-
-               and that breaks gdb's binary search on line numbers, if the
-               above table is not sorted on line numbers. And that sort
-               should be on function based, since gcc can emit line numbers
-               like:
-               
-                       10      0x100   - for the init/test part of a for stmt.
-                       20      0x200
-                       30      0x300
-                       10      0x400   - for the increment part of a for stmt.
+         record_include_begin (cs);
+         break;
 
-               arrange_linenos() will do this sorting.         
+       case C_EINCL:
+         /* End of include file.  */
+         /* See the comment after case C_BINCL.  */
+         record_include_end (cs);
+         break;
 
+       case C_BLOCK:
+         if (STREQ (cs->c_name, ".bb"))
+           {
+             depth++;
+             new = push_context (depth, cs->c_value);
+           }
+         else if (STREQ (cs->c_name, ".eb"))
+           {
+             new = pop_context ();
+             if (depth != new->depth)
+               error ("\
+  Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
+                      symnum);
+
+             depth--;
+             if (local_symbols && context_stack_depth > 0)
+               {
+                 /* Make a block for the local symbols within.  */
+                 finish_block (new->name, &local_symbols, new->old_blocks,
+                               new->start_addr, cs->c_value, objfile);
+               }
+             local_symbols = new->locals;
+           }
+         break;
 
-            2) aix symbol table might look like:
-       
-                       c_file          // beginning of a new file
-                       .bi             // beginning of include file
-                       .ei             // end of include file
-                       .bi
-                       .ei
-
-               basically, .bi/.ei pairs do not necessarily encapsulate
-               their scope. They need to be recorded, and processed later
-               on when we come the end of the compilation unit.
-               Include table (inclTable) and process_linenos() handle
-               that.
-       */
-       mark_first_line (fcn_line_offset, cs->c_symnum);
-
-       new = push_context (0, fcn_start_addr);
-
-#ifdef NO_DEFINE_SYMBOL
-       new->name = process_xcoff_symbol (&fcn_cs_saved, objfile);
-
-       /* Between a function symbol and `.bf', there always will be a function
-          stab. We save function type when processing that stab. */
-
-       if (fcn_type_saved == NULL) {
-         printf ("Unknown function type: symbol 0x%x\n", cs->c_symnum);
-         SYMBOL_TYPE (new->name) = lookup_function_type (builtin_type_int);
-       }
-       else {
-         SYMBOL_TYPE (new->name) = fcn_type_saved;
-         fcn_type_saved = NULL;
-       }
-#else
-       new->name = define_symbol 
-               (fcn_cs_saved.c_value, fcn_stab_saved.c_name, 0, 0, objfile);
-#endif
-      }
-      else if (STREQ (cs->c_name, ".ef")) {
-
-        bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
-                             main_aux);
-
-       /* the value of .ef is the address of epilogue code;
-          not useful for gdb */
-       /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
-          contains number of lines to '}' */
-
-       fcn_last_line = main_aux->x_sym.x_misc.x_lnsz.x_lnno;
-       new = pop_context ();
-       if (context_stack_depth != 0)
-         error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
-             symnum);
-
-       finish_block (new->name, &local_symbols, new->old_blocks,
-           new->start_addr,
-           fcn_cs_saved.c_value +
-           fcn_aux_saved.x_sym.x_misc.x_fsize, objfile);
-       within_function = 0;
-      }
-      break;
-
-    case C_BSTAT       :               /* begin static block   */
-      static_block_base = read_symbol_nvalue (cs->c_value);
-      break;
-
-    case C_ESTAT       :               /* end of static block  */
-      static_block_base = 0;
-      break;
-
-    case C_ARG         :               /* These are not implemented. */
-    case C_REGPARM     :
-    case C_TPDEF       :
-    case C_STRTAG      :
-    case C_UNTAG       :
-    case C_ENTAG       :
-      printf ("ERROR: Unimplemented storage class: %d.\n", cs->c_sclass);
-      break;
-
-    case C_HIDEXT      :               /* ignore these.. */
-    case C_LABEL       :
-    case C_NULL                :
-      break;
-
-    case C_BINCL       :               /* beginning of include file */
-
-       /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
-          order. Thus, when wee see them, we might not know enough info
-          to process them. Thus, we'll be saving them into a table 
-          (inclTable) and postpone their processing. */
-
-       record_include_begin (cs);
-       break;
-
-    case C_EINCL       :               /* end of include file */
-                       /* see the comment after case C_BINCL. */
-       record_include_end (cs);
-       break;
-
-    case C_BLOCK       :
-      if (STREQ (cs->c_name, ".bb")) {
-       depth++;
-       new = push_context (depth, cs->c_value);
-      }
-      else if (STREQ (cs->c_name, ".eb")) {
-       new = pop_context ();
-       if (depth != new->depth)
-         error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
-                        symnum);
-
-       depth--;
-       if (local_symbols && context_stack_depth > 0) {
-         /* Make a block for the local symbols within.  */
-         finish_block (new->name, &local_symbols, new->old_blocks,
-                                 new->start_addr, cs->c_value, objfile);
+       default:
+         process_xcoff_symbol (cs, objfile);
+         break;
        }
-       local_symbols = new->locals;
-      }
-      break;
-
-    default            :
-      process_xcoff_symbol (cs, objfile);
-      break;
     }
 
-  } /* while */
-
   if (last_source_file)
     {
-      end_symtab (cur_src_end_addr, 1, 0, objfile);
+      end_symtab (cur_src_end_addr, 1, 0, objfile, textsec->target_index);
       end_stabs ();
     }
 
@@ -1645,6 +1753,9 @@ function_entry_point:
   (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
 
 
+static struct type *func_symbol_type;
+static struct type *var_symbol_type;
+
 /* process one xcoff symbol. */
 
 static struct symbol *
@@ -1664,309 +1775,214 @@ process_xcoff_symbol (cs, objfile)
   if (name[0] == '.')
     ++name;
 
-  bzero (sym, sizeof (struct symbol));
+  memset (sym, '\0', sizeof (struct symbol));
 
   /* default assumptions */
   SYMBOL_VALUE (sym) = cs->c_value;
   SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
+  SYMBOL_SECTION (sym) = cs->c_secnum;
 
-  if (ISFCN (cs->c_type)) {
-
-    /* At this point, we don't know the type of the function and assume it 
-       is int. This will be patched with the type from its stab entry later 
-       on in patch_block_stabs () */
-
-    SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
-    SYMBOL_TYPE (sym) = lookup_function_type (lookup_fundamental_type (objfile, FT_INTEGER));
-
-    SYMBOL_CLASS (sym) = LOC_BLOCK;
-    SYMBOL_DUP (sym, sym2);
-
-    if (cs->c_sclass == C_EXT)
-      add_symbol_to_list (sym2, &global_symbols);
-    else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
-      add_symbol_to_list (sym2, &file_symbols);
-  }
+  if (ISFCN (cs->c_type))
+    {
+      /* At this point, we don't know the type of the function.  This
+        will be patched with the type from its stab entry later on in
+        patch_block_stabs (), unless the file was compiled without -g.  */
 
-  else {
+      SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
+      SYMBOL_TYPE (sym) = func_symbol_type;
 
-    /* in case we can't figure out the type, default is `int'. */
-    SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile, FT_INTEGER);
+      SYMBOL_CLASS (sym) = LOC_BLOCK;
+      SYMBOL_DUP (sym, sym2);
 
-    switch (cs->c_sclass)
+      if (cs->c_sclass == C_EXT)
+       add_symbol_to_list (sym2, &global_symbols);
+      else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
+       add_symbol_to_list (sym2, &file_symbols);
+    }
+  else
     {
+      /* In case we can't figure out the type, provide default. */
+      SYMBOL_TYPE (sym) = var_symbol_type;
+
+      switch (cs->c_sclass)
+       {
 #if 0
-    case C_FUN:
-      if (fcn_cs_saved.c_sclass == C_EXT)
-       add_stab_to_list (name, &global_stabs);
-      else
-       add_stab_to_list (name, &file_stabs);
-      break;
+       case C_FUN:
+         if (fcn_cs_saved.c_sclass == C_EXT)
+           add_stab_to_list (name, &global_stabs);
+         else
+           add_stab_to_list (name, &file_stabs);
+         break;
 #endif
 
-    case C_DECL:                       /* a type decleration?? */
-
-#if defined(NO_TYPEDEFS) || defined(NO_DEFINE_SYMBOL)
-       qq =  (char*) strchr (name, ':');
-       if (!qq)                        /* skip if there is no ':' */
-         return NULL;
-
-       nameless = (qq == name);
-
-       struct_and_type_combined = (qq[1] == 'T' && qq[2] == 't');
-       pp = qq + (struct_and_type_combined ? 3 : 2);
-
-
-       /* To handle GNU C++ typename abbreviation, we need to be able to fill
-          in a type's name as soon as space for that type is allocated. */
-
-       if (struct_and_type_combined && name != qq) {
-
-          int typenums[2];
-          struct type *tmp_type;
-          char *tmp_pp = pp;
-
-          read_type_number (&tmp_pp, typenums);
-          tmp_type = dbx_alloc_type (typenums, objfile);
-
-          if (tmp_type && !TYPE_NAME (tmp_type) && !nameless)
-            TYPE_NAME (tmp_type) = SYMBOL_NAME (sym) =
-                               obsavestring (name, qq-name,
-                                             &objfile->symbol_obstack);
-       }
-       ttype = SYMBOL_TYPE (sym) = read_type (&pp, objfile);
-
-       /* if there is no name for this typedef, you don't have to keep its
-          symbol, since nobody could ask for it. Otherwise, build a symbol
-          and add it into symbol_list. */
-
-       if (nameless)
-         return;
+       case C_GSYM:
+         add_stab_to_list (name, &global_stabs);
+         break;
 
-#ifdef NO_TYPEDEFS
-       /* Transarc wants to eliminate type definitions from the symbol table.
-          Limited debugging capabilities, but faster symbol table processing
-          and less memory usage. Note that tag definitions (starting with
-          'T') will remain intact. */
+       case C_BCOMM:
+         common_block_start (cs->c_name, objfile);
+         break;
 
-       if (qq[1] != 'T' && (!TYPE_NAME (ttype) || *(TYPE_NAME (ttype)) == '\0')) {
+       case C_ECOMM:
+         common_block_end (objfile);
+         break;
 
-         if (SYMBOL_NAME (sym))
-             TYPE_NAME (ttype) = SYMBOL_NAME (sym);
-         else
-             TYPE_NAME (ttype) = obsavestring (name, qq-name);
+       default:
+         complain (&storclass_complaint, cs->c_sclass);
+         /* FALLTHROUGH */
 
-         return;
-       }
+       case C_DECL:
+       case C_PSYM:
+       case C_RPSYM:
+       case C_ECOML:
 
-#endif /* !NO_TYPEDEFS */
+         sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
+         if (sym != NULL)
+           {
+             SYMBOL_SECTION (sym) = cs->c_secnum;
+           }
+         return sym;
 
-       /* read_type() will return null if type (or tag) definition was
-          unnnecessarily duplicated. Also, if the symbol doesn't have a name,
-          there is no need to keep it in symbol table. */
-       /* The above argument no longer valid. read_type() never returns NULL. */
+       case C_STSYM:
 
-       if (!ttype)
-         return NULL;
+         /* For xlc (not GCC), the 'V' symbol descriptor is used for
+            all statics and we need to distinguish file-scope versus
+            function-scope using within_function.  We do this by
+            changing the string we pass to define_symbol to use 'S'
+            where we need to, which is not necessarily super-clean,
+            but seems workable enough.  */
 
-       /* if there is no name for this typedef, you don't have to keep its
-          symbol, since nobody could ask for it. Otherwise, build a symbol
-          and add it into symbol_list. */
-
-       if (qq[1] == 'T')
-           SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
-       else if (qq[1] == 't')
-           SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
-       else {
-           warning ("Unrecognized stab string.\n");
+         if (*name == ':' || (pp = (char *) strchr(name, ':')) == NULL)
            return NULL;
-       }
-
-       SYMBOL_CLASS (sym) = LOC_TYPEDEF;
-       if (!SYMBOL_NAME (sym))
-           SYMBOL_NAME (sym) = obsavestring (name, qq-name);
-
-       SYMBOL_DUP (sym, sym2);
-       add_symbol_to_list 
-            (sym2, within_function ? &local_symbols : &file_symbols);
-
-       /* For a combination of struct and type, add one more symbol
-          for the type. */
-
-       if (struct_and_type_combined) {
-           SYMBOL_DUP (sym, sym2);
-           SYMBOL_NAMESPACE (sym2) = VAR_NAMESPACE;
-           add_symbol_to_list 
-              (sym2, within_function ? &local_symbols : &file_symbols);
-       }
-
-       /*  assign a name to the type node. */
-
-       if (!TYPE_NAME (ttype) || *(TYPE_NAME (ttype)) == '\0') {
-         if (struct_and_type_combined)
-           TYPE_NAME (ttype) = SYMBOL_NAME (sym);
-         else if  (qq[1] == 'T')               /* struct namespace */
-           TYPE_NAME (ttype) = concat (
-               TYPE_CODE (ttype) == TYPE_CODE_UNION ? "union " :
-               TYPE_CODE (ttype) == TYPE_CODE_STRUCT? "struct " : "enum ",
-               SYMBOL_NAME (sym), NULL);
-       }
-       break;
 
-#else /* !NO_DEFINE_SYMBOL */
-       return define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
-#endif
-
-    case C_GSYM:
-      add_stab_to_list (name, &global_stabs);
-      break;
-
-    case C_PSYM:
-    case C_RPSYM:
-
-#ifdef NO_DEFINE_SYMBOL
-       if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
-         return NULL;
-       SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack);
-       SYMBOL_CLASS (sym) = (cs->c_sclass == C_PSYM) ? LOC_ARG : LOC_REGPARM;
-       pp += 2;
-       SYMBOL_TYPE (sym) = read_type (&pp, objfile);
-       SYMBOL_DUP (sym, sym2);
-       add_symbol_to_list (sym2, &local_symbols);
-       break;
-#else
-       sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
-       SYMBOL_CLASS (sym) = (cs->c_sclass == C_PSYM) ? LOC_ARG : LOC_REGPARM;
-       return sym;
-#endif
-
-    case C_STSYM:
+         ++pp;
+         if (*pp == 'V' && !within_function)
+           *pp = 'S';
+         sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
+         if (sym != NULL)
+           {
+             SYMBOL_VALUE (sym) += static_block_base;
+             SYMBOL_SECTION (sym) = static_block_section;
+           }
+         return sym;
 
-#ifdef NO_DEFINE_SYMBOL
-       if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
-         return NULL;
-       SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack);
-       SYMBOL_CLASS (sym) = LOC_STATIC;
-       SYMBOL_VALUE (sym) += static_block_base;
-       pp += 2;
-       SYMBOL_TYPE (sym) = read_type (&pp, objfile);
-       SYMBOL_DUP (sym, sym2);
-       add_symbol_to_list 
-          (sym2, within_function ? &local_symbols : &file_symbols);
-       break;
-#else
-       /* If we are going to use Sun dbx's define_symbol(), we need to
-          massage our stab string a little. Change 'V' type to 'S' to be
-          comparible with Sun. */
-
-       if (*name == ':' || (pp = (char *) index (name, ':')) == NULL)
-         return NULL;
+       case C_LSYM:
+         sym = define_symbol (cs->c_value, cs->c_name, 0, N_LSYM, objfile);
+         if (sym != NULL)
+           {
+             SYMBOL_SECTION (sym) = cs->c_secnum;
+           }
+         return sym;
 
-       ++pp;
-       if (*pp == 'V') *pp = 'S';
-       sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
-       SYMBOL_VALUE (sym) += static_block_base;
-       return sym;
-#endif
+       case C_AUTO:
+         SYMBOL_CLASS (sym) = LOC_LOCAL;
+         SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
+         SYMBOL_SECTION (sym) = cs->c_secnum;
+         SYMBOL_DUP (sym, sym2);
+         add_symbol_to_list (sym2, &local_symbols);
+         break;
 
-    case C_LSYM:
-       if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
-         return NULL;
-       SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack);
-       SYMBOL_CLASS (sym) = LOC_LOCAL;
-       pp += 1;
-       SYMBOL_TYPE (sym) = read_type (&pp, objfile);
-       SYMBOL_DUP (sym, sym2);
-       add_symbol_to_list (sym2, &local_symbols);
-       break;
-
-    case C_AUTO:
-      SYMBOL_CLASS (sym) = LOC_LOCAL;
-      SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
-      SYMBOL_DUP (sym, sym2);
-      add_symbol_to_list (sym2, &local_symbols);
-      break;
+       case C_EXT:
+         SYMBOL_CLASS (sym) = LOC_STATIC;
+         SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
+         SYMBOL_SECTION (sym) = cs->c_secnum;
+         SYMBOL_DUP (sym, sym2);
+         add_symbol_to_list (sym2, &global_symbols);
+         break;
 
-    case C_EXT:
-      SYMBOL_CLASS (sym) = LOC_STATIC;
-      SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
-      SYMBOL_DUP (sym, sym2);
-      add_symbol_to_list (sym2, &global_symbols);
-      break;
+       case C_STAT:
+         SYMBOL_CLASS (sym) = LOC_STATIC;
+         SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
+         SYMBOL_SECTION (sym) = cs->c_secnum;
+         SYMBOL_DUP (sym, sym2);
+         add_symbol_to_list 
+           (sym2, within_function ? &local_symbols : &file_symbols);
+         break;
 
-    case C_STAT:
-      SYMBOL_CLASS (sym) = LOC_STATIC;
-      SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
-      SYMBOL_DUP (sym, sym2);
-      add_symbol_to_list 
-          (sym2, within_function ? &local_symbols : &file_symbols);
-      break;
+       case C_REG:
+         printf_unfiltered ("ERROR! C_REG is not fully implemented!\n");
+         SYMBOL_CLASS (sym) = LOC_REGISTER;
+         SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
+         SYMBOL_SECTION (sym) = cs->c_secnum;
+         SYMBOL_DUP (sym, sym2);
+         add_symbol_to_list (sym2, &local_symbols);
+         break;
 
-    case C_REG:
-      printf ("ERROR! C_REG is not fully implemented!\n");
-      SYMBOL_CLASS (sym) = LOC_REGISTER;
-      SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
-      SYMBOL_DUP (sym, sym2);
-      add_symbol_to_list (sym2, &local_symbols);
-      break;
-
-    case C_RSYM:
-       pp = (char*) strchr (name, ':');
-#ifdef NO_DEFINE_SYMBOL
-       SYMBOL_CLASS (sym) = LOC_REGISTER;
-       SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (cs->c_value);
-       if (pp) {
-         SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack);
-         pp += 2;
-         if (*pp)
-           SYMBOL_TYPE (sym) = read_type (&pp, objfile);
-       }
-       else
-         /* else this is not a stab entry, suppose the type is either
-            `int' or `float', depending on the register class. */
-
-         SYMBOL_TYPE (sym) = (SYMBOL_VALUE (sym) < 32)
-             ? lookup_fundamental_type (objfile, FT_INTEGER)
-                 : lookup_fundamental_type (objfile, FT_FLOAT);
-
-       SYMBOL_DUP (sym, sym2);
-       add_symbol_to_list (sym2, &local_symbols);
-       break;
-#else
-       if (pp) {
-         sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
-         return sym;
-       }
-       else {
-         complain (&rsym_complaint, name);
-         return NULL;
+       case C_RSYM:
+         pp = (char*) strchr (name, ':');
+         if (pp)
+           {
+             sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
+             if (sym != NULL)
+               SYMBOL_SECTION (sym) = cs->c_secnum;
+             return sym;
+           }
+         else
+           {
+             complain (&rsym_complaint, name);
+             return NULL;
+           }
        }
-#endif
-
-    default    :
-      complain (&storclass_complaint, cs->c_sclass);
-      return NULL;
     }
-  }
   return sym2;
 }
 
-/* Get value corresponding to symbol number symno in symtbl.  */
+/* Extract the file name from the aux entry of a C_FILE symbol.  Return
+   only the last component of the name.  Result is in static storage and
+   is only good for temporary use.  */
 
-static int
-read_symbol_nvalue (symno)
-     int symno;
+static char *
+coff_getfilename (aux_entry)
+    union internal_auxent *aux_entry;
 {
-  struct internal_syment symbol[1];
+  static char buffer[BUFSIZ];
+  register char *temp;
+  char *result;
+
+  if (aux_entry->x_file.x_n.x_zeroes == 0)
+    strcpy (buffer, strtbl + aux_entry->x_file.x_n.x_offset);
+  else
+    {
+      strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
+      buffer[FILNMLEN] = '\0';
+    }
+  result = buffer;
+
+  /* FIXME: We should not be throwing away the information about what
+     directory.  It should go into dirname of the symtab, or some such
+     place.  */
+  if ((temp = strrchr (result, '/')) != NULL)
+    result = temp + 1;
+  return (result);
+}
 
+/* Set *SYMBOL to symbol number symno in symtbl.  */
+static void
+read_symbol (symbol, symno)
+     struct internal_syment *symbol;
+     int symno;
+{
   if (symno < 0 || symno >= symtbl_num_syms)
     {
-      struct complaint msg =
+      static struct complaint msg =
        {"Invalid symbol offset", 0, 0};
       complain (&msg);
-      return 0;
+      symbol->n_value = 0;
+      symbol->n_scnum = -1;
+      return;
     }
   bfd_coff_swap_sym_in (symfile_bfd, symtbl + (symno*local_symesz), symbol);
+}
+  
+/* Get value corresponding to symbol number symno in symtbl.  */
+
+static int
+read_symbol_nvalue (symno)
+     int symno;
+{
+  struct internal_syment symbol[1];
+
+  read_symbol (symbol, symno);
   return symbol->n_value;  
 }
 
@@ -2008,7 +2024,8 @@ gotit:
   /* take aux entry and return its lineno */
   symno++;
   bfd_coff_swap_aux_in (symfile_bfd, symtbl+(symno*local_symesz),
-                       symbol->n_type, symbol->n_sclass, main_aux);
+                       symbol->n_type, symbol->n_sclass,
+                       0, symbol->n_numaux, main_aux);
 
   return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
 }
@@ -2059,6 +2076,8 @@ init_lineno (abfd, offset, size)
 {
   int val;
 
+  free_linetab ();
+
   if (bfd_seek(abfd, offset, L_SET) < 0)
     return -1;
 
@@ -2070,22 +2089,17 @@ init_lineno (abfd, offset, size)
 
   linetab_offset = offset;
   linetab_size = size;
-  make_cleanup (free, linetab);        /* Be sure it gets de-allocated. */
   return 0;
 }
-\f
-/* dbx allows the text of a symbol name to be continued into the
-   next symbol name!  When such a continuation is encountered
-   (a \ at the end of the text of a name)
-   call this function to get the continuation.  */
-/* So far, I haven't seen this happenning xlc output. I doubt we'll need this
-   for xcoff. */
-
-#undef next_symbol_text
-#define        next_symbol_text() \
-  printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
-
 
+static void
+free_linetab ()
+{
+  if (linetab)
+    free (linetab);
+  linetab = NULL;
+}
+\f
 static void
 xcoff_new_init (objfile)
      struct objfile *objfile;
@@ -2172,7 +2186,7 @@ init_stringtab(abfd, offset, objfile)
   if (strtbl == NULL)
     return -1;
 
-  bcopy(&length, strtbl, sizeof length);
+  memcpy(strtbl, &length, sizeof length);
   if (length == sizeof length)
     return 0;
 
@@ -2208,7 +2222,7 @@ init_debugsection(abfd)
     return -1;
 
   if (!bfd_get_section_contents(abfd, secp, debugsec, (file_ptr) 0, length)) {
-    printf ("Can't read .debug section from symbol file\n");
+    printf_unfiltered ("Can't read .debug section from symbol file\n");
     return -1;
   }
   return 0;
@@ -2228,7 +2242,7 @@ free_debugsection()
 static void
 xcoff_symfile_read (objfile, section_offset, mainline)
   struct objfile *objfile;
-  struct section_offset *section_offset;
+  struct section_offsets *section_offset;
   int mainline;
 {
   int num_symbols;                     /* # of symbols */
@@ -2238,6 +2252,7 @@ xcoff_symfile_read (objfile, section_offset, mainline)
   bfd *abfd;
   struct coff_symfile_info *info;
   char *name;
+  struct cleanup *back_to = make_cleanup (null_cleanup, 0);
 
   info = (struct coff_symfile_info *) objfile -> sym_private;
   symfile_bfd = abfd = objfile->obfd;
@@ -2257,6 +2272,7 @@ xcoff_symfile_read (objfile, section_offset, mainline)
       && info->max_lineno_offset > info->min_lineno_offset) {
 
     /* only read in the line # table if one exists */
+    make_cleanup (free_linetab, 0);
     val = init_lineno(abfd, info->min_lineno_offset,
        (int) (info->max_lineno_offset - info->min_lineno_offset));
 
@@ -2302,19 +2318,35 @@ xcoff_symfile_read (objfile, section_offset, mainline)
   free_debugsection ();
 
   /* Sort symbols alphabetically within each block.  */
-  sort_syms ();
+  {
+    struct symtab *s;
+    for (s = objfile -> symtabs; s != NULL; s = s -> next)
+      {
+       sort_symtab_syms (s);
+      }
+  }
 
   /* Install any minimal symbols that have been collected as the current
      minimal symbols for this objfile. */
 
   install_minimal_symbols (objfile);
 
-  /* Make a default for file to list.  */
-  select_source_symtab (0);
+  do_cleanups (back_to);
 }
 
-/* XCOFF-specific parsing routine for section offsets.
-   Plain and simple for now.  */
+/* XCOFF-specific parsing routine for section offsets.  */
+
+static int largest_section;
+
+static void
+note_one_section (abfd, asect, ptr)
+     bfd *abfd;
+     asection *asect;
+     PTR ptr;
+{
+  if (asect->target_index > largest_section)
+    largest_section = asect->target_index;
+}
 
 static
 struct section_offsets *
@@ -2324,23 +2356,43 @@ xcoff_symfile_offsets (objfile, addr)
 {
   struct section_offsets *section_offsets;
   int i;
-  section_offsets = (struct section_offsets *)
-    obstack_alloc (&objfile -> psymbol_obstack,
-                  sizeof (struct section_offsets) +
-                         sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
 
-  for (i = 0; i < SECT_OFF_MAX; i++)
-    ANOFFSET (section_offsets, i) = addr;
+  largest_section = 0;
+  bfd_map_over_sections (objfile->obfd, note_one_section, NULL);
+  objfile->num_sections = largest_section + 1;
+  section_offsets = (struct section_offsets *)
+    obstack_alloc
+      (&objfile -> psymbol_obstack,
+       sizeof (struct section_offsets)
+       + sizeof (section_offsets->offsets) * (objfile->num_sections));
+
+  /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
+     of the .text section.  This strikes me as wrong--whether the
+     offset to be applied to symbol reading is relative to the start
+     address of the section depends on the symbol format.  In any
+     event, this whole "addr" concept is pretty broken (it doesn't
+     handle any section but .text sensibly), so just ignore the addr
+     parameter and use 0.  That matches the fact that xcoff_symfile_read
+     ignores the section_offsets).  */
+  for (i = 0; i < objfile->num_sections; i++)
+    ANOFFSET (section_offsets, i) = 0;
   
   return section_offsets;
 }
-/* Register our ability to parse symbols for xcoff BFD files. */
+
+/* Register our ability to parse symbols for xcoff BFD files.  */
 
 static struct sym_fns xcoff_sym_fns =
 {
-  "aixcoff-rs6000",    /* sym_name: name or name prefix of BFD target type */
-  15,                  /* sym_namelen: number of significant sym_name chars */
+
+  /* Because the bfd uses coff_flavour, we need to specially kludge
+     the flavour.  FIXME: coff and xcoff and fundamentally similar
+     except for debug format, and we should see if we can merge this
+     file with coffread.c.  For example, the extra storage classes
+     used for stabs could presumably be recognized in any COFF file.  */
+
+  (enum bfd_flavour)-1,
+
   xcoff_new_init,      /* sym_new_init: init anything gbl to entire symtab */
   xcoff_symfile_init,  /* sym_init: read initial info, setup for sym_read() */
   xcoff_symfile_read,  /* sym_read: read a symbol file into symtab */
@@ -2354,10 +2406,17 @@ _initialize_xcoffread ()
 {
   add_symtab_fns(&xcoff_sym_fns);
 
-  /* Initialize symbol template later used for arguments.  */
+  /* Initialize symbol template later used for arguments.  Its other
+     fields are zero, or are filled in later.  */
   SYMBOL_NAME (&parmsym) = "";
   SYMBOL_INIT_LANGUAGE_SPECIFIC (&parmsym, language_c);
   SYMBOL_NAMESPACE (&parmsym) = VAR_NAMESPACE;
   SYMBOL_CLASS (&parmsym) = LOC_ARG;
-  /* Its other fields are zero, or are filled in later.  */
+
+  func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
+                               "<function, no debug info>", NULL);
+  TYPE_TARGET_TYPE (func_symbol_type) = builtin_type_int;
+  var_symbol_type =
+    init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
+              "<variable, no debug info>", NULL);
 }
This page took 0.047795 seconds and 4 git commands to generate.