From patchwork Wed Oct 18 04:14:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23662 Received: (qmail 121714 invoked by alias); 18 Oct 2017 04:14:58 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 121657 invoked by uid 89); 18 Oct 2017 04:14:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Placement X-HELO: gproxy6-pub.mail.unifiedlayer.com Received: from gproxy6-pub.mail.unifiedlayer.com (HELO gproxy6-pub.mail.unifiedlayer.com) (67.222.39.168) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Oct 2017 04:14:56 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy6.mail.unifiedlayer.com (Postfix) with ESMTP id F1F431E061C for ; Tue, 17 Oct 2017 22:14:54 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id NsEr1w00U2f2jeq01sEudX; Tue, 17 Oct 2017 22:14:54 -0600 X-Authority-Analysis: v=2.2 cv=K4VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=02M-m0pO-4AA:10 a=zstS-IiYAAAA:8 a=gtRBDd1uKfKO_k4J0u8A:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 184-96-33-178.hlrn.qwest.net ([184.96.33.178]:51240 helo=bapiya.localdomain) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1e4fkp-001dwQ-OA; Tue, 17 Oct 2017 22:14:51 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/3] Use "new" to allocate gdb_bfd_data Date: Tue, 17 Oct 2017 22:14:48 -0600 Message-Id: <20171018041449.10019-3-tom@tromey.com> In-Reply-To: <20171018041449.10019-1-tom@tromey.com> References: <20171018041449.10019-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1e4fkp-001dwQ-OA X-Source-Sender: 184-96-33-178.hlrn.qwest.net (bapiya.localdomain) [184.96.33.178]:51240 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes gdb_bfd_data to be allocated with new. Placement new is used because the object actually resides in the BFD's objalloc. ChangeLog 2017-10-17 Tom Tromey * gdb_bfd.c (gdb_bfd_ref): Use placement new. (struct gdb_bfd_data): Add constructor, destructor, and member initializers. (gdb_bfd_unref): Use explicit destructor call. --- gdb/ChangeLog | 7 ++++++ gdb/gdb_bfd.c | 75 ++++++++++++++++++++++++++++++++++------------------------- 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 5ba03c17df..e943d9bb62 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,9 @@ 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; - } + void *space = bfd_zalloc (abfd, sizeof (struct gdb_bfd_data)); + gdata = new (space) 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 +572,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,12 +618,7 @@ 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); - + gdata->~gdb_bfd_data (); bfd_free_data (abfd); bfd_usrdata (abfd) = NULL; /* Paranoia. */