2004-01-09 Elena Zannoni <ezannoni@redhat.com>
[deliverable/binutils-gdb.git] / gdb / dbxread.c
index 7bdc6f52210945631abe95c774da2c7ddae8e8d1..9bcb50eda32ec54e0885691c9befa22ed8241005 100644 (file)
 #include "language.h"          /* Needed for local_hex_string */
 #include "complaints.h"
 #include "cp-abi.h"
+#include "gdb_assert.h"
 
 #include "aout/aout64.h"
 #include "aout/stab_gnu.h"     /* We always use GNU stabs, not native, now */
 \f
 
-/* This macro returns the size field of a minimal symbol, which is normally
-   stored in the "info" field.  The macro can be overridden for specific
-   targets (e.g. MIPS16) that use the info field for other purposes.  */
-#ifndef MSYMBOL_SIZE
-#define MSYMBOL_SIZE(msym) ((long) MSYMBOL_INFO (msym))
-#endif
-
-
 /* We put a pointer to this structure in the read_symtab_private field
    of the psymtab.  */
 
@@ -257,10 +250,6 @@ static int bincls_allocated;
 
 extern void _initialize_dbxread (void);
 
-#if 0 /* OBSOLETE CFront */
-// OBSOLETE static void process_now (struct objfile *);
-#endif /* OBSOLETE CFront */
-
 static void read_ofile_symtab (struct partial_symtab *);
 
 static void dbx_psymtab_to_symtab (struct partial_symtab *);
