* hppa-tdep.c (hppa_push_arguments): Allocate enough space for
[deliverable/binutils-gdb.git] / gdb / dbxread.c
index 3f9334b579b537cfd8d1ffbe16f79892317f790e..4c33fe611c49984c4afad8821dc0f22ea2df6d5e 100644 (file)
@@ -1,5 +1,6 @@
 /* Read dbx symbol tables and convert to internal format, for GDB.
-   Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
+   Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -37,8 +38,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #if defined(USG) || defined(__CYGNUSCLIB__)
 #include <sys/types.h>
 #include <fcntl.h>
-#define L_SET 0
-#define L_INCR 1
 #endif
 
 #include <obstack.h>
@@ -67,6 +66,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "aout/aout64.h"
 #include "aout/stab_gnu.h"     /* We always use GNU stabs, not native, now */
 
+#if !defined (SEEK_SET)
+#define SEEK_SET 0
+#define SEEK_CUR 1
+#endif
+
 /* Each partial symbol table entry contains a pointer to private data for the
    read_symtab() function to use when expanding a partial symbol table entry
    to a full symbol table entry.
@@ -165,6 +169,9 @@ struct complaint string_table_offset_complaint =
 struct complaint unknown_symtype_complaint =
   {"unknown symbol type %s", 0, 0};
 
+struct complaint unknown_symchar_complaint =
+  {"unknown symbol type character `%c'", 0, 0};
+
 struct complaint lbrac_rbrac_complaint =
   {"block start larger than block end", 0, 0};
 
@@ -208,9 +215,8 @@ init_header_files PARAMS ((void));
 static struct pending *
 copy_pending PARAMS ((struct pending *, int, struct pending *));
 
-static struct symtab *
-read_ofile_symtab PARAMS ((struct objfile *, int, int, CORE_ADDR, int, 
-                          struct section_offsets *));
+static void
+read_ofile_symtab PARAMS ((struct partial_symtab *));
 
 static void
 dbx_psymtab_to_symtab PARAMS ((struct partial_symtab *));
@@ -452,7 +458,7 @@ dbx_symfile_read (objfile, section_offsets, mainline)
   int val;
 
   sym_bfd = objfile->obfd;
-  val = bfd_seek (objfile->obfd, DBX_SYMTAB_OFFSET (objfile), L_SET);
+  val = bfd_seek (objfile->obfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
   if (val < 0)
     perror_with_name (objfile->name);
 
@@ -561,40 +567,62 @@ dbx_symfile_init (objfile)
 
   if (STRING_TABLE_OFFSET == 0)
     {
+      /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
+        will never be zero, even when there is no string table.  This
+        would appear to be a bug in bfd. */
       DBX_STRINGTAB_SIZE (objfile) = 0;
       DBX_STRINGTAB (objfile) = NULL;
     }
   else
     {
-      val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
+      val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
       if (val < 0)
        perror_with_name (name);
       
       memset ((PTR) size_temp, 0, sizeof (size_temp));
       val = bfd_read ((PTR) size_temp, sizeof (size_temp), 1, sym_bfd);
       if (val < 0)
-       perror_with_name (name);
-      
-      DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
-      
-      if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
-         || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
-       error ("ridiculous string table size (%d bytes).",
-              DBX_STRINGTAB_SIZE (objfile));
-      
-      DBX_STRINGTAB (objfile) =
-       (char *) obstack_alloc (&objfile -> psymbol_obstack,
-                               DBX_STRINGTAB_SIZE (objfile));
-      
-      /* Now read in the string table in one big gulp.  */
-      
-      val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
-      if (val < 0)
-       perror_with_name (name);
-      val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1,
-                     sym_bfd);
-      if (val != DBX_STRINGTAB_SIZE (objfile))
-       perror_with_name (name);
+       {
+         perror_with_name (name);
+       }
+      else if (val == 0)
+       {
+         /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
+            EOF if there is no string table, and attempting to read the size
+            from EOF will read zero bytes. */
+         DBX_STRINGTAB_SIZE (objfile) = 0;
+         DBX_STRINGTAB (objfile) = NULL;
+       }
+      else
+       {
+         /* Read some data that would appear to be the string table size.
+            If there really is a string table, then it is probably the right
+            size.  Byteswap if necessary and validate the size.  Note that
+            the minimum is DBX_STRINGTAB_SIZE_SIZE.  If we just read some
+            random data that happened to be at STRING_TABLE_OFFSET, because
+            bfd can't tell us there is no string table, the sanity checks may
+            or may not catch this. */
+         DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
+         
+         if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
+             || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
+           error ("ridiculous string table size (%d bytes).",
+                  DBX_STRINGTAB_SIZE (objfile));
+         
+         DBX_STRINGTAB (objfile) =
+           (char *) obstack_alloc (&objfile -> psymbol_obstack,
+                                   DBX_STRINGTAB_SIZE (objfile));
+         
+         /* Now read in the string table in one big gulp.  */
+         
+         val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
+         if (val < 0)
+           perror_with_name (name);
+         val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1,
+                         sym_bfd);
+         if (val != DBX_STRINGTAB_SIZE (objfile))
+           perror_with_name (name);
+       }
     }
 }
 
