* objfiles.c (allocate_objfile): Add the newly-created objfile to
[deliverable/binutils-gdb.git] / gdb / xcoffread.c
index 7290f179fd708c3d19ac951c2cb65167dd4ed522..a40aa8f1237858cfd79f033b20e50acac14d5ea3 100644 (file)
@@ -41,6 +41,10 @@ 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"
@@ -49,25 +53,15 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "stabsread.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 */
-
 /* For interface with stabsread.c.  */
 #include "aout/stab_gnu.h"
 
-/* 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. */
-
-/* #define     NO_TYPEDEFS  1 */
-
 /* 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;
   unsigned char c_sclass;
   int c_secnum;
@@ -174,12 +168,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 *));
@@ -190,6 +180,9 @@ 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));
 
@@ -298,6 +291,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)
@@ -405,6 +400,7 @@ 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)
@@ -418,32 +414,17 @@ struct coff_symbol *cs;
       /* 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.  */
-      struct complaint msg = {"Nested C_BINCL symbols", 0, 0};
+      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;
@@ -452,10 +433,12 @@ struct coff_symbol *cs;
 
   if (inclDepth == 0)
     {
-      struct complaint msg = {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
+      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;
 
@@ -463,9 +446,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)
@@ -491,7 +495,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)
@@ -520,7 +524,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. */
@@ -620,7 +624,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
@@ -718,7 +722,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. */
@@ -811,7 +815,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;
       }
@@ -893,7 +897,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;
       }
@@ -927,7 +931,7 @@ 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, SECTION)       \
+#define        RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED, SECTION, OBJFILE) \
 {                                              \
   char *namestr;                               \
   if (ALLOCED)                                         \
@@ -938,7 +942,7 @@ retrieve_traceback (abfd, textsec, cs, size)
     (ALLOCED) = 1;                                             \
   }                                                            \
   prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
-                                      (char *)NULL, (SECTION));        \
+                                      (char *)NULL, (SECTION), (OBJFILE)); \
   misc_func_recorded = 1;                                      \
 }
 
@@ -976,6 +980,46 @@ static int static_block_section = -1;
 
 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
@@ -984,13 +1028,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;
@@ -1052,9 +1095,11 @@ read_xcoff_symtab (objfile, nsyms)
 
   textsec = bfd_get_section_by_name (abfd, ".text");
   if (!textsec) {
-    printf ("Unable to locate text section!\n");
+    printf_unfiltered ("Unable to locate text section!\n");
   }
 
+  next_symbol_text_func = xcoff_next_symbol_text;
+
   while (symnum < nsyms) {
 
     QUIT;                      /* make this command interruptable.  */
@@ -1071,7 +1116,7 @@ read_xcoff_symtab (objfile, nsyms)
       bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
 
       cs->c_symnum = symnum;
-      cs->c_nsyms = symbol->n_numaux;
+      cs->c_naux = symbol->n_numaux;
       if (symbol->n_zeroes) {
        symname_alloced = 0;
        /* We must use the original, unswapped, name here so the name field
@@ -1133,44 +1178,46 @@ read_xcoff_symtab (objfile, nsyms)
     /* 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);
+                           0, cs->c_naux, &main_aux);
       goto function_entry_point;
     }
 
-    if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT) && cs->c_nsyms == 1)
+    if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT) && cs->c_naux == 1)
     {
        /* dealing with a symbol with a csect entry. */
 
 #   define     CSECT(PP)       ((PP)->x_csect)
-#   define     CSECT_LEN(PP)   (CSECT(PP).x_scnlen)
+#   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)
 
        /* Convert the auxent to something we can access.  */
         bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
-                             main_aux);
+                             0, cs->c_naux, &main_aux);
 