@@ -351,11 +340,11 @@ add_this_object_header_file (int i)
 static void
 add_old_header_file (char *name, int instance)
 {
-  register struct header_file *p = HEADER_FILES (current_objfile);
-  register int i;
+  struct header_file *p = HEADER_FILES (current_objfile);
+  int i;
 
   for (i = 0; i < N_HEADER_FILES (current_objfile); i++)
-    if (STREQ (p[i].name, name) && instance == p[i].instance)
+    if (strcmp (p[i].name, name) == 0 && instance == p[i].instance)
       {
        add_this_object_header_file (i);
        return;
@@ -377,8 +366,8 @@ add_old_header_file (char *name, int instance)
 static void
 add_new_header_file (char *name, int instance)
 {
-  register int i;
-  register struct header_file *hfile;
+  int i;
+  struct header_file *hfile;
 
   /* Make sure there is room for one more header file.  */
 
@@ -420,7 +409,7 @@ add_new_header_file (char *name, int instance)
 static struct type **
 explicit_lookup_type (int real_filenum, int index)
 {
-  register struct header_file *f = &HEADER_FILES (current_objfile)[real_filenum];
+  struct header_file *f = &HEADER_FILES (current_objfile)[real_filenum];
 
   if (index >= f->length)
     {
@@ -494,7 +483,7 @@ record_minimal_symbol (char *name, CORE_ADDR address, int type,
          Record it as global even if it's local, not global, so
          lookup_minimal_symbol can find it.  We don't check symbol_leading_char
          because for SunOS4 it always is '_'.  */
-      if (name[8] == 'C' && STREQ ("__DYNAMIC", name))
+      if (name[8] == 'C' && DEPRECATED_STREQ ("__DYNAMIC", name))
        ms_type = mst_data;
 
       /* Same with virtual function tables, both global and static.  */
@@ -751,8 +740,8 @@ dbx_symfile_finish (struct objfile *objfile)
     {
       if (HEADER_FILES (objfile) != NULL)
        {
-         register int i = N_HEADER_FILES (objfile);
-         register struct header_file *hfiles = HEADER_FILES (objfile);
+         int i = N_HEADER_FILES (objfile);
+         struct header_file *hfiles = HEADER_FILES (objfile);
 
          while (--i >= 0)
            {
@@ -772,107 +761,6 @@ static struct external_nlist symbuf[4096];
 static int symbuf_idx;
 static int symbuf_end;
 
-#if 0 /* OBSOLETE CFront */
-// OBSOLETE  /* cont_elem is used for continuing information in cfront.
-// OBSOLETE     It saves information about which types need to be fixed up and 
-// OBSOLETE     completed after all the stabs are read.  */
-// OBSOLETE  struct cont_elem
-// OBSOLETE    {
-// OBSOLETE      /* sym and stabstring for continuing information in cfront */
-// OBSOLETE      struct symbol *sym;
-// OBSOLETE      char *stabs;
-// OBSOLETE      /* state dependencies (statics that must be preserved) */
-// OBSOLETE      int sym_idx;
-// OBSOLETE      int sym_end;
-// OBSOLETE      int symnum;
-// OBSOLETE      int (*func) (struct objfile *, struct symbol *, char *);
-// OBSOLETE      /* other state dependencies include:
-// OBSOLETE         (assumption is that these will not change since process_now FIXME!!)
-// OBSOLETE         stringtab_global
-// OBSOLETE         n_stabs
-// OBSOLETE         objfile
-// OBSOLETE         symfile_bfd */
-// OBSOLETE    };
-
-// OBSOLETE  static struct cont_elem *cont_list = 0;
-// OBSOLETE  static int cont_limit = 0;
-// OBSOLETE  static int cont_count = 0;
-
-// OBSOLETE  /* Arrange for function F to be called with arguments SYM and P later
-// OBSOLETE     in the stabs reading process.  */
-// OBSOLETE  void
-// OBSOLETE  process_later (struct symbol *sym, char *p,
-// OBSOLETE           int (*f) (struct objfile *, struct symbol *, char *))
-// OBSOLETE  {
-
-// OBSOLETE    /* Allocate more space for the deferred list.  */
-// OBSOLETE    if (cont_count >= cont_limit - 1)
-// OBSOLETE      {
-// OBSOLETE        cont_limit += 32;           /* chunk size */
-
-// OBSOLETE        cont_list
-// OBSOLETE    = (struct cont_elem *) xrealloc (cont_list,
-// OBSOLETE                                     (cont_limit
-// OBSOLETE                                      * sizeof (struct cont_elem)));
-// OBSOLETE        if (!cont_list)
-// OBSOLETE    error ("Virtual memory exhausted\n");
-// OBSOLETE      }
-
-// OBSOLETE    /* Save state variables so we can process these stabs later.  */
-// OBSOLETE    cont_list[cont_count].sym_idx = symbuf_idx;
-// OBSOLETE    cont_list[cont_count].sym_end = symbuf_end;
-// OBSOLETE    cont_list[cont_count].symnum = symnum;
-// OBSOLETE    cont_list[cont_count].sym = sym;
-// OBSOLETE    cont_list[cont_count].stabs = p;
-// OBSOLETE    cont_list[cont_count].func = f;
-// OBSOLETE    cont_count++;
-// OBSOLETE  }
-
-// OBSOLETE  /* Call deferred funtions in CONT_LIST.  */
-
-// OBSOLETE  static void
-// OBSOLETE  process_now (struct objfile *objfile)
-// OBSOLETE  {
-// OBSOLETE    int i;
-// OBSOLETE    int save_symbuf_idx;
-// OBSOLETE    int save_symbuf_end;
-// OBSOLETE    int save_symnum;
-// OBSOLETE    struct symbol *sym;
-// OBSOLETE    char *stabs;
-// OBSOLETE    int err;
-// OBSOLETE    int (*func) (struct objfile *, struct symbol *, char *);
-
-// OBSOLETE    /* Save the state of our caller, we'll want to restore it before
-// OBSOLETE       returning.  */
-// OBSOLETE    save_symbuf_idx = symbuf_idx;
-// OBSOLETE    save_symbuf_end = symbuf_end;
-// OBSOLETE    save_symnum = symnum;
-
-// OBSOLETE    /* Iterate over all the deferred stabs.  */
-// OBSOLETE    for (i = 0; i < cont_count; i++)
-// OBSOLETE      {
-// OBSOLETE        /* Restore the state for this deferred stab.  */
-// OBSOLETE        symbuf_idx = cont_list[i].sym_idx;
-// OBSOLETE        symbuf_end = cont_list[i].sym_end;
-// OBSOLETE        symnum = cont_list[i].symnum;
-// OBSOLETE        sym = cont_list[i].sym;
-// OBSOLETE        stabs = cont_list[i].stabs;
-// OBSOLETE        func = cont_list[i].func;
-
-// OBSOLETE        /* Call the function to handle this deferrd stab.  */
-// OBSOLETE        err = (*func) (objfile, sym, stabs);
-// OBSOLETE        if (err)
-// OBSOLETE    error ("Internal error: unable to resolve stab.\n");
-// OBSOLETE      }
-
-// OBSOLETE    /* Restore our caller's state.  */
-// OBSOLETE    symbuf_idx = save_symbuf_idx;
-// OBSOLETE    symbuf_end = save_symbuf_end;
-// OBSOLETE    symnum = save_symnum;
-// OBSOLETE    cont_count = 0;
-// OBSOLETE  }
-#endif /* OBSOLETE CFront */
-
 /* Name of last function encountered.  Used in Solaris to approximate
    object file boundaries.  */
 static char *last_function_name;
@@ -1039,7 +927,7 @@ find_corresponding_bincl_psymtab (char *name, int instance)
 
   for (bincl = bincl_list; bincl < next_bincl; bincl++)
     if (bincl->instance == instance
-       && STREQ (name, bincl->name))
+       && strcmp (name, bincl->name) == 0)
       return bincl->pst;
 
   repeated_header_complaint (name, symnum);
@@ -1291,12 +1179,12 @@ function_outside_compilation_unit_complaint (const char *arg1)
 static void
 read_dbx_symtab (struct objfile *objfile)
 {
-  register struct external_nlist *bufp = 0;    /* =0 avoids gcc -Wall glitch */
+  struct external_nlist *bufp = 0;     /* =0 avoids gcc -Wall glitch */
   struct internal_nlist nlist;
   CORE_ADDR text_addr;
   int text_size;
 
-  register char *namestring;
+  char *namestring;
   int nsl;
   int past_first_source_file = 0;
   CORE_ADDR last_o_file_start = 0;
@@ -1304,6 +1192,7 @@ read_dbx_symtab (struct objfile *objfile)
   struct cleanup *back_to;
   bfd *abfd;
   int textlow_not_set;
+  int data_sect_index;
 
   /* Current partial symtab */
   struct partial_symtab *pst;
@@ -1355,6 +1244,38 @@ read_dbx_symtab (struct objfile *objfile)
   textlow_not_set = 1;
   has_line_numbers = 0;
 
+  /* FIXME: jimb/2003-09-12: We don't apply the right section's offset
+     to global and static variables.  The stab for a global or static
+     variable doesn't give us any indication of which section it's in,
+     so we can't tell immediately which offset in
+     objfile->section_offsets we should apply to the variable's
+     address.
+
+     We could certainly find out which section contains the variable
+     by looking up the variable's unrelocated address with
+     find_pc_section, but that would be expensive; this is the
+     function that constructs the partial symbol tables by examining
+     every symbol in the entire executable, and it's
+     performance-critical.  So that expense would not be welcome.  I'm
+     not sure what to do about this at the moment.
+
+     What we have done for years is to simply assume that the .data
+     section's offset is appropriate for all global and static
+     variables.  Recently, this was expanded to fall back to the .bss
+     section's offset if there is no .data section, and then to the
+     .rodata section's offset.  */
+  data_sect_index = objfile->sect_index_data;
+  if (data_sect_index == -1)
+    data_sect_index = SECT_OFF_BSS (objfile);
+  if (data_sect_index == -1)
+    data_sect_index = SECT_OFF_RODATA (objfile);
+
+  /* If data_sect_index is still -1, that's okay.  It's perfectly fine
+     for the file to have no .data, no .bss, and no .text at all, if
+     it also has no global or static variables.  If it does, we will
+     get an internal error from an ANOFFSET macro below when we try to
+     use data_sect_index.  */
+
   for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
     {
       /* Get the symbol for this run and pull out some info */
@@ -1442,8 +1363,8 @@ read_dbx_symtab (struct objfile *objfile)
            if (objfile->ei.entry_point < nlist.n_value &&
                objfile->ei.entry_point >= last_o_file_start)
              {
-               objfile->ei.entry_file_lowpc = last_o_file_start;
-               objfile->ei.entry_file_highpc = nlist.n_value;
+               objfile->ei.deprecated_entry_file_lowpc = last_o_file_start;
+               objfile->ei.deprecated_entry_file_highpc = nlist.n_value;
              }
            if (past_first_source_file && pst
                /* The gould NP1 uses low values for .o and -l symbols
@@ -1678,12 +1599,12 @@ read_dbx_symtab (struct objfile *objfile)
               things like "break c-exp.y:435" need to work (I
               suppose the psymtab_include_list could be hashed or put
               in a binary tree, if profiling shows this is a major hog).  */
-           if (pst && STREQ (namestring, pst->filename))
+           if (pst && strcmp (namestring, pst->filename) == 0)
            continue;
            {
-             register int i;
+             int i;
              for (i = 0; i < includes_used; i++)
-               if (STREQ (namestring, psymtab_include_list[i]))
+               if (strcmp (namestring, psymtab_include_list[i]) == 0)
                  {
                    i = -1;
                    break;
@@ -1757,7 +1678,7 @@ read_dbx_symtab (struct objfile *objfile)
          switch (p[1])
          {
          case 'S':
-           nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
+           nlist.n_value += ANOFFSET (objfile->section_offsets, data_sect_index);
 #ifdef STATIC_TRANSFORM_NAME
            namestring = STATIC_TRANSFORM_NAME (namestring);
 #endif
@@ -1768,7 +1689,7 @@ read_dbx_symtab (struct objfile *objfile)
                                 psymtab_language, objfile);
            continue;
          case 'G':
-           nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
+           nlist.n_value += ANOFFSET (objfile->section_offsets, data_sect_index);
            /* The addresses in these entries are reported to be
               wrong.  See the code that reads 'G's for symtabs. */
            add_psymbol_to_list (namestring, p - namestring,
@@ -1804,22 +1725,6 @@ read_dbx_symtab (struct objfile *objfile)
                                         psymtab_language, objfile);
                    p += 1;
                  }
-#if 0 /* OBSOLETE CFront */
-// OBSOLETE            /* The semantics of C++ state that "struct foo { ... }"
-// OBSOLETE               also defines a typedef for "foo".  Unfortuantely, cfront
-// OBSOLETE               never makes the typedef when translating from C++ to C.
-// OBSOLETE               We make the typedef here so that "ptype foo" works as
-// OBSOLETE               expected for cfront translated code.  */
-// OBSOLETE            else if (psymtab_language == language_cplus)
-// OBSOLETE              {
-// OBSOLETE                /* Also a typedef with the same name.  */
-// OBSOLETE                add_psymbol_to_list (namestring, p - namestring,
-// OBSOLETE                                     VAR_DOMAIN, LOC_TYPEDEF,
-// OBSOLETE                                     &objfile->static_psymbols,
-// OBSOLETE                                     nlist.n_value, 0,
-// OBSOLETE                                     psymtab_language, objfile);
-// OBSOLETE              }
-#endif /* OBSOLETE CFront */
              }
            goto check_enum;
          case 't':
@@ -2054,11 +1959,6 @@ read_dbx_symtab (struct objfile *objfile)
          case '9':
          case '-':
          case '#':             /* for symbol identification (used in live ranges) */
-#if 0 /* OBSOLETE CFront */
-// OBSOLETE        /* added to support cfront stabs strings */
-// OBSOLETE      case 'Z':             /* for definition continuations */
-// OBSOLETE      case 'P':             /* for prototypes */
-#endif /* OBSOLETE CFront */
            continue;
 
          case ':':
@@ -2206,8 +2106,8 @@ read_dbx_symtab (struct objfile *objfile)
       && objfile->ei.entry_point < nlist.n_value
       && objfile->ei.entry_point >= last_o_file_start)
     {
-      objfile->ei.entry_file_lowpc = last_o_file_start;
-      objfile->ei.entry_file_highpc = nlist.n_value;
+      objfile->ei.deprecated_entry_file_lowpc = last_o_file_start;
+      objfile->ei.deprecated_entry_file_highpc = nlist.n_value;
     }
 
   if (pst)
@@ -2484,7 +2384,6 @@ dbx_psymtab_to_symtab_1 (struct partial_symtab *pst)
       /* Read in this file's symbols */
       bfd_seek (pst->objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET);
       read_ofile_symtab (pst);
-      sort_symtab_syms (pst->symtab);
 
       do_cleanups (old_chain);
     }
@@ -2555,12 +2454,12 @@ dbx_psymtab_to_symtab (struct partial_symtab *pst)
 static void
 read_ofile_symtab (struct partial_symtab *pst)
 {
-  register char *namestring;
-  register struct external_nlist *bufp;
+  char *namestring;
+  struct external_nlist *bufp;
   struct internal_nlist nlist;
   unsigned char type;
   unsigned max_symnum;
-  register bfd *abfd;
+  bfd *abfd;
   struct objfile *objfile;
   int sym_offset;              /* Offset to start of symbols to read */
   int sym_size;                        /* Size of symbols to read */
@@ -2612,13 +2511,13 @@ read_ofile_symtab (struct partial_symtab *pst)
        {
          const char *tempstring = namestring;
 
-         if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
+         if (DEPRECATED_STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
            processing_gcc_compilation = 1;
-         else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
+         else if (DEPRECATED_STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
            processing_gcc_compilation = 2;
          if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd))
            ++tempstring;
-         if (STREQN (tempstring, "__gnu_compiled", 14))
+         if (DEPRECATED_STREQN (tempstring, "__gnu_compiled", 14))
            processing_gcc_compilation = 2;
        }
 
@@ -2684,9 +2583,9 @@ read_ofile_symtab (struct partial_symtab *pst)
             However, there is no reason not to accept
             the GCC_COMPILED_FLAG_SYMBOL anywhere.  */
 
-         if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
+         if (DEPRECATED_STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
            processing_gcc_compilation = 1;
-         else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
+         else if (DEPRECATED_STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
            processing_gcc_compilation = 2;
 
 #if 0
@@ -2731,11 +2630,6 @@ read_ofile_symtab (struct partial_symtab *pst)
 
   pst->symtab = end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile));
 
-#if 0 /* OBSOLETE CFront */
-// OBSOLETE    /* Process items which we had to "process_later" due to dependencies 
-// OBSOLETE       on other stabs.  */
-// OBSOLETE    process_now (objfile);
-#endif /* OBSOLETE CFront */
   end_stabs ();
 }
 \f
@@ -2772,7 +2666,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
   static CORE_ADDR last_pc_address;
 #endif
 
-  register struct context_stack *new;
+  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
      relative to the current function's start address.  On systems
@@ -3267,12 +3161,12 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
                  int l = colon_pos - name;
 
                  m = lookup_minimal_symbol_by_pc (last_pc_address);
-                 if (m && STREQN (DEPRECATED_SYMBOL_NAME (m), name, l)
+                 if (m && strncmp (DEPRECATED_SYMBOL_NAME (m), name, l) == 0
                      && DEPRECATED_SYMBOL_NAME (m)[l] == '\0')
                    /* last_pc_address was in this function */
                    valu = SYMBOL_VALUE (m);
                  else if (m && DEPRECATED_SYMBOL_NAME (m + 1)
-                          && STREQN (DEPRECATED_SYMBOL_NAME (m + 1), name, l)
+                          && strncmp (DEPRECATED_SYMBOL_NAME (m + 1), name, l) == 0
                           && DEPRECATED_SYMBOL_NAME (m + 1)[l] == '\0')
                    /* last_pc_address was in last function */
                    valu = SYMBOL_VALUE (m + 1);
@@ -3327,7 +3221,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
     case N_OPT:                /* Solaris 2:  Compiler options */
       if (name)
        {
-         if (STREQ (name, GCC2_COMPILED_FLAG_SYMBOL))
+         if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)
            {
              processing_gcc_compilation = 2;
 #if 0                          /* Works, but is experimental.  -fnf */
This page took 0.032733 seconds and 4 git commands to generate.