From patchwork Fri Oct 20 04:18:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23722 Received: (qmail 51544 invoked by alias); 20 Oct 2017 04:18:27 -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 51436 invoked by uid 89); 20 Oct 2017 04:18:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=H*MI:sk:2017102 X-HELO: gproxy8-pub.mail.unifiedlayer.com Received: from gproxy8-pub.mail.unifiedlayer.com (HELO gproxy8-pub.mail.unifiedlayer.com) (67.222.33.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Oct 2017 04:18:25 +0000 Received: from cmgw4 (unknown [10.0.90.85]) by gproxy8.mail.unifiedlayer.com (Postfix) with ESMTP id 6DABA1AB0C3 for ; Thu, 19 Oct 2017 22:18:24 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id PgJM1w0022f2jeq01gJQdi; Thu, 19 Oct 2017 22:18:24 -0600 X-Authority-Analysis: v=2.2 cv=JNNLi4Cb c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=02M-m0pO-4AA:10 a=zstS-IiYAAAA:8 a=_hvxY5W4PH1bc1OPw-sA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 71-218-90-63.hlrn.qwest.net ([71.218.90.63]:60108 helo=bapiya.localdomain) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1e5OlJ-004ECG-4D; Thu, 19 Oct 2017 22:18:21 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 2/3] Use "new" to allocate gdb_bfd_data Date: Thu, 19 Oct 2017 22:18:14 -0600 Message-Id: <20171020041815.20291-3-tom@tromey.com> In-Reply-To: <20171020041815.20291-1-tom@tromey.com> References: <20171020041815.20291-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1e5OlJ-004ECG-4D X-Source-Sender: 71-218-90-63.hlrn.qwest.net (bapiya.localdomain) [71.218.90.63]:60108 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes gdb_bfd_data to be allocated with new and destroyed with delete. ChangeLog 2017-10-19 Tom Tromey * 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 | 7 ++++++ gdb/gdb_bfd.c | 74 +++++++++++++++++++++++++++++++++-------------------------- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 5ba03c17df..b60d237635 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);