* configure.tgt (mips64*vr4320*el-*-elf*) : Removed spurious case.
[deliverable/binutils-gdb.git] / gdb / hpread.c
index b31d9723a5c59e85075aac2bdd058d04737ccf11..0e4174600eeb0881a63da0b1eb9aa8b4c861e45a 100644 (file)
@@ -1,5 +1,5 @@
 /* Read hp debug symbols and convert to internal format, for GDB.
-   Copyright 1993 Free Software Foundation, Inc.
+   Copyright 1993, 1996 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
    Written by the Center for Software Science at the University of Utah
    and by Cygnus Support.  */
 
 #include "defs.h"
 #include "bfd.h"
-#include <string.h>
+#include "gdb_string.h"
 #include "hp-symtab.h"
 #include "syms.h"
 #include "symtab.h"
@@ -32,6 +32,7 @@
 #include "complaints.h"
 #include "gdb-stabs.h"
 #include "gdbtypes.h"
+#include "demangle.h"
 
 /* Private information attached to an objfile which we use to find
    and internalize the HP C debug symbols within that objfile.  */
@@ -99,29 +100,30 @@ struct hpread_symfile_info
     } \
   else \
     *NAMEP = (SYM)->dsfile.name + VT (OBJFILE)
-
-/* 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.
-
-   For hpuxread this structure contains the offset within the file symbol table
-   of first local symbol for this file, and length (in bytes) of the section
-   of the symbol table devoted to this file's symbols (actually, the section
-   bracketed may contain more than just this file's symbols).
-
-   If ldsymlen is 0, the only reason for this thing's existence is the
-   dependency list.  Nothing else will happen when it is read in.  */
-
-#define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
-#define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
-#define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
+\f
+/* We put a pointer to this structure in the read_symtab_private field
+   of the psymtab.  */
 
 struct symloc
 {
+  /* The offset within the file symbol table of first local symbol for
+     this file.  */
+
   int ldsymoff;
+
+  /* Length (in bytes) of the section of the symbol table devoted to
+     this file's symbols (actually, the section bracketed may contain
+     more than just this file's symbols).  If ldsymlen is 0, the only
+     reason for this thing's existence is the dependency list.
+     Nothing else will happen when it is read in.  */
+
   int ldsymlen;
 };
 
+#define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
+#define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
+#define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
+\f
 /* FIXME: Shouldn't this stuff be in a .h file somewhere?  */
 /* Nonzero means give verbose info on gdb action.  */
 extern int info_verbose;
@@ -134,6 +136,9 @@ extern struct complaint lbrac_mismatch_complaint;
 \f
 void hpread_symfile_init  PARAMS ((struct objfile *));
 
+static struct type *
+hpread_read_array_type PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
+
 static struct type *hpread_alloc_type
   PARAMS ((dnttpointer, struct objfile *));
 
@@ -159,7 +164,7 @@ void hpread_symfile_finish PARAMS ((struct objfile *));
 
 static struct partial_symtab *hpread_start_psymtab
   PARAMS ((struct objfile *, struct section_offsets *, char *, CORE_ADDR, int,
-          struct partial_symbol *, struct partial_symbol *));
+          struct partial_symbol **, struct partial_symbol **));
 
 static struct partial_symtab *hpread_end_psymtab
   PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
@@ -174,7 +179,8 @@ static void hpread_process_one_debug_symbol
           struct objfile *, CORE_ADDR, int, char *, int));
 
 static sltpointer hpread_record_lines
-  PARAMS ((struct subfile *, sltpointer, sltpointer, struct objfile *));
+  PARAMS ((struct subfile *, sltpointer, sltpointer,
+          struct objfile *, CORE_ADDR));
 
 static struct type *hpread_read_function_type
   PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
@@ -334,7 +340,7 @@ hpread_build_psymtabs (objfile, section_offsets, mainline)
   int dependencies_used, dependencies_allocated;
 
   /* Just in case the stabs reader left turds lying around.  */
-  pending_blocks = 0;
+  free_pending_blocks ();
   make_cleanup (really_free_pendings, 0);
 
   pst = (struct partial_symtab *) 0;