@@ -1128,7 +1156,7 @@ end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
 
       subpst->readin = 0;
       subpst->symtab = 0;
-      subpst->read_symtab = dbx_psymtab_to_symtab;
+      subpst->read_symtab = pst->read_symtab;
     }
 
   sort_pst_symbols (pst);
@@ -1207,11 +1235,8 @@ dbx_psymtab_to_symtab_1 (pst)
       symbol_size = SYMBOL_SIZE (pst);
 
       /* Read in this file's symbols */
-      bfd_seek (pst->objfile->obfd, SYMBOL_OFFSET (pst), L_SET);
-      pst->symtab =
-       read_ofile_symtab (pst->objfile, LDSYMOFF(pst), LDSYMLEN(pst),
-                          pst->textlow, pst->texthigh - pst->textlow,
-                          pst->section_offsets);
+      bfd_seek (pst->objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET);
+      read_ofile_symtab (pst);
       sort_symtab_syms (pst->symtab);
 
       do_cleanups (old_chain);
@@ -1265,26 +1290,11 @@ dbx_psymtab_to_symtab (pst)
     }
 }
 
-/* Read in a defined section of a specific object file's symbols.
+/* Read in a defined section of a specific object file's symbols. */
   
-   DESC is the file descriptor for the file, positioned at the
-   beginning of the symtab
-   SYM_OFFSET is the offset within the file of
-   the beginning of the symbols we want to read
-   SYM_SIZE is the size of the symbol info to read in.
-   TEXT_OFFSET is the beginning of the text segment we are reading symbols for
-   TEXT_SIZE is the size of the text segment read in.
-   SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
-
-static struct symtab *
-read_ofile_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
-                  section_offsets)
-     struct objfile *objfile;
-     int sym_offset;
-     int sym_size;
-     CORE_ADDR text_offset;
-     int text_size;
-     struct section_offsets *section_offsets;
+static void
+read_ofile_symtab (pst)
+     struct partial_symtab *pst;
 {
   register char *namestring;
   register struct internal_nlist *bufp;
@@ -1292,6 +1302,19 @@ read_ofile_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
   unsigned max_symnum;
   register bfd *abfd;
   struct symtab *rtn;
+  struct objfile *objfile;
+  int sym_offset;              /* Offset to start of symbols to read */
+  int sym_size;                        /* Size of symbols to read */
+  CORE_ADDR text_offset;       /* Start of text segment for symbols */
+  int text_size;               /* Size of text segment for symbols */
+  struct section_offsets *section_offsets;
+
+  objfile = pst->objfile;
+  sym_offset = LDSYMOFF(pst);
+  sym_size = LDSYMLEN(pst);
+  text_offset = pst->textlow;
+  text_size = pst->texthigh - pst->textlow;
+  section_offsets = pst->section_offsets;
 
   current_objfile = objfile;
   subfile_stack = NULL;
@@ -1311,7 +1334,7 @@ read_ofile_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
      would slow down initial readin, so we look for it here instead.  */
   if (!processing_acc_compilation && sym_offset >= (int)symbol_size)
     {
-      bfd_seek (symfile_bfd, sym_offset - symbol_size, L_INCR);
+      bfd_seek (symfile_bfd, sym_offset - symbol_size, SEEK_CUR);
       fill_symbuf (abfd);
       bufp = &symbuf[symbuf_idx++];
       SWAP_SYMBOL (bufp, abfd);
@@ -1332,12 +1355,10 @@ read_ofile_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
 
       if (processing_gcc_compilation)
        {
-#if 1    /* Works, but is experimental.  -fnf */
          if (AUTO_DEMANGLING)
            {
              set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
            }
-#endif
        }
     }
   else
@@ -1345,7 +1366,7 @@ read_ofile_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
       /* The N_SO starting this symtab is the first symbol, so we
         better not check the symbol before it.  I'm not this can
         happen, but it doesn't hurt to check for it.  */
-      bfd_seek (symfile_bfd, sym_offset, L_INCR);
+      bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
       processing_gcc_compilation = 0;
     }
 
