daily update
[deliverable/binutils-gdb.git] / gdb / gdb_bfd.c
index 2beeb5dea3e65a7bc29f82a316a4830b98fb8c9c..4d4b0a53593a3560b742a27f7ad51d1dff5e109f 100644 (file)
@@ -1,6 +1,6 @@
 /* Definitions for BFD wrappers used by GDB.
 
-   Copyright (C) 2011-2013 Free Software Foundation, Inc.
+   Copyright (C) 2011-2014 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -25,6 +25,7 @@
 #include "gdbcmd.h"
 #include "hashtab.h"
 #include "filestuff.h"
+#include "vec.h"
 #ifdef HAVE_ZLIB_H
 #include <zlib.h>
 #endif
@@ -35,6 +36,9 @@
 #endif
 #endif
 
+typedef bfd *bfdp;
+DEF_VEC_P (bfdp);
+
 /* An object of this type is stored in the section's user data when
    mapping a section.  */
 
@@ -57,21 +61,6 @@ struct gdb_bfd_section_data
 
 static htab_t all_bfds;
 
-/* See gdb_bfd.h.  */
-
-void
-gdb_bfd_stash_filename (struct bfd *abfd)
-{
-  char *name = bfd_get_filename (abfd);
-  char *data;
-
-  data = bfd_alloc (abfd, strlen (name) + 1);
-  strcpy (data, name);
-
-  /* Unwarranted chumminess with BFD.  */
-  abfd->filename = data;
-}
-
 /* An object of this type is stored in each BFD's user data.  */
 
 struct gdb_bfd_data
@@ -99,6 +88,9 @@ struct gdb_bfd_data
      BFD.  Otherwise, this is NULL.  */
   bfd *archive_bfd;
 
+  /* Table of all the bfds this bfd has included.  */
+  VEC (bfdp) *included_bfds;
+
   /* The registry.  */
   REGISTRY_FIELDS;
 };
@@ -204,7 +196,6 @@ gdb_bfd_open (const char *name, const char *target, int fd)
   gdb_assert (!*slot);
   *slot = abfd;
 
-  gdb_bfd_stash_filename (abfd);
   gdb_bfd_ref (abfd);
   return abfd;
 }
@@ -293,9 +284,10 @@ gdb_bfd_ref (struct bfd *abfd)
 void
 gdb_bfd_unref (struct bfd *abfd)
 {
+  int ix;
   struct gdb_bfd_data *gdata;
   struct gdb_bfd_cache_search search;
-  bfd *archive_bfd;
+  bfd *archive_bfd, *included_bfd;
 
   if (abfd == NULL)
     return;
@@ -323,6 +315,12 @@ gdb_bfd_unref (struct bfd *abfd)
        htab_clear_slot (gdb_bfd_cache, slot);
     }
 
+  for (ix = 0;
+       VEC_iterate (bfdp, gdata->included_bfds, ix, included_bfd);
+       ++ix)
+    gdb_bfd_unref (included_bfd);
+  VEC_free (bfdp, gdata->included_bfds);
+
   bfd_free_data (abfd);
   bfd_usrdata (abfd) = NULL;  /* Paranoia.  */
 
@@ -490,10 +488,7 @@ gdb_bfd_fopen (const char *filename, const char *target, const char *mode,
   bfd *result = bfd_fopen (filename, target, mode, fd);
 
   if (result)
-    {
-      gdb_bfd_stash_filename (result);
-      gdb_bfd_ref (result);
-    }
+    gdb_bfd_ref (result);
 
   return result;
 }
@@ -506,10 +501,7 @@ gdb_bfd_openr (const char *filename, const char *target)
   bfd *result = bfd_openr (filename, target);
 
   if (result)
-    {
-      gdb_bfd_stash_filename (result);
-      gdb_bfd_ref (result);
-    }
+    gdb_bfd_ref (result);
 
   return result;
 }
@@ -522,10 +514,7 @@ gdb_bfd_openw (const char *filename, const char *target)
   bfd *result = bfd_openw (filename, target);
 
   if (result)
-    {
-      gdb_bfd_stash_filename (result);
-      gdb_bfd_ref (result);
-    }
+    gdb_bfd_ref (result);
 
   return result;
 }
@@ -553,10 +542,7 @@ gdb_bfd_openr_iovec (const char *filename, const char *target,
                                 pread_func, close_func, stat_func);
 
   if (result)
-    {
-      gdb_bfd_ref (result);
-      gdb_bfd_stash_filename (result);
-    }
+    gdb_bfd_ref (result);
 
   return result;
 }
@@ -597,16 +583,25 @@ gdb_bfd_openr_next_archived_file (bfd *archive, bfd *previous)
 
 /* See gdb_bfd.h.  */
 
+void
+gdb_bfd_record_inclusion (bfd *includer, bfd *includee)
+{
+  struct gdb_bfd_data *gdata;
+
+  gdb_bfd_ref (includee);
+  gdata = bfd_usrdata (includer);
+  VEC_safe_push (bfdp, gdata->included_bfds, includee);
+}
+
+/* See gdb_bfd.h.  */
+
 bfd *
 gdb_bfd_fdopenr (const char *filename, const char *target, int fd)
 {
   bfd *result = bfd_fdopenr (filename, target, fd);
 
   if (result)
-    {
-      gdb_bfd_ref (result);
-      gdb_bfd_stash_filename (result);
-    }
+    gdb_bfd_ref (result);
 
   return result;
 }
This page took 0.025131 seconds and 4 git commands to generate.