]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use "new" to allocate gdb_bfd_data
authorTom Tromey <tom@tromey.com>
Sun, 15 Oct 2017 17:23:22 +0000 (11:23 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 20 Oct 2017 15:01:03 +0000 (09:01 -0600)
This changes gdb_bfd_data to be allocated with new and destroyed with
delete.

ChangeLog
2017-10-20  Tom Tromey  <tom@tromey.com>

* gdb_bfd.c (gdb_bfd_ref): Use new.
(struct gdb_bfd_data): Add constructor, destructor, and member
initializers.
(gdb_bfd_unref): Use delete.

gdb/ChangeLog
gdb/gdb_bfd.c

index 81b70c15f7b847739164d4a32f88e945bb59497a..97fcde2196bc921d01c6c2a52276f80b0aff4ff4 100644 (file)
@@ -1,3 +1,10 @@
+2017-10-20  Tom Tromey  <tom@tromey.com>
+
+       * gdb_bfd.c (gdb_bfd_ref): Use new.
+       (struct gdb_bfd_data): Add constructor, destructor, and member
+       initializers.
+       (gdb_bfd_unref): Use delete.
+
 2017-10-20  Tom Tromey  <tom@tromey.com>
 
        * exec.c (exec_file_attach): Use new_bfd_ref.
index 5ba03c17df346129f2824aa63e88583df8c4cb5a..b60d237635a124e5e5fd3bca112ec5b147f1181d 100644 (file)
@@ -63,8 +63,42 @@ static htab_t all_bfds;
 
 struct gdb_bfd_data
 {
+  gdb_bfd_data (bfd *abfd)
+    : mtime (bfd_get_mtime (abfd)),
+      size (bfd_get_size (abfd)),
+      relocation_computed (0),
+      needs_relocations (0),
+      crc_computed (0)
+  {
+    struct stat buf;
+
+    if (bfd_stat (abfd, &buf) == 0)
+      {
+       inode = buf.st_ino;
+       device_id = buf.st_dev;
+      }
+    else
+      {
+       /* The stat failed.  */
+       inode = 0;
+       device_id = 0;
+      }
+  }
+
+  ~gdb_bfd_data ()
+  {
+    int ix;
+    bfd *included_bfd;
+
+    for (ix = 0;
+        VEC_iterate (bfdp, included_bfds, ix, included_bfd);
+        ++ix)
+      gdb_bfd_unref (included_bfd);
+    VEC_free (bfdp, included_bfds);
+  }
+
   /* The reference count.  */
-  int refc;
+  int refc = 1;
 
   /* The mtime of the BFD at the point the cache entry was made.  */
   time_t mtime;
@@ -89,17 +123,17 @@ struct gdb_bfd_data
   unsigned int crc_computed : 1;
 
   /* The file's CRC.  */
-  unsigned long crc;
+  unsigned long crc = 0;
 
   /* If the BFD comes from an archive, this points to the archive's
      BFD.  Otherwise, this is NULL.  */
-  bfd *archive_bfd;
+  bfd *archive_bfd = nullptr;
 
   /* Table of all the bfds this bfd has included.  */
-  VEC (bfdp) *included_bfds;
+  VEC (bfdp) *included_bfds = nullptr;
 
   /* The registry.  */
-  REGISTRY_FIELDS;
+  REGISTRY_FIELDS = {};
 };
 
 #define GDB_BFD_DATA_ACCESSOR(ABFD) \
@@ -499,7 +533,6 @@ gdb_bfd_close_or_warn (struct bfd *abfd)
 void
 gdb_bfd_ref (struct bfd *abfd)
 {
-  struct stat buf;
   struct gdb_bfd_data *gdata;
   void **slot;
 
@@ -523,25 +556,8 @@ gdb_bfd_ref (struct bfd *abfd)
   /* Ask BFD to decompress sections in bfd_get_full_section_contents.  */
   abfd->flags |= BFD_DECOMPRESS;
 
-  gdata
-    = (struct gdb_bfd_data *) bfd_zalloc (abfd, sizeof (struct gdb_bfd_data));
-  gdata->refc = 1;
-  gdata->mtime = bfd_get_mtime (abfd);
-  gdata->size = bfd_get_size (abfd);
-  gdata->archive_bfd = NULL;
-  if (bfd_stat (abfd, &buf) == 0)
-    {
-      gdata->inode = buf.st_ino;
-      gdata->device_id = buf.st_dev;
-    }
-  else
-    {
-      /* The stat failed.  */
-      gdata->inode = 0;
-      gdata->device_id = 0;
-    }
+  gdata = new gdb_bfd_data (abfd);
   bfd_usrdata (abfd) = gdata;
-
   bfd_alloc_data (abfd);
 
   /* This is the first we've seen it, so add it to the hash table.  */
@@ -555,10 +571,9 @@ 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, *included_bfd;
+  bfd *archive_bfd;
 
   if (abfd == NULL)
     return;
@@ -602,13 +617,8 @@ 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);
+  delete gdata;
   bfd_usrdata (abfd) = NULL;  /* Paranoia.  */
 
   htab_remove_elt (all_bfds, abfd);