* coffread.c (coff_symfile_read): Make a cleanup for 'debugfile'
authorTom Tromey <tromey@redhat.com>
Mon, 23 Jul 2012 14:58:44 +0000 (14:58 +0000)
committerTom Tromey <tromey@redhat.com>
Mon, 23 Jul 2012 14:58:44 +0000 (14:58 +0000)
and 'abfd'.
* elfread.c (elf_symfile_read): Make a cleanup for 'debugfile'
and 'abfd'.
* jit.c (jit_bfd_try_read_symtab): Make a cleanup for 'nbfd'.
* machoread.c (macho_add_oso_symfile): Make a cleanup for
'abfd'.
(macho_symfile_read): Make a cleanup for 'dsym_bfd'.
* objfiles.c (allocate_objfile): Acquire a new reference.
* rs6000-nat.c (add_vmap): Don't acquire a BFD reference.
* solib.c (solib_read_symbols): Don't acquire a BFD reference.
* spu-linux-nat.c (spu_symbol_file_add_from_memory): Make
a cleanup for 'nbfd'.
* symfile-mem.c (symbol_file_add_from_memory): Make a cleanup
for 'nbfd'.
* symfile.c (symbol_file_add_with_addrs_or_offsets): Don't
make a cleanup for 'abfd'.
(symbol_file_add): Make a BFD cleanup.

gdb/ChangeLog
gdb/coffread.c
gdb/elfread.c
gdb/jit.c
gdb/machoread.c
gdb/objfiles.c
gdb/rs6000-nat.c
gdb/solib.c
gdb/spu-linux-nat.c
gdb/symfile-mem.c
gdb/symfile.c

index 9b96acf65a0d3ccf1f7e6e23619e78024c4ce6a6..a8cd9360b980d9dbc6a28c1afd62c6a783334c20 100644 (file)
@@ -1,3 +1,24 @@
+2012-07-23  Tom Tromey  <tromey@redhat.com>
+
+       * coffread.c (coff_symfile_read): Make a cleanup for 'debugfile'
+       and 'abfd'.
+       * elfread.c (elf_symfile_read): Make a cleanup for 'debugfile'
+       and 'abfd'.
+       * jit.c (jit_bfd_try_read_symtab): Make a cleanup for 'nbfd'.
+       * machoread.c (macho_add_oso_symfile): Make a cleanup for
+       'abfd'.
+       (macho_symfile_read): Make a cleanup for 'dsym_bfd'.
+       * objfiles.c (allocate_objfile): Acquire a new reference.
+       * rs6000-nat.c (add_vmap): Don't acquire a BFD reference.
+       * solib.c (solib_read_symbols): Don't acquire a BFD reference.
+       * spu-linux-nat.c (spu_symbol_file_add_from_memory): Make
+       a cleanup for 'nbfd'.
+       * symfile-mem.c (symbol_file_add_from_memory): Make a cleanup
+       for 'nbfd'.
+       * symfile.c (symbol_file_add_with_addrs_or_offsets): Don't
+       make a cleanup for 'abfd'.
+       (symbol_file_add): Make a BFD cleanup.
+
 2012-07-23  Tom Tromey  <tromey@redhat.com>
 
        * cli/cli-dump.c (bfd_openr_with_cleanup): Use gdb_bfd_openr.
index b0a8b8202995186f5a99c737612fe7d56b70c96d..0c7e6d90abebd6e97b3437d5ed8bc31304ff91fa 100644 (file)
@@ -653,13 +653,14 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
       char *debugfile;
 
       debugfile = find_separate_debug_file_by_debuglink (objfile);
+      make_cleanup (xfree, debugfile);
 
       if (debugfile)
        {
          bfd *abfd = symfile_bfd_open (debugfile);
 
+         make_cleanup_bfd_unref (abfd);
          symbol_file_add_separate (abfd, symfile_flags, objfile);
-         xfree (debugfile);
        }
     }
 
index de61a9aa586dc0a03f99239d1747e514a999a4af..608a8682d831875fb84d5b85cb6f6c30b597a435 100644 (file)
@@ -1445,10 +1445,12 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
 
       if (debugfile)
        {
+         struct cleanup *cleanup = make_cleanup (xfree, debugfile);
          bfd *abfd = symfile_bfd_open (debugfile);
 
+         make_cleanup_bfd_unref (abfd);
          symbol_file_add_separate (abfd, symfile_flags, objfile);
-         xfree (debugfile);
+         do_cleanups (cleanup);
        }
     }
 
index 410b94d8610c389001ab7dfb9c2058f840eac161..cdd9f49e071a9e1cb37e0fb3fe198247efd5928b 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -896,7 +896,8 @@ JITed symbol file is not an object file, ignoring it.\n"));
         ++i;
       }
 
-  /* This call takes ownership of NBFD.  It does not take ownership of SAI.  */
+  /* This call does not take ownership of SAI.  */
+  make_cleanup_bfd_unref (nbfd);
   objfile = symbol_file_add_from_bfd (nbfd, 0, sai, OBJF_SHARED, NULL);
 
   do_cleanups (old_cleanups);
index 5b9e2ba4f64fb18fa0ca75464462db89d0439b2a..0d7578a914223de8c126ed5cabcd404c15e12c2b 100644 (file)
@@ -454,6 +454,7 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd,
   asymbol **symp;
   struct bfd_hash_table table;
   int nbr_sections;
+  struct cleanup *cleanup;
 
   /* Per section flag to mark which section have been rebased.  */
   unsigned char *sections_rebased;
