*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / rs6000-nat.c
index 073f167caf4e03ded73dba24d3538b7c79afcc39..f46169b91de32e7cc19fca48f1b4170d50bcabd6 100644 (file)
@@ -53,6 +53,7 @@
 #include <a.out.h>
 #include <sys/file.h>
 #include "gdb_stat.h"
+#include "gdb_bfd.h"
 #include <sys/core.h>
 #define __LDINFO_PTRACE32__    /* for __ld_info32 */
 #define __LDINFO_PTRACE64__    /* for __ld_info64 */
@@ -75,7 +76,7 @@
 #ifndef ARCH3264
 # define ARCH64() 0
 #else
-# define ARCH64() (register_size (target_gdbarch, 0) == 8)
+# define ARCH64() (register_size (target_gdbarch (), 0) == 8)
 #endif
 
 /* Union of 32-bit and 64-bit versions of ld_info.  */
@@ -745,20 +746,13 @@ add_vmap (LdInfo *ldi)
   mem = xstrdup (mem);
 
   fd = LDI_FD (ldi, arch64);
-  if (fd < 0)
-    /* Note that this opens it once for every member; a possible
-       enhancement would be to only open it once for every object.  */
-    abfd = bfd_openr (filename, gnutarget);
-  else
-    abfd = bfd_fdopenr (filename, gnutarget, fd);
-  gdb_bfd_ref (abfd);
+  abfd = gdb_bfd_open (filename, gnutarget, fd < 0 ? -1 : fd);
   if (!abfd)
     {
       warning (_("Could not open `%s' as an executable file: %s"),
               filename, bfd_errmsg (bfd_get_error ()));
       return NULL;
     }
-  gdb_bfd_stash_filename (abfd);
 
   /* Make sure we have an object file.  */
 
@@ -767,13 +761,17 @@ add_vmap (LdInfo *ldi)
 
   else if (bfd_check_format (abfd, bfd_archive))
     {
-      last = 0;
-      /* FIXME??? am I tossing BFDs?  bfd?  */
-      while ((last = bfd_openr_next_archived_file (abfd, last)))
+      last = gdb_bfd_openr_next_archived_file (abfd, NULL);
+      while (last != NULL)
        {
-         gdb_bfd_ref (last);
+         bfd *next;
+
          if (strcmp (mem, last->filename) == 0)
            break;
+
+         next = gdb_bfd_openr_next_archived_file (abfd, last);
+         gdb_bfd_unref (last);
+         last = next;
        }
 
       if (!last)
@@ -793,6 +791,9 @@ add_vmap (LdInfo *ldi)
        }
 
       vp = map_vmap (last, abfd);
+      /* map_vmap acquired a reference to LAST, so we can release
+        ours.  */
+      gdb_bfd_unref (last);
     }
   else
     {
@@ -801,13 +802,17 @@ add_vmap (LdInfo *ldi)
       gdb_bfd_unref (abfd);
       return NULL;
     }
-  gdb_bfd_ref (vp->bfd);
   obj = allocate_objfile (vp->bfd, 0);
   vp->objfile = obj;
 
   /* Always add symbols for the main objfile.  */
   if (vp == vmap || auto_solib_add)
     vmap_add_symbols (vp);
+
+  /* Anything needing a reference to ABFD has already acquired it, so
+     release our local reference.  */
+  gdb_bfd_unref (abfd);
+
   return vp;
 }
 \f
This page took 0.026027 seconds and 4 git commands to generate.