*** empty log message ***
[binutils-gdb.git] / gdb / elfread.c
index 9a2a1e3bd820c9df7411b48f99ad5ca22a61ce41..ae92ff65b19dd19f9580bc2e03190e4e6c91ac1a 100644 (file)
 #include "gdb-stabs.h"
 #include "complaints.h"
 #include "demangle.h"
+#include "psympriv.h"
 
 extern void _initialize_elfread (void);
 
+/* Forward declaration.  */
+static struct sym_fns elf_sym_fns_gdb_index;
+
 /* The struct elfinfo is available only during ELF symbol table and
    psymtab reading.  It is destroyed at the completion of psymtab-reading.
    It's local to elf_symfile_read.  */
@@ -222,7 +226,6 @@ elf_symtab_read (struct objfile *objfile, int type,
                 int copy_names)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
-  long storage_needed;
   asymbol *sym;
   long i;
   CORE_ADDR symaddr;
@@ -425,6 +428,7 @@ elf_symtab_read (struct objfile *objfile, int type,
                  /* Named Local variable in a Data section.
                     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);
                  else if (strcmp ("Ddata.data", sym->name) == 0)
@@ -617,9 +621,7 @@ build_id_verify (const char *filename, struct build_id *check)
   else
     retval = 1;
 
-  if (!bfd_close (abfd))
-    warning (_("cannot close \"%s\": %s"), filename,
-            bfd_errmsg (bfd_get_error ()));
+  gdb_bfd_close_or_warn (abfd);
 
   xfree (found);
 
@@ -689,14 +691,6 @@ build_id_to_debug_filename (struct build_id *build_id)
 static char *
 find_separate_debug_file_by_buildid (struct objfile *objfile)
 {
-  asection *sect;
-  char *basename, *name_copy, *debugdir;
-  char *dir = NULL;
-  char *debugfile = NULL;
-  char *canon_name = NULL;
-  bfd_size_type debuglink_size;
-  unsigned long crc32;
-  int i;
   struct build_id *build_id;
 
   build_id = build_id_bfd_get (objfile->obfd);
@@ -753,7 +747,6 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
   bfd *abfd = objfile->obfd;
   struct elfinfo ei;
   struct cleanup *back_to;
-  CORE_ADDR offset;
   long symcount = 0, dynsymcount = 0, synthcount, storage_needed;
   asymbol **symbol_table = NULL, **dyn_symbol_table = NULL;
   asymbol *synthsyms;
@@ -879,15 +872,9 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
                                str_sect->filepos,
                                bfd_section_size (abfd, str_sect));
     }
-  if (dwarf2_has_info (objfile))
-    {
-      /* DWARF 2 sections */
-      dwarf2_build_psymtabs (objfile);
-    }
 
-  /* FIXME: kettenis/20030504: This still needs to be integrated with
-     dwarf2read.c in a better way.  */
-  dwarf2_build_frame_info (objfile);
+  if (dwarf2_has_info (objfile) && dwarf2_initialize_objfile (objfile))
+    objfile->sf = &elf_sym_fns_gdb_index;
 
   /* If the file has its own symbol tables it has no separate debug info.
      `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to SYMTABS/PSYMTABS.
@@ -904,6 +891,7 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
       if (debugfile)
        {
          bfd *abfd = symfile_bfd_open (debugfile);
+
          symbol_file_add_separate (abfd, symfile_flags, objfile);
          xfree (debugfile);
        }
@@ -1058,6 +1046,25 @@ static struct sym_fns elf_sym_fns =
                                   a file.  */
   NULL,                         /* sym_read_linetable */
   default_symfile_relocate,    /* sym_relocate: Relocate a debug section.  */
+  &psym_functions,
+  NULL                         /* next: pointer to next struct sym_fns */
+};
+
+/* The same as elf_sym_fns, but not registered and uses the
+   DWARF-specific GNU index rather than psymtab.  */
+static struct sym_fns elf_sym_fns_gdb_index =
+{
+  bfd_target_elf_flavour,
+  elf_new_init,                        /* sym_new_init: init anything gbl to entire symab */
+  elf_symfile_init,            /* sym_init: read initial info, setup for sym_red() */
+  elf_symfile_read,            /* sym_read: read a symbol file into symtab */
+  elf_symfile_finish,          /* sym_finish: finished with file, cleanup */
+  default_symfile_offsets,     /* sym_offsets:  Translate ext. to int. relocatin */
+  elf_symfile_segments,                /* sym_segments: Get segment information from
+                                  a file.  */
+  NULL,                         /* sym_read_linetable */
+  default_symfile_relocate,    /* sym_relocate: Relocate a debug section.  */
+  &dwarf2_gdb_index_functions,
   NULL                         /* next: pointer to next struct sym_fns */
 };