@@ -631,11 +632,13 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd,
 
   /* We need to clear SYMFILE_MAINLINE to avoid interractive question
      from symfile.c:symbol_file_add_with_addrs_or_offsets.  */
+  cleanup = make_cleanup_bfd_unref (abfd);
   symbol_file_add_from_bfd
     (abfd, symfile_flags & ~(SYMFILE_MAINLINE | SYMFILE_VERBOSE), NULL,
      main_objfile->flags & (OBJF_REORDERED | OBJF_SHARED
                            | OBJF_READNOW | OBJF_USERLOADED),
      main_objfile);
+  do_cleanups (cleanup);
 }
 
 /* Read symbols from the vector of oso files.  */
@@ -897,6 +900,7 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
          int ix;
          oso_el *oso;
           struct bfd_section *asect, *dsect;
+         struct cleanup *cleanup;
 
          if (mach_o_debug_level > 0)
            printf_unfiltered (_("dsym file found\n"));
@@ -917,7 +921,9 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
             }
 
          /* Add the dsym file as a separate file.  */
+         cleanup = make_cleanup_bfd_unref (dsym_bfd);
           symbol_file_add_separate (dsym_bfd, symfile_flags, objfile);
+         do_cleanups (cleanup);
 
          /* Don't try to read dwarf2 from main file or shared libraries.  */
           return;
index 5ff0eb2536bc05ecc574989d4b6d1ac141fa5a80..411618f90855814ed75de3f6a4dfd40cfd11b476 100644 (file)
@@ -194,9 +194,10 @@ allocate_objfile (bfd *abfd, int flags)
 
   /* Update the per-objfile information that comes from the bfd, ensuring
      that any data that is reference is saved in the per-objfile data
-     region.  Note that we steal a reference to ABFD.  */
+     region.  */
 
   objfile->obfd = abfd;
+  gdb_bfd_ref (abfd);
   if (abfd != NULL)
     {
       /* Look up the gdbarch associated with the BFD.  */
index 140012bbebcf70f4559123c4b00db62447ec4d7f..8c3f54606f2db5730a7865600b5479dd1ef6ce83 100644 (file)
@@ -798,7 +798,6 @@ add_vmap (LdInfo *ldi)
       gdb_bfd_unref (abfd);
       return NULL;
     }
-  gdb_bfd_ref (vp->bfd);
   obj = allocate_objfile (vp->bfd, 0);
   vp->objfile = obj;
 
index 9779e100a01cffeffb628d2d9bed55a63684fa69..73773f10989aac4c0d14eedf6ff85eb901b7c681 100644 (file)
@@ -610,7 +610,6 @@ solib_read_symbols (struct so_list *so, int flags)
 
          sap = build_section_addr_info_from_section_table (so->sections,
                                                            so->sections_end);
-         gdb_bfd_ref (so->abfd);
          so->objfile = symbol_file_add_from_bfd (so->abfd,
                                                  flags, sap, OBJF_SHARED,
                                                  NULL);
index a17ff3f831f8a1936e7e559a8e4d79d2212ef688..999f1abd9783fdc28b782241f14309cefcbee009 100644 (file)
@@ -374,8 +374,13 @@ spu_symbol_file_add_from_memory (int inferior_fd)
   /* Open BFD representing SPE executable and read its symbols.  */
   nbfd = spu_bfd_open (addr);
   if (nbfd)
-    symbol_file_add_from_bfd (nbfd, SYMFILE_VERBOSE | SYMFILE_MAINLINE,
-                              NULL, 0, NULL);
+    {
+      struct cleanup *cleanup = make_cleanup_bfd_unref (nbfd);
+
+      symbol_file_add_from_bfd (nbfd, SYMFILE_VERBOSE | SYMFILE_MAINLINE,
+                               NULL, 0, NULL);
+      do_cleanups (cleanup);
+    }
 }
 
 
index ad87abdf75d67c07bd8bf61b95411e293ad1393d..2e53be05de42b91280062a4a16f4a61b1cc2b3f4 100644 (file)
@@ -111,15 +111,14 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, char *name,
       xfree (name);
     }
 
+  cleanup = make_cleanup_bfd_unref (nbfd);
+
   if (!bfd_check_format (nbfd, bfd_object))
-    {
-      make_cleanup_bfd_unref (nbfd);
-      error (_("Got object file from memory but can't read symbols: %s."),
-            bfd_errmsg (bfd_get_error ()));
-    }
+    error (_("Got object file from memory but can't read symbols: %s."),
+          bfd_errmsg (bfd_get_error ()));
 
   sai = alloc_section_addr_info (bfd_count_sections (nbfd));
-  cleanup = make_cleanup (xfree, sai);
+  make_cleanup (xfree, sai);
   i = 0;
   for (sec = nbfd->sections; sec != NULL; sec = sec->next)
     if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0)
index 64c4a3b23d363953f9ed26ed0b4b7c5354c719b6..e1d5c15d4124e3b2972ebbf4e6166f330e6d5e17 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_unref (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,14 @@ 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,
+  bfd *bfd = symfile_bfd_open (name);
+  struct cleanup *cleanup = make_cleanup_bfd_unref (bfd);
+  struct objfile *objf;
+
+  objf = symbol_file_add_from_bfd (symfile_bfd_open (name), add_flags, addrs,
                                    flags, NULL);
+  do_cleanups (cleanup);
+  return objf;
 }
 
 
This page took 0.035762 seconds and 4 git commands to generate.