@@ -448,7 +454,6 @@ hpread_build_psymtabs (objfile, section_offsets, mainline)
 
                if (pst && past_first_source_file)
                  {
-                   texthigh += ANOFFSET (section_offsets, SECT_OFF_TEXT);
                    hpread_end_psymtab (pst, psymtab_include_list,
                                        includes_used,
                                        (hp_symnum
@@ -498,15 +503,17 @@ hpread_build_psymtabs (objfile, section_offsets, mainline)
            case DNTT_TYPE_ENTRY:
              /* The beginning of a function.  DNTT_TYPE_ENTRY may also denote
                 a secondary entry point.  */
+             valu = dn_bufp->dfunc.hiaddr + ANOFFSET (section_offsets,
+                                                      SECT_OFF_TEXT);
+             if (valu > texthigh)
+               texthigh = valu;
              valu = dn_bufp->dfunc.lowaddr +
                ANOFFSET (section_offsets, SECT_OFF_TEXT);
-             if (dn_bufp->dfunc.hiaddr > texthigh)
-               texthigh = dn_bufp->dfunc.hiaddr;
              SET_NAMESTRING (dn_bufp, &namestring, objfile);
-             ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
+             add_psymbol_to_list (namestring, strlen (namestring),
                                   VAR_NAMESPACE, LOC_BLOCK,
-                                  objfile->static_psymbols, valu,
-                                  language_unknown, objfile);
+                                  &objfile->static_psymbols, valu,
+                                  0, language_unknown, objfile);
              within_function = 1;
              continue;
            case DNTT_TYPE_BEGIN:
@@ -515,7 +522,6 @@ hpread_build_psymtabs (objfile, section_offsets, mainline)
                 and file blocks right now.  */
              if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
                {
-                 texthigh += ANOFFSET (section_offsets, SECT_OFF_TEXT);
                  hpread_end_psymtab (pst, psymtab_include_list, includes_used,
                                      (hp_symnum
                                       * sizeof (struct dntt_type_block)),
@@ -536,7 +542,7 @@ hpread_build_psymtabs (objfile, section_offsets, mainline)
              {
                /* Variables, typedefs an the like.  */
                enum address_class storage;
-               enum namespace namespace;
+               namespace_enum namespace;
 
                /* Don't add locals to the partial symbol table.  */
                if (within_function
@@ -573,19 +579,19 @@ hpread_build_psymtabs (objfile, section_offsets, mainline)
                  }
                if (dn_bufp->dsvar.global)
                  {
-                   ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
+                   add_psymbol_to_list (namestring, strlen (namestring),
                                         namespace, storage,
-                                        objfile->global_psymbols,
+                                        &objfile->global_psymbols,
                                         dn_bufp->dsvar.location,
-                                        language_unknown, objfile);
+                                        0, language_unknown, objfile);
                  }
                else
                  {
-                   ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
+                   add_psymbol_to_list (namestring, strlen (namestring),
                                         namespace, storage,
-                                        objfile->static_psymbols,
+                                        &objfile->static_psymbols,
                                         dn_bufp->dsvar.location,
-                                        language_unknown, objfile);
+                                        0, language_unknown, objfile);
                  }
                continue;
              }
@@ -602,10 +608,10 @@ hpread_build_psymtabs (objfile, section_offsets, mainline)
                                              objfile->global_psymbols.next,
                                              objfile->static_psymbols.next);
                }
-             ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
+             add_psymbol_to_list (namestring, strlen (namestring),
                                   VAR_NAMESPACE, LOC_CONST,
-                                  objfile->static_psymbols, 0,
-                                  language_unknown, objfile);
+                                  &objfile->static_psymbols, 0,
+                                  0, language_unknown, objfile);
              continue;
            default:
              continue;
@@ -700,7 +706,7 @@ hpread_get_textlow (global, index, objfile)
     return 0;
 
   /* The minimal symbols are typically more accurate for some reason.  */
-  msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile),
+  msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
                                   objfile);
   if (msymbol)
     return SYMBOL_VALUE_ADDRESS (msymbol);
