2002-07-29 Andrew Cagney <ac131313@redhat.com>
[deliverable/binutils-gdb.git] / gdb / mdebugread.c
index c9e3490a5c53821a6409b29697bf63ccc4dc292d..d920f8dae86682d79f4029f1eff679ea476d6d3b 100644 (file)
@@ -1,6 +1,6 @@
 /* Read a symbol table in ECOFF format (Third-Eye).
    Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
-   1997, 1998, 1999, 2000, 2001
+   1997, 1998, 1999, 2000, 2001, 2002
    Free Software Foundation, Inc.
    Original version contributed by Alessandro Forin (af@cs.cmu.edu) at
    CMU.  Major work by Per Bothner, John Gilmore and Ian Lance Taylor
 #include "gdbcore.h"
 #include "symfile.h"
 #include "objfiles.h"
-#include "obstack.h"
+#include "gdb_obstack.h"
 #include "buildsym.h"
 #include "stabsread.h"
 #include "complaints.h"
 #include "demangle.h"
+#include "gdb_assert.h"
 
 /* These are needed if the tm.h file does not contain the necessary
    mips specific definitions.  */
@@ -143,7 +144,8 @@ struct symloc
                   || (sc) == scPData \
                   || (sc) == scXData)
 #define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon)
-#define SC_IS_BSS(sc) ((sc) == scBss || (sc) == scSBss)
+#define SC_IS_BSS(sc) ((sc) == scBss)
+#define SC_IS_SBSS(sc) ((sc) == scSBss)
 #define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined)
 \f
 /* Various complaints about symbol reading that don't abort the process */
@@ -327,30 +329,15 @@ static int found_ecoff_debugging_info;
 
 /* Forward declarations */
 
-static void add_pending (FDR *, char *, struct type *);
-
-static struct mdebug_pending *is_pending_symbol (FDR *, char *);
-
-static void pop_parse_stack (void);
-
-static void push_parse_stack (void);
-
-static char *fdr_name (FDR *);
-
-static void mdebug_psymtab_to_symtab (struct partial_symtab *);
-
-static int
-upgrade_type (int, struct type **, int, union aux_ext *, int, char *);
+static int upgrade_type (int, struct type **, int, union aux_ext *,
+                        int, char *);
 
 static void parse_partial_symbols (struct objfile *);
 
-static FDR * get_rfd (int, int);
-
 static int has_opaque_xref (FDR *, SYMR *);
 
-static int
-cross_ref (int, union aux_ext *, struct type **, enum type_code,
-          char **, int, char *);
+static int cross_ref (int, union aux_ext *, struct type **, enum type_code,
+                     char **, int, char *);
 
 static struct symbol *new_symbol (char *);
 
@@ -364,10 +351,6 @@ static struct linetable *new_linetable (int);
 
 static struct blockvector *new_bvect (int);
 
-static int
-parse_symbol (SYMR *, union aux_ext *, char *, int, struct section_offsets *,
-             struct objfile *);
-
 static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
                                int, char *);
 