@@ -1390,12 +1411,10 @@ read_ofile_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
          else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
            processing_gcc_compilation = 2;
 
-#if 1    /* Works, but is experimental.  -fnf */
          if (AUTO_DEMANGLING)
            {
              set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
            }
-#endif
        }
       else if (type & N_EXT || type == (unsigned char)N_TEXT
               || type == (unsigned char)N_NBTEXT
@@ -1421,10 +1440,11 @@ read_ofile_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
   if (last_source_start_addr == 0)
     last_source_start_addr = text_offset;
 
-  rtn = end_symtab (text_offset + text_size, 0, 0, objfile);
+  pst->symtab = end_symtab (text_offset + text_size, 0, 0, objfile,
+                           SECT_OFF_TEXT);
   end_stabs ();
-  return (rtn);
 }
+
 \f
 /* This handles a single symbol from the symbol-file, building symbols
    into a GDB symtab.  It takes these arguments and an implicit argument.
@@ -1448,12 +1468,17 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
      struct section_offsets *section_offsets;
      struct objfile *objfile;
 {
-#ifndef SUN_FIXED_LBRAC_BUG
+#ifdef SUN_FIXED_LBRAC_BUG
+  /* If SUN_FIXED_LBRAC_BUG is defined, then it tells us whether we need
+     to correct the address of N_LBRAC's.  If it is not defined, then
+     we never need to correct the addresses.  */
+
   /* This records the last pc address we've seen.  We depend on there being
      an SLINE or FUN or SO before the first LBRAC, since the variable does
      not get reset in between reads of different symbol files.  */
   static CORE_ADDR last_pc_address;
 #endif
+
   register struct context_stack *new;
   /* This remembers the address of the start of a function.  It is used
      because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries are
@@ -1463,25 +1488,35 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
   static CORE_ADDR function_start_offset;
   char *colon_pos;
 
-#ifndef        BLOCK_ADDRESS_FUNCTION_RELATIVE
-  /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
-     function start address, so just use the text offset.  */
-  function_start_offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
-#endif
+  /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are relative
+     to the function start address.  */
+  int block_address_function_relative;
+
+  /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this source
+     file.  */
+  int n_opt_found;
+
+  /* This is true for Solaris (and all other stabs-in-elf systems, hopefully,
+     since it would be silly to do things differently from Solaris), and
+     false for SunOS4 and other a.out file formats.  */
+  block_address_function_relative =
+    0 == strncmp (bfd_get_target (objfile->obfd), "elf", 3);
+
+  if (!block_address_function_relative)
+    /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
+       function start address, so just use the text offset.  */
+    function_start_offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
 
   /* Something is wrong if we see real data before
      seeing a source file name.  */
 
   if (last_source_file == NULL && type != (unsigned char)N_SO)
     {
-      /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
-        where that code is defined.  */
-      if (IGNORE_SYMBOL (type))
-       return;
-
-      /* FIXME, this should not be an error, since it precludes extending
-         the symbol table information in this way...  */
-      error ("Invalid symbol data: does not start by identifying a source file.");
+      /* Ignore any symbols which appear before an N_SO symbol.  Currently
+        no one puts symbols there, but we should deal gracefully with the
+        case.  A complain()t might be in order (if !IGNORE_SYMBOL (type)),
+        but this should not be an error ().  */
+      return;
     }
 
   switch (type)
