Replace <sys/dir.h> (and <dirent.h>) with "gdb_dirent.h".
[deliverable/binutils-gdb.git] / gdb / symfile.c
index 108695a338e6cf825649e6e8decfe58e5eff389b..6f2edf34353bc75cd504b82089168dde5dce7727 100644 (file)
@@ -72,6 +72,8 @@ void (*pre_add_symbol_hook) PARAMS ((char *));
 void (*post_add_symbol_hook) PARAMS ((void));
 void (*target_new_objfile_hook) PARAMS ((struct objfile *));
 
+static void clear_symtab_users_cleanup (void *ignore);
+
 /* Global variables owned by this file */
 int readnow_symbol_files;      /* Read full symbols immediately */
 
@@ -518,33 +520,49 @@ default_symfile_offsets (objfile, addrs)
      struct section_addr_info *addrs;
 {
   int i;
+  asection *sect = NULL;
 
   objfile->num_sections = SECT_OFF_MAX;
   objfile->section_offsets = (struct section_offsets *)
     obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
   memset (objfile->section_offsets, 0, SIZEOF_SECTION_OFFSETS);
 
-  /* Now calculate offsets for other sections. */
+  /* Now calculate offsets for section that were specified by the
+     caller. */
   for (i = 0; i < MAX_SECTIONS && addrs->other[i].name; i++)
     {
       struct other_sections *osp ;
 
       osp = &addrs->other[i] ;
-      if (addrs->other[i].addr == 0)
+      if (osp->addr == 0)
        continue;
-#if 0
-      if (strcmp (".text", osp->name) == 0)
-       SECT_OFF_TEXT = osp->sectindex ;
-      else if (strcmp (".data", osp->name) == 0)
-       SECT_OFF_DATA = osp->sectindex ;
-      else if (strcmp (".bss", osp->name) == 0)
-       SECT_OFF_BSS =  osp->sectindex ;
-#endif
+
       /* Record all sections in offsets */
+      /* The section_offsets in the objfile are here filled in using
+         the BFD index. */
       ANOFFSET (objfile->section_offsets, osp->sectindex) = osp->addr;
     }
-}
 
+  /* Remember the bfd indexes for the .text, .data, .bss and
+     .rodata sections. */
+
+  sect = bfd_get_section_by_name (objfile->obfd, ".text");
+  if (sect) 
+    objfile->sect_index_text = sect->index;
+
+  sect = bfd_get_section_by_name (objfile->obfd, ".data");
+  if (sect) 
+    objfile->sect_index_data = sect->index;
+
+  sect = bfd_get_section_by_name (objfile->obfd, ".bss");
+  if (sect) 
+    objfile->sect_index_bss = sect->index;
+
+  sect = bfd_get_section_by_name (objfile->obfd, ".rodata");
+  if (sect) 
+    objfile->sect_index_rodata = sect->index;
+
+}
 
 /* Process a symbol file, as either the main file or as a dynamically
    loaded file.
@@ -589,13 +607,13 @@ syms_from_objfile (objfile, addrs, mainline, verbo)
 
   /* Make sure that partially constructed symbol tables will be cleaned up
      if an error occurs during symbol reading.  */
-  old_chain = make_cleanup ((make_cleanup_func) free_objfile, objfile);
+  old_chain = make_cleanup_free_objfile (objfile);
 
   if (mainline)
     {
       /* We will modify the main symbol table, make sure that all its users
          will be cleaned up if an error occurs during symbol reading.  */
-      make_cleanup ((make_cleanup_func) clear_symtab_users, 0);
+      make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/);
 
       /* Since no error yet, throw away the old symbol table.  */
 
@@ -631,12 +649,12 @@ syms_from_objfile (objfile, addrs, mainline, verbo)
       if (lower_sect == NULL)
        warning ("no loadable sections found in added symbol-file %s",
                 objfile->name);
-      else if ((bfd_get_section_flags (objfile->obfd, lower_sect) & SEC_CODE)
-              == 0)
-       warning ("Lowest section in %s is %s at %s",
-                objfile->name,
-                bfd_section_name (objfile->obfd, lower_sect),
-                paddr (bfd_section_vma (objfile->obfd, lower_sect)));
+      else 
+       if ((bfd_get_section_flags (objfile->obfd, lower_sect) & SEC_CODE) == 0)
+         warning ("Lowest section in %s is %s at %s",
+                  objfile->name,
+                  bfd_section_name (objfile->obfd, lower_sect),
+                  paddr (bfd_section_vma (objfile->obfd, lower_sect)));
       if (lower_sect != NULL)
        lower_offset = bfd_section_vma (objfile->obfd, lower_sect);
       else
@@ -1214,7 +1232,7 @@ generic_load (char *args, int from_tty)
   /* FIXME: should be checking for errors from bfd_close (for one thing,
      on error it does not free all the storage associated with the
      bfd).  */
-  make_cleanup ((make_cleanup_func) bfd_close, loadfile_bfd);
+  make_cleanup_bfd_close (loadfile_bfd);
 
   if (!bfd_check_format (loadfile_bfd, bfd_object))
     {
@@ -1641,10 +1659,9 @@ reread_symbols ()
              /* If we get an error, blow away this objfile (not sure if
                 that is the correct response for things like shared
                 libraries).  */
-             old_cleanups = make_cleanup ((make_cleanup_func) free_objfile,
-                                          objfile);
+             old_cleanups = make_cleanup_free_objfile (objfile);
              /* We need to do this whenever any symbols go away.  */
-             make_cleanup ((make_cleanup_func) clear_symtab_users, 0);
+             make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/);
 
              /* Clean up any state BFD has sitting around.  We don't need
                 to close the descriptor but BFD lacks a way of closing the
@@ -2072,6 +2089,12 @@ clear_symtab_users ()
     target_new_objfile_hook (NULL);
 }
 
+static void
+clear_symtab_users_cleanup (void *ignore)
+{
+  clear_symtab_users ();
+}
+
 /* clear_symtab_users_once:
 
    This function is run after symbol reading, or from a cleanup.
This page took 0.02549 seconds and 4 git commands to generate.