@@ -376,12 +359,8 @@ static struct symbol *mylookup_symbol (char *, struct block *, namespace_enum,
 
 static struct block *shrink_block (struct block *, struct symtab *);
 
-static PTR xzalloc (unsigned int);
-
 static void sort_blocks (struct symtab *);
 
-static int compare_blocks (const PTR, const PTR);
-
 static struct partial_symtab *new_psymtab (char *, struct objfile *);
 
 static void psymtab_to_symtab_1 (struct partial_symtab *, char *);
@@ -394,8 +373,8 @@ static int add_line (struct linetable *, int, CORE_ADDR, int);
 
 static struct linetable *shrink_linetable (struct linetable *);
 
-static void
-handle_psymbol_enumerators (struct objfile *, FDR *, int, CORE_ADDR);
+static void handle_psymbol_enumerators (struct objfile *, FDR *, int,
+                                       CORE_ADDR);
 
 static char *mdebug_next_symbol_text (struct objfile *);
 \f
@@ -405,10 +384,10 @@ CORE_ADDR sigtramp_address, sigtramp_end;
 
 /* Allocate zeroed memory */
 
-static PTR
+static void *
 xzalloc (unsigned int size)
 {
-  PTR p = xmalloc (size);
+  void *p = xmalloc (size);
 
   memset (p, 0, size);
   return p;
@@ -698,7 +677,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
              struct section_offsets *section_offsets, struct objfile *objfile)
 {
   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
-  void (*const swap_sym_in) (bfd *, PTR, SYMR *) = debug_swap->swap_sym_in;
+  void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
   char *name;
   struct symbol *s;
   struct block *b;
@@ -854,7 +833,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
       else
        {
          t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
-         if (STREQ (name, "malloc") && t->code == TYPE_CODE_VOID)
+         if (STREQ (name, "malloc") && TYPE_CODE (t) == TYPE_CODE_VOID)
            {
              /* I don't know why, but, at least under Alpha GNU/Linux,
                 when linking against a malloc without debugging
@@ -1137,7 +1116,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
                enum_sym = ((struct symbol *)
                            obstack_alloc (&current_objfile->symbol_obstack,
                                           sizeof (struct symbol)));
-               memset ((PTR) enum_sym, 0, sizeof (struct symbol));
+               memset (enum_sym, 0, sizeof (struct symbol));
                SYMBOL_NAME (enum_sym) =
                  obsavestring (f->name, strlen (f->name),
                                &current_objfile->symbol_obstack);
@@ -1235,7 +1214,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
          e = ((struct mips_extra_func_info *)
               obstack_alloc (&current_objfile->symbol_obstack,
                              sizeof (struct mips_extra_func_info)));
-         memset ((PTR) e, 0, sizeof (struct mips_extra_func_info));
+         memset (e, 0, sizeof (struct mips_extra_func_info));
          SYMBOL_VALUE (s) = (long) e;
          e->numargs = top_stack->numargs;
          e->pdr.framereg = -1;
@@ -1282,6 +1261,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
                        case LOC_REGPARM:
                        case LOC_REGPARM_ADDR:
                          TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
+                         TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
                          iparams++;
                          break;
                        default:
@@ -1625,7 +1605,7 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
          dereference them.  */
       while (TYPE_CODE (tp) == TYPE_CODE_PTR
             || TYPE_CODE (tp) == TYPE_CODE_ARRAY)
-       tp = tp->target_type;
+       tp = TYPE_TARGET_TYPE (tp);
 
       /* Make sure that TYPE_CODE(tp) has an expected type code.
          Any type may be returned from cross_ref if file indirect entries
@@ -2229,9 +2209,9 @@ parse_partial_symbols (struct objfile *objfile)
   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
   const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
   const bfd_size_type external_ext_size = debug_swap->external_ext_size;
-  void (*const swap_ext_in) (bfd *, PTR, EXTR *) = debug_swap->swap_ext_in;
-  void (*const swap_sym_in) (bfd *, PTR, SYMR *) = debug_swap->swap_sym_in;
-  void (*const swap_rfd_in) (bfd *, PTR, RFDT *) = debug_swap->swap_rfd_in;
+  void (*const swap_ext_in) (bfd *, void *, EXTR *) = debug_swap->swap_ext_in;
+  void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
+  void (*const swap_rfd_in) (bfd *, void *, RFDT *) = debug_swap->swap_rfd_in;
   int f_idx, s_idx;
   HDRR *hdr = &debug_info->symbolic_header;
   /* Running pointers */
@@ -2318,7 +2298,7 @@ parse_partial_symbols (struct objfile *objfile)
     ((struct mdebug_pending **)
      obstack_alloc (&objfile->psymbol_obstack,
                    hdr->ifdMax * sizeof (struct mdebug_pending *)));
-  memset ((PTR) pending_list, 0,
+  memset (pending_list, 0,
          hdr->ifdMax * sizeof (struct mdebug_pending *));
 
   /* Pass 0 over external syms: swap them in.  */
@@ -2447,26 +2427,72 @@ parse_partial_symbols (struct objfile *objfile)
              ms_type = mst_bss;
              svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
            }
+          else if (SC_IS_SBSS (ext_in->asym.sc))
+            {
+              ms_type = mst_bss;
+              svalue += ANOFFSET (objfile->section_offsets, 
+                                  get_section_index (objfile, ".sbss"));
+            }
          else
            ms_type = mst_abs;
          break;
        case stLabel:
          /* Label */
+
+          /* On certain platforms, some extra label symbols can be
+             generated by the linker. One possible usage for this kind
+             of symbols is to represent the address of the begining of a
+             given section. For instance, on Tru64 5.1, the address of
+             the _ftext label is the start address of the .text section.
+
+             The storage class of these symbols is usually directly
+             related to the section to which the symbol refers. For
+             instance, on Tru64 5.1, the storage class for the _fdata
+             label is scData, refering to the .data section.
+
+             It is actually possible that the section associated to the
+             storage class of the label does not exist. On True64 5.1
+             for instance, the libm.so shared library does not contain
+             any .data section, although it contains a _fpdata label
+             which storage class is scData... Since these symbols are
+             usually useless for the debugger user anyway, we just
+             discard these symbols.
+           */
+          
          if (SC_IS_TEXT (ext_in->asym.sc))
            {
+              if (objfile->sect_index_text == -1)
+                continue;
+                
              ms_type = mst_file_text;
              svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
            }
          else if (SC_IS_DATA (ext_in->asym.sc))
            {
+              if (objfile->sect_index_data == -1)
+                continue;
+
              ms_type = mst_file_data;
              svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
            }
          else if (SC_IS_BSS (ext_in->asym.sc))
            {
+              if (objfile->sect_index_bss == -1)
+                continue;
+
              ms_type = mst_file_bss;
              svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
            }
+          else if (SC_IS_SBSS (ext_in->asym.sc))
+            {
+              const int sbss_sect_index = get_section_index (objfile, ".sbss");
+
+              if (sbss_sect_index == -1)
+                continue;
+
+              ms_type = mst_file_bss;
+              svalue += ANOFFSET (objfile->section_offsets, sbss_sect_index);
+            }
          else
            ms_type = mst_abs;
          break;
@@ -2521,7 +2547,7 @@ parse_partial_symbols (struct objfile *objfile)
       pst->read_symtab_private = ((char *)
                                  obstack_alloc (&objfile->psymbol_obstack,
                                                 sizeof (struct symloc)));
-      memset ((PTR) pst->read_symtab_private, 0, sizeof (struct symloc));
+      memset (pst->read_symtab_private, 0, sizeof (struct symloc));
 
       save_pst = pst;
       TEXTLOW (pst) = pst->textlow;
@@ -2706,8 +2732,10 @@ parse_partial_symbols (struct objfile *objfile)
                     && stabstring != debug_info->ss + fh->issBase + sh.iss)
                      stabstring = xrealloc (stabstring, len + len2 + 1);
                    else
-                     stabstring = xmalloc (len + len2 + 1);
-                   strcpy (stabstring, stabstring1);
+                     {
+                       stabstring = xmalloc (len + len2 + 1);
+                       strcpy (stabstring, stabstring1);
+                     }
                    strcpy (stabstring + len, stabstring2);
                    len += len2;
                  }
@@ -3670,7 +3698,7 @@ handle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype,
                            CORE_ADDR svalue)
 {
   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
-  void (*const swap_sym_in) (bfd *, PTR, SYMR *) = debug_swap->swap_sym_in;
+  void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
   char *ext_sym = ((char *) debug_info->external_sym
                   + ((fh->isymBase + cur_sdx + 1) * external_sym_size));
   SYMR sh;
@@ -3761,8 +3789,8 @@ psymtab_to_symtab_1 (struct partial_symtab *pst, char *filename)
 {
   bfd_size_type external_sym_size;
   bfd_size_type external_pdr_size;
-  void (*swap_sym_in) (bfd *, PTR, SYMR *);
-  void (*swap_pdr_in) (bfd *, PTR, PDR *);
+  void (*swap_sym_in) (bfd *, void *, SYMR *);
+  void (*swap_pdr_in) (bfd *, void *, PDR *);
   int i;
   struct symtab *st = NULL;
   FDR *fh;
@@ -3915,7 +3943,7 @@ psymtab_to_symtab_1 (struct partial_symtab *pst, char *filename)
                                  sizeof (struct mips_extra_func_info)));
                  struct symbol *s = new_symbol (MIPS_EFI_SYMBOL_NAME);
 
-                 memset ((PTR) e, 0, sizeof (struct mips_extra_func_info));
+                 memset (e, 0, sizeof (struct mips_extra_func_info));
                  SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
                  SYMBOL_CLASS (s) = LOC_CONST;
                  SYMBOL_TYPE (s) = mdebug_type_void;
@@ -4234,8 +4262,7 @@ cross_ref (int fd, union aux_ext *ax, struct type **tpp, enum type_code type_cod
   if (rf == -1)
     {
       *pname = "<undefined>";
-      *tpp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
-      TYPE_FLAGS (*tpp) |= TYPE_FLAG_STUB;
+      *tpp = init_type (type_code, 0, TYPE_FLAG_STUB, (char *) NULL, current_objfile);
       return result;
     }
 
@@ -4465,7 +4492,7 @@ add_block (struct block *b, struct symtab *s)
 {
   struct blockvector *bv = BLOCKVECTOR (s);
 
-  bv = (struct blockvector *) xrealloc ((PTR) bv,
+  bv = (struct blockvector *) xrealloc ((void *) bv,
                                        (sizeof (struct blockvector)
                                         + BLOCKVECTOR_NBLOCKS (bv)
                                         * sizeof (bv->block)));
@@ -4513,7 +4540,7 @@ add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last)
 /* Blocks with a smaller low bound should come first */
 
 static int
-compare_blocks (const PTR arg1, const PTR arg2)
+compare_blocks (const void *arg1, const void *arg2)
 {
   register int addr_diff;
   struct block **b1 = (struct block **) arg1;
@@ -4615,7 +4642,7 @@ new_psymtab (char *name, struct objfile *objfile)
   psymtab->read_symtab_private = ((char *)
                                  obstack_alloc (&objfile->psymbol_obstack,
                                                 sizeof (struct symloc)));
-  memset ((PTR) psymtab->read_symtab_private, 0, sizeof (struct symloc));
+  memset (psymtab->read_symtab_private, 0, sizeof (struct symloc));
   CUR_BFD (psymtab) = cur_bfd;
   DEBUG_SWAP (psymtab) = debug_swap;
   DEBUG_INFO (psymtab) = debug_info;
@@ -4652,7 +4679,7 @@ static struct linetable *
 shrink_linetable (struct linetable *lt)
 {
 
-  return (struct linetable *) xrealloc ((PTR) lt,
+  return (struct linetable *) xrealloc ((void *) lt,
                                        (sizeof (struct linetable)
                                         + ((lt->nitems - 1)
                                            * sizeof (lt->item))));
@@ -4696,11 +4723,16 @@ shrink_block (struct block *b, struct symtab *s)
 
   /* Just reallocate it and fix references to the old one */
 
-  new = (struct block *) xrealloc ((PTR) b,
+  new = (struct block *) xrealloc ((void *) b,
                                   (sizeof (struct block)
                                    + ((BLOCK_NSYMS (b) - 1)
                                       * sizeof (struct symbol *))));
 
+  /* FIXME: Not worth hashing this block as it's built.  */
+  /* All callers should have created the block with new_block (), which
+     would mean it was not previously hashed.  Make sure.  */
+  gdb_assert (BLOCK_HASHTABLE (new) == 0);
+
   /* Should chase pointers to old one.  Fortunately, that`s just
      the block`s function and inferior blocks */
   if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b)
@@ -4722,7 +4754,7 @@ new_symbol (char *name)
                      obstack_alloc (&current_objfile->symbol_obstack,
                                     sizeof (struct symbol)));
 
-  memset ((PTR) s, 0, sizeof (*s));
+  memset (s, 0, sizeof (*s));
   SYMBOL_NAME (s) = obsavestring (name, strlen (name),
                                  &current_objfile->symbol_obstack);
   SYMBOL_LANGUAGE (s) = psymtab_language;
This page took 0.029925 seconds and 4 git commands to generate.