2005-05-22 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / elfread.c
index 75384a5020c4a1979e85d6da9fc20ae36d7b0556..70a825fb42f88f0cdcd45ad11e7740a92c3c847a 100644 (file)
@@ -1,7 +1,7 @@
 /* Read ELF (Executable and Linking Format) object files for GDB.
 
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
    Written by Fred Fish at Cygnus Support.
 
@@ -80,40 +80,40 @@ elf_locate_sections (bfd *ignore_abfd, asection *sectp, void *eip)
   struct elfinfo *ei;
 
   ei = (struct elfinfo *) eip;
-  if (STREQ (sectp->name, ".debug"))
+  if (strcmp (sectp->name, ".debug") == 0)
     {
       ei->dboffset = sectp->filepos;
-      ei->dbsize = bfd_get_section_size_before_reloc (sectp);
+      ei->dbsize = bfd_get_section_size (sectp);
     }
-  else if (STREQ (sectp->name, ".line"))
+  else if (strcmp (sectp->name, ".line") == 0)
     {
       ei->lnoffset = sectp->filepos;
-      ei->lnsize = bfd_get_section_size_before_reloc (sectp);
+      ei->lnsize = bfd_get_section_size (sectp);
     }
-  else if (STREQ (sectp->name, ".stab"))
+  else if (strcmp (sectp->name, ".stab") == 0)
     {
       ei->stabsect = sectp;
     }
-  else if (STREQ (sectp->name, ".stab.index"))
+  else if (strcmp (sectp->name, ".stab.index") == 0)
     {
       ei->stabindexsect = sectp;
     }
-  else if (STREQ (sectp->name, ".mdebug"))
+  else if (strcmp (sectp->name, ".mdebug") == 0)
     {
       ei->mdebugsect = sectp;
     }
 }
 
 static struct minimal_symbol *
-record_minimal_symbol_and_info (char *name, CORE_ADDR address,
-                               enum minimal_symbol_type ms_type, char *info,   /* FIXME, is this really char *? */
-                               asection *bfd_section, struct objfile *objfile)
+record_minimal_symbol (char *name, CORE_ADDR address,
+                      enum minimal_symbol_type ms_type,
+                      asection *bfd_section, struct objfile *objfile)
 {
   if (ms_type == mst_text || ms_type == mst_file_text)
     address = SMASH_TEXT_ADDRESS (address);
 
   return prim_record_minimal_symbol_and_info
-    (name, address, ms_type, info, bfd_section->index, bfd_section, objfile);
+    (name, address, ms_type, NULL, bfd_section->index, bfd_section, objfile);
 }
 
 /*
@@ -159,11 +159,10 @@ elf_symtab_read (struct objfile *objfile, int dynamic)
      seen any section info for it yet.  */
   asymbol *filesym = 0;
 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
-  /* Name of filesym, as saved on the symbol_obstack.  */
-  char *filesymname = obsavestring ("", 0, &objfile->symbol_obstack);
+  /* Name of filesym, as saved on the objfile_obstack.  */
+  char *filesymname = obsavestring ("", 0, &objfile->objfile_obstack);
 #endif
-  struct dbx_symfile_info *dbx = objfile->sym_stab_info;
-  unsigned long size;
+  struct dbx_symfile_info *dbx = objfile->deprecated_sym_stab_info;
   int stripped = (bfd_get_symcount (objfile->obfd) == 0);
 
   if (dynamic)
@@ -178,7 +177,7 @@ elf_symtab_read (struct objfile *objfile, int dynamic)
     {
       storage_needed = bfd_get_symtab_upper_bound (objfile->obfd);
       if (storage_needed < 0)
-       error ("Can't read symbols from %s: %s", bfd_get_filename (objfile->obfd),
+       error (_("Can't read symbols from %s: %s"), bfd_get_filename (objfile->obfd),
               bfd_errmsg (bfd_get_error ()));
     }
   if (storage_needed > 0)
@@ -191,7 +190,7 @@ elf_symtab_read (struct objfile *objfile, int dynamic)
       else
        number_of_symbols = bfd_canonicalize_symtab (objfile->obfd, symbol_table);
       if (number_of_symbols < 0)
-       error ("Can't read symbols from %s: %s", bfd_get_filename (objfile->obfd),
+       error (_("Can't read symbols from %s: %s"), bfd_get_filename (objfile->obfd),
               bfd_errmsg (bfd_get_error ()));
 
       for (i = 0; i < number_of_symbols; i++)
@@ -223,9 +222,9 @@ elf_symtab_read (struct objfile *objfile, int dynamic)
              if (symaddr == 0)
                continue;
              symaddr += offset;
-             msym = record_minimal_symbol_and_info
+             msym = record_minimal_symbol
                ((char *) sym->name, symaddr,
-                mst_solib_trampoline, NULL, sym->section, objfile);
+                mst_solib_trampoline, sym->section, objfile);
 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
              if (msym != NULL)
                msym->filename = filesymname;
@@ -252,9 +251,11 @@ elf_symtab_read (struct objfile *objfile, int dynamic)
 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
              filesymname =
                obsavestring ((char *) filesym->name, strlen (filesym->name),
-                             &objfile->symbol_obstack);
+                             &objfile->objfile_obstack);
 #endif
            }