@@ -1515,18 +1550,17 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
          break;
        }
 
-#ifndef SUN_FIXED_LBRAC_BUG
+#ifdef SUN_FIXED_LBRAC_BUG
       last_pc_address = valu;  /* Save for SunOS bug circumcision */
 #endif
 
-#ifdef BLOCK_ADDRESS_FUNCTION_RELATIVE
-      /* On Solaris 2.0 compilers, the block addresses and N_SLINE's
-        are relative to the start of the function.  On normal systems,
-        and when using gcc on Solaris 2.0, these addresses are just
-        absolute, or relative to the N_SO, depending on
-        BLOCK_ADDRESS_ABSOLUTE.  */
-      function_start_offset = valu;    
-#endif
+      if (block_address_function_relative)
+       /* On Solaris 2.0 compilers, the block addresses and N_SLINE's
+          are relative to the start of the function.  On normal systems,
+          and when using gcc on Solaris 2.0, these addresses are just
+          absolute, or relative to the N_SO, depending on
+          BLOCK_ADDRESS_ABSOLUTE.  */
+       function_start_offset = valu;   
 
       within_function = 1;
       if (context_stack_depth > 0)
@@ -1548,17 +1582,21 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
       /* This "symbol" just indicates the start of an inner lexical
         context within a function.  */
 
-#if defined(BLOCK_ADDRESS_ABSOLUTE) || defined(BLOCK_ADDRESS_FUNCTION_RELATIVE)
-      /* Relocate for dynamic loading and Sun ELF acc fn-relative syms.  */
+#if defined(BLOCK_ADDRESS_ABSOLUTE)
+      /* Relocate for dynamic loading (?).  */
       valu += function_start_offset;
 #else
-      /* On most machines, the block addresses are relative to the
-        N_SO, the linker did not relocate them (sigh).  */
-      valu += last_source_start_addr;
+      if (block_address_function_relative)
+       /* Relocate for Sun ELF acc fn-relative syms.  */
+       valu += function_start_offset;
+      else
+       /* On most machines, the block addresses are relative to the
+          N_SO, the linker did not relocate them (sigh).  */
+       valu += last_source_start_addr;
 #endif
 
