* dwarf2read.c (macro_start_file): Update.
[deliverable/binutils-gdb.git] / gdb / symfile.c
index 2ad72c5b1e493994a87c677acc8fce057ee04b6e..6c93ba6dcdb27af235fd6d2454c54f4bd1e21345 100644 (file)
@@ -1037,7 +1037,7 @@ new_symfile_objfile (struct objfile *objfile, int add_flags)
    loaded file.
 
    ABFD is a BFD already open on the file, as from symfile_bfd_open.
-   This BFD will be closed on error, and is always consumed by this function.
+   A new reference is acquired by this function.
 
    ADD_FLAGS encodes verbosity, whether this is main symbol file or
    extra, such as dynamically loaded code, and what to do with breakpoins.
@@ -1061,7 +1061,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
                                        int flags, struct objfile *parent)
 {
   struct objfile *objfile;
-  struct cleanup *my_cleanups;
   const char *name = bfd_get_filename (abfd);
   const int from_tty = add_flags & SYMFILE_VERBOSE;
   const int mainline = add_flags & SYMFILE_MAINLINE;
@@ -1075,8 +1074,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
       add_flags &= ~SYMFILE_NO_READ;
     }
 
-  my_cleanups = make_cleanup_bfd_close (abfd);
-
   /* Give user a chance to burp if we'd be
      interactively wiping out any existing symbols.  */
 
@@ -1087,7 +1084,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
     error (_("Not confirmed."));
 
   objfile = allocate_objfile (abfd, flags | (mainline ? OBJF_MAINLINE : 0));
-  discard_cleanups (my_cleanups);
 
   if (parent)
     add_separate_debug_objfile (objfile, parent);
@@ -1208,8 +1204,13 @@ struct objfile *
 symbol_file_add (char *name, int add_flags, struct section_addr_info *addrs,
                 int flags)
 {
-  return symbol_file_add_from_bfd (symfile_bfd_open (name), add_flags, addrs,
-                                   flags, NULL);
+  bfd *bfd = symfile_bfd_open (name);
+  struct cleanup *cleanup = make_cleanup_bfd_unref (bfd);
+  struct objfile *objf;
+
+  objf = symbol_file_add_from_bfd (bfd, add_flags, addrs, flags, NULL);
+  do_cleanups (cleanup);
+  return objf;
 }
 
 