+         else if (sym->flags & BSF_SECTION_SYM)
+           continue;
          else if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK))
            {
              struct minimal_symbol *msym;
@@ -343,10 +344,7 @@ elf_symtab_read (struct objfile *objfile, int dynamic)
                  else if (sym->flags & BSF_LOCAL)
                    {
                      /* Named Local variable in a Data section.
-                        Check its name for stabs-in-elf.  The STREQ
-                        macro checks the first character inline, so
-                        we only actually do a strcmp function call on
-                        names that start with 'B' or 'D'.  */
+                        Check its name for stabs-in-elf.  */
                      int special_local_sect;
                      if (strcmp ("Bbss.bss", sym->name) == 0)
                        special_local_sect = SECT_OFF_BSS (objfile);
@@ -381,13 +379,13 @@ elf_symtab_read (struct objfile *objfile, int dynamic)
                                      + (sizeof (CORE_ADDR)
                                         * max_index));
                              sectinfo = (struct stab_section_info *)
-                               xmmalloc (objfile->md, size);
+                               xmalloc (size);
                              memset (sectinfo, 0, size);
                              sectinfo->num_sections = max_index;
                              if (filesym == NULL)
                                {
                                  complaint (&symfile_complaints,
-                                            "elf/stab section information %s without a preceding file symbol",
+                                            _("elf/stab section information %s without a preceding file symbol"),
                                             sym->name);
                                }
                              else
@@ -398,7 +396,7 @@ elf_symtab_read (struct objfile *objfile, int dynamic)
                            }
                          if (sectinfo->sections[special_local_sect] != 0)
                            complaint (&symfile_complaints,
-                                      "duplicated elf/stab section information for %s",
+                                      _("duplicated elf/stab section information for %s"),
                                       sectinfo->filename);
                          /* BFD symbols are section relative.  */
                          symaddr = sym->value + sym->section->vma;
@@ -436,11 +434,15 @@ elf_symtab_read (struct objfile *objfile, int dynamic)
                  /* ms_type = mst_unknown; */
                  continue;     /* Skip this symbol. */
                }
-             /* Pass symbol size field in via BFD.  FIXME!!!  */
-             size = ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
-             msym = record_minimal_symbol_and_info
+             msym = record_minimal_symbol
                ((char *) sym->name, symaddr,
-                ms_type, (void *) size, sym->section, objfile);
+                ms_type, sym->section, objfile);
+             if (msym)
+             {
+               /* Pass symbol size field in via BFD.  FIXME!!!  */
+               unsigned long size = ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
+               MSYMBOL_SIZE(msym) = size;
+             }
 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
              if (msym != NULL)
                msym->filename = filesymname;
@@ -498,13 +500,13 @@ elf_symfile_read (struct objfile *objfile, int mainline)
   memset ((char *) &ei, 0, sizeof (ei));
 
   /* Allocate struct to keep track of the symfile */
-  objfile->sym_stab_info = (struct dbx_symfile_info *)
-    xmmalloc (objfile->md, sizeof (struct dbx_symfile_info));
-  memset ((char *) objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info));
+  objfile->deprecated_sym_stab_info = (struct dbx_symfile_info *)
+    xmalloc (sizeof (struct dbx_symfile_info));
+  memset ((char *) objfile->deprecated_sym_stab_info, 0, sizeof (struct dbx_symfile_info));
   make_cleanup (free_elfinfo, (void *) objfile);
 
   /* Process the normal ELF symbol table first.  This may write some 
-     chain of info into the dbx_symfile_info in objfile->sym_stab_info,
+     chain of info into the dbx_symfile_info in objfile->deprecated_sym_stab_info,
      which can later be used by elfstab_offset_sections.  */
 
   elf_symtab_read (objfile, 0);