-       switch (CSECT_SMTYP (main_aux)) {
+       switch (CSECT_SMTYP (&main_aux)) {
 
        case XTY_ER :
          continue;                     /* ignore all external references. */
 
        case XTY_SD :                   /* a section description. */
          {
-           switch (CSECT_SCLAS (main_aux)) {
+           switch (CSECT_SCLAS (&main_aux)) {
 
            case XMC_PR :                       /* a `.text' csect.     */
              {
 
-               /* 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!  */
+               /* 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) {
 
@@ -1181,7 +1228,8 @@ read_xcoff_symtab (objfile, nsyms)
                  if (!misc_func_recorded) {
                     int alloced = 0;
                     RECORD_MINIMAL_SYMBOL (last_csect_name, last_csect_val,
-                                           mst_text, alloced, last_csect_sec);
+                                           mst_text, alloced, last_csect_sec,
+                                           objfile);
                  }
                    
 
@@ -1191,17 +1239,19 @@ read_xcoff_symtab (objfile, nsyms)
                              textsec->target_index);
                  end_stabs ();
                  start_stabs ();
-                 start_symtab ((char *)NULL, (char *)NULL, (CORE_ADDR)0);
+                 /* Give all csects for this source file the same
+                    name.  */
+                 start_symtab (filestring, (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);
+                 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);
+               file_end_addr = cs->c_value + CSECT_LEN (&main_aux);
 
                if (cs->c_name && cs->c_name[0] == '.') {
                  last_csect_name = cs->c_name;
@@ -1234,19 +1284,19 @@ read_xcoff_symtab (objfile, nsyms)
        case XTY_LD :
          
          /* a function entry point. */
-         if (CSECT_SCLAS (main_aux) == XMC_PR) {
+         if (CSECT_SCLAS (&main_aux) == XMC_PR) {
 
 function_entry_point:
            RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text, 
-                                  symname_alloced, cs->c_secnum);
+                                  symname_alloced, cs->c_secnum, objfile);
 
-           fcn_line_offset = main_aux->x_sym.x_fcnary.x_fcn.x_lnnoptr;
+           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;
+           fcn_aux_saved = main_aux;
 
 
            ptb = NULL;
@@ -1255,11 +1305,15 @@ function_entry_point:
               already available for it. Process traceback table for
               functions with only one auxent. */
 
-           if (cs->c_nsyms == 1)
+           if (cs->c_naux == 1)
              ptb = retrieve_tracebackinfo (abfd, textsec, cs);
 
-           else if (cs->c_nsyms != 2)
-             abort ();
+           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. */
 
@@ -1305,10 +1359,11 @@ function_entry_point:
            continue;
          }
          /* shared library function trampoline code entry point. */
-         else if (CSECT_SCLAS (main_aux) == XMC_GL) {
+         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. */
+           /* record trampoline code entries as mst_solib_trampoline symbol.
+              When we lookup mst symbols, we will choose mst_text over
+              mst_solib_trampoline. */
 
 #if 1
            /* After the implementation of incremental loading of shared
@@ -1319,26 +1374,28 @@ function_entry_point:
               consistient with gdb's behaviour on a SUN platform. */
 
            /* 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. */
+              by assigning `mst_solib_trampoline' type to trampoline entries
+              fails.  Gdb treats those entries as chars. FIXME. */
 
            /* Recording this entry is necessary. Single stepping relies on
               this vector to get an idea about function address boundaries. */
 
            prim_record_minimal_symbol_and_info
-             ("<trampoline>", cs->c_value, mst_unknown,
-              (char *)NULL, cs->c_secnum);
+             ("<trampoline>", cs->c_value, mst_solib_trampoline,
+              (char *)NULL, cs->c_secnum, objfile);
 #else
 
-           /* record trampoline code entries as mst_unknown symbol. When we
-              lookup mst symbols, we will choose mst_text over mst_unknown. */
+           /* 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_unknown,
-                                  symname_alloced);
+           RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value,
+                                  mst_solib_trampoline,
+                                  symname_alloced, objfile);
 #endif
            continue;
          }
-         break;
+         continue;
 
        default :               /* all other XTY_XXXs */
          break;
@@ -1358,7 +1415,7 @@ function_entry_point:
 
          int alloced = 0;
          RECORD_MINIMAL_SYMBOL (last_csect_name, last_csect_val,
-                               mst_text, alloced, last_csect_sec);
+                               mst_text, alloced, last_csect_sec, objfile);
       }
 
       /* c_value field contains symnum of next .file entry in table
@@ -1377,15 +1434,24 @@ function_entry_point:
       cur_src_end_addr = file_end_addr;
       end_symtab (file_end_addr, 1, 0, objfile, textsec->target_index);
       end_stabs ();
+
+      /* 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)
+       filestring = coff_getfilename (&main_aux);
+      else
+       filestring = cs->c_name;
+
       start_stabs ();
-      start_symtab (cs->c_name, (char *)NULL, (CORE_ADDR)0);
+      start_symtab (filestring, (char *)NULL, (CORE_ADDR)0);
       last_csect_name = 0;
 
       /* 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;
-
-      filestring = cs->c_name;
       break;
 
 
@@ -1398,7 +1464,7 @@ function_entry_point:
       if (STREQ (cs->c_name, ".bf")) {
 
         bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
-                             main_aux);
+                             0, cs->c_naux, &main_aux);
 
        within_function = 1;
 
@@ -1414,14 +1480,14 @@ function_entry_point:
       else if (STREQ (cs->c_name, ".ef")) {
 
         bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
-                             main_aux);
+                             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;
+       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.",
@@ -1456,7 +1522,7 @@ function_entry_point:
     case C_STRTAG      :
     case C_UNTAG       :
     case C_ENTAG       :
-      printf ("ERROR: Unimplemented storage class: %d.\n", cs->c_sclass);
+      printf_unfiltered ("ERROR: Unimplemented storage class: %d.\n", cs->c_sclass);
       break;
 
     case C_HIDEXT      :               /* ignore these.. */
@@ -1554,7 +1620,7 @@ 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;
@@ -1595,125 +1661,26 @@ process_xcoff_symbol (cs, objfile)
       break;
 #endif
 
-    case C_DECL:                       /* a type decleration?? */
-
-#if defined(NO_TYPEDEFS)
-       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;
-
-       /* 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. */
-
-       if (qq[1] != 'T' && (!TYPE_NAME (ttype) || *(TYPE_NAME (ttype)) == '\0')) {
-
-         if (SYMBOL_NAME (sym))
-             TYPE_NAME (ttype) = SYMBOL_NAME (sym);
-         else
-             TYPE_NAME (ttype) = obsavestring (name, qq-name);
-
-         return;
-       }
-
-       /* 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. */
-
-       if (!ttype)
-         return NULL;
-
-       /* 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");
-           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_TYPEDEFS */
-      sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
-      if (sym != NULL)
-       SYMBOL_SECTION (sym) = cs->c_secnum;
-      return sym;
-#endif
-
     case C_GSYM:
       add_stab_to_list (name, &global_stabs);
       break;
 
+    case C_BCOMM:
+      common_block_start (cs->c_name, objfile);
+      break;
+
+    case C_ECOMM:
+      common_block_end (objfile);
+      break;
+
+    default:
+      complain (&storclass_complaint, cs->c_sclass);
+      /* FALLTHROUGH */
+
+    case C_DECL:
     case C_PSYM:
     case C_RPSYM:
+    case C_ECOML:
 
       sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
       if (sym != NULL)
@@ -1724,24 +1691,25 @@ process_xcoff_symbol (cs, objfile)
 
     case C_STSYM:
 
-       /* 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. */
-        /* FIXME: I believe this is to avoid a Sun-specific hack somewhere.
-          Needs more investigation.  */
+      /* 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 (*name == ':' || (pp = (char *) index (name, ':')) == NULL)
-         return NULL;
+      if (*name == ':' || (pp = (char *) strchr(name, ':')) == NULL)
+       return NULL;
 
-       ++pp;
-       if (*pp == 'V') *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;
+      ++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;
 
     case C_LSYM:
       sym = define_symbol (cs->c_value, cs->c_name, 0, N_LSYM, objfile);
@@ -1777,7 +1745,7 @@ process_xcoff_symbol (cs, objfile)
       break;
 
     case C_REG:
-      printf ("ERROR! C_REG is not fully implemented!\n");
+      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;
@@ -1797,10 +1765,6 @@ process_xcoff_symbol (cs, objfile)
          complain (&rsym_complaint, name);
          return NULL;
        }
-
-    default    :
-      complain (&storclass_complaint, cs->c_sclass);
-      return NULL;
     }
   }
   return sym2;
@@ -1814,7 +1778,7 @@ read_symbol (symbol, symno)
 {
   if (symno < 0 || symno >= symtbl_num_syms)
     {
-      struct complaint msg =
+      static struct complaint msg =
        {"Invalid symbol offset", 0, 0};
       complain (&msg);
       symbol->n_value = 0;
@@ -1874,7 +1838,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;
 }
@@ -1925,6 +1890,8 @@ init_lineno (abfd, offset, size)
 {
   int val;
 
+  free_linetab ();
+
   if (bfd_seek(abfd, offset, L_SET) < 0)
     return -1;
 
@@ -1936,22 +1903,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;
@@ -2038,7 +2000,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;
 
@@ -2074,7 +2036,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;
@@ -2094,7 +2056,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 */
@@ -2104,6 +2066,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;
@@ -2123,6 +2086,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));
 
@@ -2168,12 +2132,20 @@ xcoff_symfile_read (objfile, section_offset, mainline)
   free_debugsection ();
 
   /* Sort symbols alphabetically within each block.  */
-  sort_all_symtab_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);
+
+  do_cleanups (back_to);
 }
 
 /* XCOFF-specific parsing routine for section offsets.  */
@@ -2221,12 +2193,20 @@ xcoff_symfile_offsets (objfile, addr)
   
   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 */
This page took 0.039243 seconds and 4 git commands to generate.