@@ -1351,7 +1352,7 @@ separate_debug_file_exists (const char *name, unsigned long crc,
   if (filename_cmp (name, parent_objfile->name) == 0)
     return 0;
 
-  abfd = bfd_open_maybe_remote (name);
+  abfd = gdb_bfd_open_maybe_remote (name);
 
   if (!abfd)
     return 0;
@@ -1695,12 +1696,16 @@ set_initial_language (void)
    returns NULL with the BFD error set.  */
 
 bfd *
-bfd_open_maybe_remote (const char *name)
+gdb_bfd_open_maybe_remote (const char *name)
 {
+  bfd *result;
+
   if (remote_filename_p (name))
-    return gdb_bfd_ref (remote_bfd_open (name, gnutarget));
+    result = remote_bfd_open (name, gnutarget);
   else
-    return gdb_bfd_ref (bfd_openr (name, gnutarget));
+    result = gdb_bfd_openr (name, gnutarget);
+
+  return result;
 }
 
 
@@ -1718,19 +1723,14 @@ symfile_bfd_open (char *name)
 
   if (remote_filename_p (name))
     {
-      name = xstrdup (name);
-      sym_bfd = gdb_bfd_ref (remote_bfd_open (name, gnutarget));
+      sym_bfd = remote_bfd_open (name, gnutarget);
       if (!sym_bfd)
-       {
-         make_cleanup (xfree, name);
-         error (_("`%s': can't open to read symbols: %s."), name,
-                bfd_errmsg (bfd_get_error ()));
-       }
+       error (_("`%s': can't open to read symbols: %s."), name,
+              bfd_errmsg (bfd_get_error ()));
 
       if (!bfd_check_format (sym_bfd, bfd_object))
        {
-         gdb_bfd_unref (sym_bfd);
-         make_cleanup (xfree, name);
+         make_cleanup_bfd_unref (sym_bfd);
          error (_("`%s': can't read symbols: %s."), name,
                 bfd_errmsg (bfd_get_error ()));
        }
@@ -1759,12 +1759,11 @@ symfile_bfd_open (char *name)
       perror_with_name (name);
     }
 
-  /* Free 1st new malloc'd copy, but keep the 2nd malloc'd copy in
-     bfd.  It'll be freed in free_objfile().  */
   xfree (name);
   name = absolute_name;
+  make_cleanup (xfree, name);
 
-  sym_bfd = gdb_bfd_ref (bfd_fopen (name, gnutarget, FOPEN_RB, desc));
+  sym_bfd = gdb_bfd_fopen (name, gnutarget, FOPEN_RB, desc);
   if (!sym_bfd)
     {
       make_cleanup (xfree, name);
@@ -1775,8 +1774,7 @@ symfile_bfd_open (char *name)
 
   if (!bfd_check_format (sym_bfd, bfd_object))
     {
-      make_cleanup_bfd_close (sym_bfd);
-      make_cleanup (xfree, name);
+      make_cleanup_bfd_unref (sym_bfd);
       error (_("`%s': can't read symbols: %s."), name,
             bfd_errmsg (bfd_get_error ()));
     }
@@ -2105,14 +2103,14 @@ generic_load (char *args, int from_tty)
     }
 
   /* Open the file for loading.  */
-  loadfile_bfd = gdb_bfd_ref (bfd_openr (filename, gnutarget));
+  loadfile_bfd = gdb_bfd_openr (filename, gnutarget);
   if (loadfile_bfd == NULL)
     {
       perror_with_name (filename);
       return;
     }
 
-  make_cleanup_bfd_close (loadfile_bfd);
+  make_cleanup_bfd_unref (loadfile_bfd);
 
   if (!bfd_check_format (loadfile_bfd, bfd_object))
     {
@@ -2511,9 +2509,16 @@ reread_symbols (void)
          /* Clean up any state BFD has sitting around.  We don't need
             to close the descriptor but BFD lacks a way of closing the
             BFD without closing the descriptor.  */
-         obfd_filename = bfd_get_filename (objfile->obfd);
-         gdb_bfd_unref (objfile->obfd);
-         objfile->obfd = bfd_open_maybe_remote (obfd_filename);
+         {
+           struct bfd *obfd = objfile->obfd;
+
+           obfd_filename = bfd_get_filename (objfile->obfd);
+           /* Open the new BFD before freeing the old one, so that
+              the filename remains live.  */
+           objfile->obfd = gdb_bfd_open_maybe_remote (obfd_filename);
+           gdb_bfd_unref (obfd);
+         }
+
          if (objfile->obfd == NULL)
            error (_("Can't open %s to read symbols."), objfile->name);
          /* bfd_openr sets cacheable to true, which is what we want.  */
@@ -2543,10 +2548,6 @@ reread_symbols (void)
          /* Free the obstacks for non-reusable objfiles.  */
          psymbol_bcache_free (objfile->psymbol_cache);
          objfile->psymbol_cache = psymbol_bcache_init ();
-         bcache_xfree (objfile->macro_cache);
-         objfile->macro_cache = bcache_xmalloc (NULL, NULL);
-         bcache_xfree (objfile->filename_cache);
-         objfile->filename_cache = bcache_xmalloc (NULL,NULL);
          if (objfile->demangled_names_hash != NULL)
            {
              htab_delete (objfile->demangled_names_hash);
@@ -2567,6 +2568,8 @@ reread_symbols (void)
          memset (&objfile->msymbol_demangled_hash, 0,
                  sizeof (objfile->msymbol_demangled_hash));
 
+         set_objfile_per_bfd (objfile);
+
          /* obstack_init also initializes the obstack so it is
             empty.  We could use obstack_specify_allocation but
             gdb_obstack.h specifies the alloc/dealloc functions.  */
@@ -2851,7 +2854,7 @@ allocate_symtab (const char *filename, struct objfile *objfile)
     obstack_alloc (&objfile->objfile_obstack, sizeof (struct symtab));
   memset (symtab, 0, sizeof (*symtab));
   symtab->filename = (char *) bcache (filename, strlen (filename) + 1,
-                                     objfile->filename_cache);
+                                     objfile->per_bfd->filename_cache);
   symtab->fullname = NULL;
   symtab->language = deduce_language_from_filename (filename);
   symtab->debugformat = "unknown";
@@ -2878,8 +2881,8 @@ allocate_symtab (const char *filename, struct objfile *objfile)
                              last_objfile_name);
        }
       fprintf_unfiltered (gdb_stdlog,
-                         "Created symtab 0x%lx for module %s.\n",
-                         (long) symtab, filename);
+                         "Created symtab %s for module %s.\n",
+                         host_address_to_string (symtab), filename);
     }
 
   return (symtab);
@@ -3388,7 +3391,7 @@ overlay_load_command (char *args, int from_tty)
    A place-holder for a mis-typed command.  */
 
 /* Command list chain containing all defined "overlay" subcommands.  */
-struct cmd_list_element *overlaylist;
+static struct cmd_list_element *overlaylist;
 
 static void
 overlay_command (char *args, int from_tty)
This page took 0.027049 seconds and 4 git commands to generate.