@@ -825,8 +831,8 @@ hpread_start_psymtab (objfile, section_offsets,
      char *filename;
      CORE_ADDR textlow;
      int ldsymoff;
-     struct partial_symbol *global_syms;
-     struct partial_symbol *static_syms;
+     struct partial_symbol **global_syms;
+     struct partial_symbol **static_syms;
 {
   struct partial_symtab *result =
   start_psymtab_common (objfile, section_offsets,
@@ -932,21 +938,8 @@ hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
         is wrong, in that a psymtab with N_SLINE entries but nothing else
         is not empty, but we don't realize that.  Fixing that without slowing
         things down might be tricky.  */
-      struct partial_symtab *prev_pst;
-
-      /* First, snip it out of the psymtab chain */
 
-      if (pst->objfile->psymtabs == pst)
-       pst->objfile->psymtabs = pst->next;
-      else
-       for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
-         if (prev_pst->next == pst)
-           prev_pst->next = pst->next;
-
-      /* Next, put it on a free list for recycling */
-
-      pst->next = pst->objfile->free_psymtabs;
-      pst->objfile->free_psymtabs = pst;
+      discard_psymtab (pst);
 
       /* Indicate that psymtab was thrown away.  */
       pst = (struct partial_symtab *)NULL;
@@ -1089,7 +1082,10 @@ hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
   dn_bufp = hpread_get_lntt (sym_index, objfile);
   if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
        (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
-    start_symtab ("globals", NULL, 0);
+    {
+      start_symtab ("globals", NULL, 0);
+      record_debugformat ("HP");
+    }
 
   max_symnum = sym_size / sizeof (struct dntt_type_block);
 
@@ -1114,7 +1110,7 @@ hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
 
   current_objfile = NULL;
 
-  return end_symtab (text_offset + text_size, 0, 0, objfile, 0);
+  return end_symtab (text_offset + text_size, objfile, 0);
 }
 \f
 
@@ -1213,12 +1209,14 @@ hpread_lookup_type (hp_type, objfile)
            {
              TYPE_VECTOR_LENGTH (objfile) = 100;
              TYPE_VECTOR (objfile) = (struct type **)
-               malloc (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
+               xmmalloc (objfile -> md,
+                         TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
            }
          while (index >= TYPE_VECTOR_LENGTH (objfile))
            TYPE_VECTOR_LENGTH (objfile) *= 2;
          TYPE_VECTOR (objfile) = (struct type **)
-           xrealloc ((char *) TYPE_VECTOR (objfile),
+           xmrealloc (objfile -> md,
+                      (char *) TYPE_VECTOR (objfile),
                      (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
          memset (&TYPE_VECTOR (objfile)[old_len], 0,
                  (TYPE_VECTOR_LENGTH (objfile) - old_len) *
@@ -1284,7 +1282,8 @@ hpread_read_enum_type (hp_type, dn_bufp, objfile)
       sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
                                             sizeof (struct symbol));
       memset (sym, 0, sizeof (struct symbol));
-      SYMBOL_NAME (sym) = name;
+      SYMBOL_NAME (sym) = obsavestring (name, strlen (name), 
+                                       &objfile->symbol_obstack);
       SYMBOL_CLASS (sym) = LOC_CONST;
       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
       SYMBOL_VALUE (sym) = memp->dmember.value;
@@ -1318,7 +1317,6 @@ hpread_read_enum_type (hp_type, dn_bufp, objfile)
          struct symbol *xsym = syms->symbol[j];
          SYMBOL_TYPE (xsym) = type;
          TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
-         TYPE_FIELD_VALUE (type, n) = 0;
          TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
          TYPE_FIELD_BITSIZE (type, n) = 0;
        }
@@ -1375,7 +1373,8 @@ hpread_read_function_type (hp_type, dn_bufp, objfile)
       sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
                                             sizeof (struct symbol));
       (void) memset (sym, 0, sizeof (struct symbol));
-      SYMBOL_NAME (sym) = name;
+      SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
+                                       &objfile->symbol_obstack);
 
       /* Figure out where it lives.  */
       if (paramp->dfparam.regparam)
@@ -1494,14 +1493,15 @@ hpread_read_struct_type (hp_type, dn_bufp, objfile)
       list = new;
 
       list->field.name = VT (objfile) + fieldp->dfield.name;
-      list->field.bitpos = fieldp->dfield.bitoffset;
+      FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
       if (fieldp->dfield.bitlength % 8)
-       list->field.bitsize = fieldp->dfield.bitlength;
+       FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
       else
-       list->field.bitsize = 0;
+       FIELD_BITSIZE (list->field) = 0;
       nfields++;
       field = fieldp->dfield.nextfield;
-      list->field.type = hpread_type_lookup (fieldp->dfield.type, objfile);
+      FIELD_TYPE (list->field) = hpread_type_lookup (fieldp->dfield.type,
+                                                    objfile);
     }
 
   TYPE_NFIELDS (type) = nfields;
@@ -1602,8 +1602,9 @@ hpread_read_subrange_type (hp_type, dn_bufp, objfile)
   TYPE_CODE (type) = TYPE_CODE_RANGE;
   TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
   TYPE_NFIELDS (type) = 2;
-  TYPE_FIELDS (type) = (struct field *) obstack_alloc
-    (&objfile->type_obstack, 2 * sizeof (struct field));
+  TYPE_FIELDS (type)
+    = (struct field *) obstack_alloc (&objfile->type_obstack,
+                                     2 * sizeof (struct field));
 
   if (dn_bufp->dsubr.dyn_low)
     TYPE_FIELD_BITPOS (type, 0) = 0;
@@ -1738,10 +1739,11 @@ hpread_type_lookup (hp_type, objfile)
 }
 
 static sltpointer
-hpread_record_lines (subfile, s_idx, e_idx, objfile)
+hpread_record_lines (subfile, s_idx, e_idx, objfile, offset)
      struct subfile *subfile;
      sltpointer s_idx, e_idx;
      struct objfile *objfile;
+     CORE_ADDR offset;
 {
   union sltentry *sl_bufp;
 
@@ -1751,7 +1753,8 @@ hpread_record_lines (subfile, s_idx, e_idx, objfile)
       /* Only record "normal" entries in the SLT.  */
       if (sl_bufp->snorm.sltdesc == SLT_NORMAL
          || sl_bufp->snorm.sltdesc == SLT_EXIT)
-       record_line (subfile, sl_bufp->snorm.line, sl_bufp->snorm.address);
+       record_line (subfile, sl_bufp->snorm.line,
+                    sl_bufp->snorm.address + offset);
       s_idx++;
     }
   return e_idx;
@@ -1784,7 +1787,7 @@ hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
   sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
                                         sizeof (struct symbol));
   memset (sym, 0, sizeof (struct symbol));
-  SYMBOL_NAME (sym) = name;
+  SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
   SYMBOL_LANGUAGE (sym) = language_auto;
   SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
   SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
@@ -1808,14 +1811,20 @@ hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
          finish the symbol table of the previous source file
          (if any) and start accumulating a new symbol table.  */
 
-      valu = text_offset + offset;     /* Relocate for dynamic loading */
+      valu = text_offset;
       if (!last_source_file)
-       start_symtab (name, NULL, valu);
-
-      SL_INDEX (objfile) = hpread_record_lines (current_subfile,
-                                               SL_INDEX (objfile),
-                                               dn_bufp->dsfile.address,
-                                               objfile);
+       {
+         start_symtab (name, NULL, valu);
+         record_debugformat ("HP");
+         SL_INDEX (objfile) = dn_bufp->dsfile.address;
+       }
+      else
+       {
+         SL_INDEX (objfile) = hpread_record_lines (current_subfile,
+                                                   SL_INDEX (objfile),
+                                                   dn_bufp->dsfile.address,
+                                                   objfile, offset);
+       }
       start_subfile (name, NULL);
       break;
       
@@ -1830,7 +1839,7 @@ hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
       SL_INDEX (objfile) = hpread_record_lines (current_subfile,
                                                SL_INDEX (objfile),
                                                dn_bufp->dfunc.address,
-                                               objfile);
+                                               objfile, offset);
       
       WITHIN_FUNCTION (objfile) = 1;
       CURRENT_FUNCTION_VALUE (objfile) = valu;
@@ -1858,7 +1867,7 @@ hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
       SL_INDEX (objfile) = hpread_record_lines (current_subfile,
                                                SL_INDEX (objfile),
                                                dn_bufp->dbegin.address,
-                                               objfile);
+                                               objfile, offset);
       SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
       record_line (current_subfile, SYMBOL_LINE (sym), valu);
       break;
@@ -1868,7 +1877,7 @@ hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
       SL_INDEX (objfile) = hpread_record_lines (current_subfile,
                                                SL_INDEX (objfile),
                                                dn_bufp->dbegin.address,
-                                               objfile);
+                                               objfile, offset);
       valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
       valu += offset;          /* Relocate for dynamic loading */
       desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
@@ -1880,13 +1889,13 @@ hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
       SL_INDEX (objfile) = hpread_record_lines (current_subfile,
                                                SL_INDEX (objfile),
                                                dn_bufp->dend.address + 1,
-                                               objfile);
+                                               objfile, offset);
       switch (dn_bufp->dend.endkind)
        {
        case DNTT_TYPE_MODULE:
          /* Ending a module ends the symbol table for that module.  */
          valu = text_offset + text_size + offset;
-         (void) end_symtab (valu, 0, 0, objfile, 0);
+         (void) end_symtab (valu, objfile, 0);
          break;
 
        case DNTT_TYPE_FUNCTION:
This page took 0.032672 seconds and 4 git commands to generate.