* symfile.c (separate_debug_file_exists): Update.
[deliverable/binutils-gdb.git] / gdb / solib-darwin.c
index d52fb468ad5476dc0edaca63baf3e9bbf7905d91..db8f187ad0f4b0a1f82bc1c57f4270c5ca4be11e 100644 (file)
@@ -28,6 +28,7 @@
 #include "inferior.h"
 #include "regcache.h"
 #include "gdbthread.h"
+#include "gdb_bfd.h"
 
 #include "gdb_assert.h"
 
@@ -356,6 +357,7 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info)
   gdb_byte *interp_name;
   CORE_ADDR load_addr = 0;
   bfd *dyld_bfd = NULL;
+  struct cleanup *cleanup;
 
   /* This method doesn't work with an attached process.  */
   if (current_inferior ()->attach_flag)
@@ -366,24 +368,31 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info)
   if (!interp_name)
     return;
 
+  cleanup = make_cleanup (null_cleanup, NULL);
+
   /* Create a bfd for the interpreter.  */
-  dyld_bfd = bfd_openr (interp_name, gnutarget);
+  dyld_bfd = gdb_bfd_openr (interp_name, gnutarget);
   if (dyld_bfd)
     {
       bfd *sub;
 
+      make_cleanup_bfd_unref (dyld_bfd);
       sub = bfd_mach_o_fat_extract (dyld_bfd, bfd_object,
                                    gdbarch_bfd_arch_info (target_gdbarch));
       if (sub)
-       dyld_bfd = sub;
-      else
        {
-         bfd_close (dyld_bfd);
-         dyld_bfd = NULL;
+         dyld_bfd = sub;
+         gdb_bfd_ref (sub);
+         make_cleanup_bfd_unref (sub);
        }
+      else
+       dyld_bfd = NULL;
     }
   if (!dyld_bfd)
-    return;
+    {
+      do_cleanups (cleanup);
+      return;
+    }
 
   /* We find the dynamic linker's base address by examining
      the current pc (which should point at the entry point for the
@@ -395,7 +404,7 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info)
   info->all_image_addr =
     lookup_symbol_from_bfd (dyld_bfd, "_dyld_all_image_infos");
 
-  bfd_close (dyld_bfd);
+  do_cleanups (cleanup);
 
   if (info->all_image_addr == 0)
     return;
@@ -509,17 +518,10 @@ darwin_bfd_open (char *pathname)
                                gdbarch_bfd_arch_info (target_gdbarch));
   if (!res)
     {
-      bfd_close (abfd);
-      make_cleanup (xfree, found_pathname);
+      make_cleanup_bfd_unref (abfd);
       error (_("`%s': not a shared-library: %s"),
-            found_pathname, bfd_errmsg (bfd_get_error ()));
+            bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
     }
-
-  /* Make sure that the filename is malloc'ed.  The current filename
-     for fat-binaries BFDs is a name that was generated by BFD, usually
-     a static string containing the name of the architecture.  */
-  res->filename = xstrdup (pathname);
-
   return res;
 }
 
This page took 0.024117 seconds and 4 git commands to generate.