diff options
author | Tom Tromey <tom@tromey.com> | 2017-10-15 11:23:22 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-10-20 09:01:03 -0600 |
commit | 06d5bbc8e5f7541b13509c33b8b3eb8afac27b2f (patch) | |
tree | 6dfe5319761dc96ababebf2d396d1d75c31535c4 /gdb/gdb_bfd.c | |
parent | 2712ce2e659f82168154d4533f53d2963ae82571 (diff) | |
download | gdb-06d5bbc8e5f7541b13509c33b8b3eb8afac27b2f.zip gdb-06d5bbc8e5f7541b13509c33b8b3eb8afac27b2f.tar.gz gdb-06d5bbc8e5f7541b13509c33b8b3eb8afac27b2f.tar.bz2 |
Use "new" to allocate gdb_bfd_data
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.
Diffstat (limited to 'gdb/gdb_bfd.c')
-rw-r--r-- | gdb/gdb_bfd.c | 74 |
1 files changed, 42 insertions, 32 deletions
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 5ba03c1..b60d237 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -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); |