@@ -575,7 +577,7 @@ elf_symfile_read (struct objfile *objfile, int mainline)
                                str_sect->filepos,
                                bfd_section_size (abfd, str_sect));
     }
-  if (dwarf2_has_info (abfd))
+  if (dwarf2_has_info (objfile))
     {
       /* DWARF 2 sections */
       dwarf2_build_psymtabs (objfile, mainline);
@@ -594,21 +596,22 @@ elf_symfile_read (struct objfile *objfile, int mainline)
   dwarf2_build_frame_info (objfile);
 }
 
-/* This cleans up the objfile's sym_stab_info pointer, and the chain of
-   stab_section_info's, that might be dangling from it.  */
+/* This cleans up the objfile's deprecated_sym_stab_info pointer, and
+   the chain of stab_section_info's, that might be dangling from
+   it.  */
 
 static void
 free_elfinfo (void *objp)
 {
   struct objfile *objfile = (struct objfile *) objp;
-  struct dbx_symfile_info *dbxinfo = objfile->sym_stab_info;
+  struct dbx_symfile_info *dbxinfo = objfile->deprecated_sym_stab_info;
   struct stab_section_info *ssi, *nssi;
 
   ssi = dbxinfo->stab_section_info;
   while (ssi)
     {
       nssi = ssi->next;
-      xmfree (objfile->md, ssi);
+      xfree (ssi);
       ssi = nssi;
     }
 
@@ -637,9 +640,9 @@ elf_new_init (struct objfile *ignore)
 static void
 elf_symfile_finish (struct objfile *objfile)
 {
-  if (objfile->sym_stab_info != NULL)
+  if (objfile->deprecated_sym_stab_info != NULL)
     {
-      xmfree (objfile->md, objfile->sym_stab_info);
+      xfree (objfile->deprecated_sym_stab_info);
     }
 }
 
@@ -673,7 +676,7 @@ void
 elfstab_offset_sections (struct objfile *objfile, struct partial_symtab *pst)
 {
   char *filename = pst->filename;
-  struct dbx_symfile_info *dbx = objfile->sym_stab_info;
+  struct dbx_symfile_info *dbx = objfile->deprecated_sym_stab_info;
   struct stab_section_info *maybe = dbx->stab_section_info;
   struct stab_section_info *questionable = 0;
   int i;
@@ -690,7 +693,7 @@ elfstab_offset_sections (struct objfile *objfile, struct partial_symtab *pst)
   for (; maybe; maybe = maybe->next)
     {
       if (filename[0] == maybe->filename[0]
-         && STREQ (filename, maybe->filename))
+         && strcmp (filename, maybe->filename) == 0)
        {
          /* We found a match.  But there might be several source files
             (from different directories) with the same name.  */
@@ -703,7 +706,7 @@ elfstab_offset_sections (struct objfile *objfile, struct partial_symtab *pst)
   if (maybe == 0 && questionable != 0)
     {
       complaint (&symfile_complaints,
-                "elf/stab section information questionable for %s", filename);
+                _("elf/stab section information questionable for %s"), filename);
       maybe = questionable;
     }
 
@@ -712,7 +715,7 @@ elfstab_offset_sections (struct objfile *objfile, struct partial_symtab *pst)
       /* Found it!  Allocate a new psymtab struct, and fill it in.  */
       maybe->found++;
       pst->section_offsets = (struct section_offsets *)
-       obstack_alloc (&objfile->psymbol_obstack, 
+       obstack_alloc (&objfile->objfile_obstack, 
                       SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
       for (i = 0; i < maybe->num_sections; i++)
        (pst->section_offsets)->offsets[i] = maybe->sections[i];
@@ -722,7 +725,7 @@ elfstab_offset_sections (struct objfile *objfile, struct partial_symtab *pst)
   /* We were unable to find any offsets for this file.  Complain.  */
   if (dbx->stab_section_info)  /* If there *is* any info, */
     complaint (&symfile_complaints,
-              "elf/stab section information missing for %s", filename);
+              _("elf/stab section information missing for %s"), filename);
 }
 \f
 /* Register that we are able to handle ELF object file formats.  */
This page took 0.027973 seconds and 4 git commands to generate.