use remote-utils facilities for baud_rate
[deliverable/binutils-gdb.git] / gdb / xcoffread.c
index ef5cc080394f8129d23f03ac7a1515e678271769..c6a138aeaaabb91e3dabff58d2234c7154e29907 100644 (file)
@@ -53,12 +53,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #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 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 */
+/* For interface with stabsread.c.  */
+#include "aout/stab_gnu.h"
 
 /* Simplified internal version of coff symbol table information */
 
@@ -188,6 +184,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));
 
@@ -231,54 +230,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;
 }
@@ -286,6 +295,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)
@@ -403,10 +414,10 @@ struct coff_symbol *cs;
       /* In xcoff, we assume include files cannot be nested (not in .c files
         of course, but in corresponding .s files.).  */
 
-      /* 14 Apr 93: A user said he got this message, but said he'd deleted
-        the test case.  I changed it from a fatal() to a complain()
-        and changed the wording.  */
-      struct complaint msg = {"Nested C_BINCL symbols", 0, 0};
+      /* 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;
@@ -415,7 +426,7 @@ struct coff_symbol *cs;
   if (inclLength == 0) {
     inclTable = (InclTable*) 
        xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
-    bzero (inclTable, sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
+    memset (inclTable, '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
     inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
     inclIndx = 0;
   }
@@ -423,8 +434,8 @@ struct coff_symbol *cs;
     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);
+    memset (inclTable+inclLength-INITIAL_INCLUDE_TABLE_LENGTH, 
+                       '\0', sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH);
   }
 
   inclTable [inclIndx].name  = cs->c_name;
@@ -440,7 +451,7 @@ 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);
     }
 
@@ -479,7 +490,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)
@@ -508,7 +519,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. */
@@ -608,7 +619,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
@@ -706,7 +717,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. */
@@ -1151,14 +1162,16 @@ read_xcoff_symtab (objfile, nsyms)
            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) {
 
@@ -1179,7 +1192,9 @@ 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'. */
@@ -1390,60 +1405,6 @@ function_entry_point:
 
        within_function = 1;
 
-       /* 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 */
-
-       /* 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_linenos() will do this sorting.         
-
-
-            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);
@@ -1596,7 +1557,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;
@@ -1639,116 +1600,10 @@ process_xcoff_symbol (cs, objfile)
 
     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);
@@ -1772,7 +1627,7 @@ process_xcoff_symbol (cs, objfile)
         /* FIXME: I believe this is to avoid a Sun-specific hack somewhere.
           Needs more investigation.  */
 
-       if (*name == ':' || (pp = (char *) index (name, ':')) == NULL)
+       if (*name == ':' || (pp = (char *) strchr(name, ':')) == NULL)
          return NULL;
 
        ++pp;
@@ -1786,16 +1641,12 @@ process_xcoff_symbol (cs, objfile)
        return sym;
 
     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_SECTION (sym) = cs->c_secnum;
-       SYMBOL_DUP (sym, sym2);
-       add_symbol_to_list (sym2, &local_symbols);
-       break;
+      sym = define_symbol (cs->c_value, cs->c_name, 0, N_LSYM, objfile);
+      if (sym != NULL)
+       {
+         SYMBOL_SECTION (sym) = cs->c_secnum;
+       }
+      return sym;
 
     case C_AUTO:
       SYMBOL_CLASS (sym) = LOC_LOCAL;
@@ -1860,7 +1711,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;
@@ -1971,6 +1822,8 @@ init_lineno (abfd, offset, size)
 {
   int val;
 
+  free_linetab ();
+
   if (bfd_seek(abfd, offset, L_SET) < 0)
     return -1;
 
@@ -1982,9 +1835,16 @@ init_lineno (abfd, offset, size)
 
   linetab_offset = offset;
   linetab_size = size;
-  make_cleanup (free, linetab);        /* Be sure it gets de-allocated. */
   return 0;
 }
+
+static void
+free_linetab ()
+{
+  if (linetab)
+    free (linetab);
+  linetab = NULL;
+}
 \f
 /* dbx allows the text of a symbol name to be continued into the
    next symbol name!  When such a continuation is encountered
@@ -2084,7 +1944,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;
 
@@ -2150,6 +2010,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;
@@ -2169,6 +2030,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));
 
@@ -2220,6 +2082,8 @@ xcoff_symfile_read (objfile, section_offset, mainline)
      minimal symbols for this objfile. */
 
   install_minimal_symbols (objfile);
+
+  do_cleanups (back_to);
 }
 
 /* XCOFF-specific parsing routine for section offsets.  */
This page took 0.032004 seconds and 4 git commands to generate.