-#ifndef SUN_FIXED_LBRAC_BUG
-      if (valu < last_pc_address) {
+#ifdef SUN_FIXED_LBRAC_BUG
+      if (!SUN_FIXED_LBRAC_BUG && valu < last_pc_address) {
        /* Patch current LBRAC pc value to match last handy pc value */
        complain (&lbrac_complaint);
        valu = last_pc_address;
@@ -1571,13 +1609,17 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
       /* This "symbol" just indicates the end of an inner lexical
         context that was started with N_LBRAC.  */
 
-#if defined(BLOCK_ADDRESS_ABSOLUTE) || defined(BLOCK_ADDRESS_FUNCTION_RELATIVE)
-      /* Relocate for dynamic loading and Sun ELF acc fn-relative syms.  */
+#if defined(BLOCK_ADDRESS_ABSOLUTE)
+      /* Relocate for dynamic loading (?).  */
       valu += function_start_offset;
 #else
-      /* On most machines, the block addresses are relative to the
-        N_SO, the linker did not relocate them (sigh).  */
-      valu += last_source_start_addr;
+      if (block_address_function_relative)
+       /* Relocate for Sun ELF acc fn-relative syms.  */
+       valu += function_start_offset;
+      else
+       /* On most machines, the block addresses are relative to the
+          N_SO, the linker did not relocate them (sigh).  */
+       valu += last_source_start_addr;
 #endif
 
       new = pop_context();
@@ -1645,10 +1687,12 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
       /* Relocate for dynamic loading */
       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
 
-#ifndef SUN_FIXED_LBRAC_BUG
+      n_opt_found = 0;
+
+#ifdef SUN_FIXED_LBRAC_BUG
       last_pc_address = valu;  /* Save for SunOS bug circumcision */
 #endif
-  
+
 #ifdef PCC_SOL_BROKEN
       /* pcc bug, occasionally puts out SO for SOL.  */
       if (context_stack_depth > 0)
@@ -1668,7 +1712,7 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
              patch_subfile_names (current_subfile, name);
              break;            /* Ignore repeated SOs */
            }
-         end_symtab (valu, 0, 0, objfile);
+         end_symtab (valu, 0, 0, objfile, SECT_OFF_TEXT);
          end_stabs ();
        }
       start_stabs ();
@@ -1706,7 +1750,7 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
         Enter it in the line list for this symbol table.  */
       /* Relocate for dynamic loading and for ELF acc fn-relative syms.  */
       valu += function_start_offset;
-#ifndef SUN_FIXED_LBRAC_BUG
+#ifdef SUN_FIXED_LBRAC_BUG
       last_pc_address = valu;  /* Save for SunOS bug circumcision */
 #endif
       record_line (current_subfile, desc, valu);
@@ -1714,8 +1758,12 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
 
     case N_BCOMM:
       if (common_block)
-       error ("Invalid symbol data: common within common at symtab pos %d",
-              symnum);
+       {
+         static struct complaint msg = {
+           "Invalid symbol data: common within common at symtab pos %d",
+           0, 0};
+         complain (&msg, symnum);
+       }
       common_block = local_symbols;
       common_block_i = local_symbols ? local_symbols->nsyms : 0;
       break;
@@ -1828,6 +1876,8 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
                }
 #endif
            }
+         else
+           n_opt_found = 1;
        }
       break;
 
@@ -1864,23 +1914,30 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
 }
 \f
 /* Copy a pending list, used to record the contents of a common
-   block for later fixup.  */
+   block for later fixup.  We copy the symbols starting with all
+   symbols in BEG, and ending with the symbols which are in 
+   END at index ENDI.  */
 static struct pending *
-copy_pending (beg, begi, end)
+copy_pending (beg, endi, end)
     struct pending *beg;
-    int begi;
+    int endi;
     struct pending *end;
 {
   struct pending *new = 0;
   struct pending *next;
+  int j;
 
-  for (next = beg; next != 0 && (next != end || begi < end->nsyms);
-       next = next->next, begi = 0)
+  /* Copy all the struct pendings before end.  */
+  for (next = beg; next != NULL && next != end; next = next->next)
     {
-      register int j;
-      for (j = begi; j < next->nsyms; j++)
+      for (j = 0; j < next->nsyms; j++)
        add_symbol_to_list (next->symbol[j], &new);
     }
+
+  /* Copy however much of END we need.  */
+  for (j = endi; j < end->nsyms; j++)
+    add_symbol_to_list (end->symbol[j], &new);
+
   return new;
 }
 \f
@@ -1943,7 +2000,7 @@ elfstab_build_psymtabs (objfile, section_offsets, mainline,
 
   /* Now read in the string table in one big gulp.  */
 
-  val = bfd_seek (sym_bfd, stabstroffset, L_SET);
+  val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
   if (val < 0)
     perror_with_name (name);
   val = bfd_read (DBX_STRINGTAB (objfile), stabstrsize, 1, sym_bfd);
This page took 0.030757 seconds and 4 git commands to generate.