From patchwork Sun Sep 24 02:46:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23116 Received: (qmail 42194 invoked by alias); 24 Sep 2017 02:46:20 -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 42057 invoked by uid 89); 24 Sep 2017 02:46:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy10-pub.mail.unifiedlayer.com Received: from gproxy10-pub.mail.unifiedlayer.com (HELO gproxy10-pub.mail.unifiedlayer.com) (69.89.20.226) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 24 Sep 2017 02:46:16 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy10.mail.unifiedlayer.com (Postfix) with ESMTP id B0E06140422 for ; Sat, 23 Sep 2017 20:46:14 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id DEmB1w00K2f2jeq01EmEu0; Sat, 23 Sep 2017 20:46:14 -0600 X-Authority-Analysis: v=2.2 cv=K/VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=3mk9hI0kGPT3VJzlWksA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:56144 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dvwvr-001i9G-Hs; Sat, 23 Sep 2017 20:46:11 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 4/5] Remove make_cleanup_regcache_invalidate Date: Sat, 23 Sep 2017 20:46:07 -0600 Message-Id: <20170924024608.4346-5-tom@tromey.com> In-Reply-To: <20170924024608.4346-1-tom@tromey.com> References: <20170924024608.4346-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dvwvr-001i9G-Hs X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:56144 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This removes make_cleanup_regcache_invalidate in favor of a simple RAII class that handles register invalidation. ChangeLog 2017-09-23 Tom Tromey * regcache.c (class regcache_invalidator): New. (struct register_to_invalidate): Remove. (make_cleanup_regcache_invalidate): Remove. (regcache::raw_write): Use regcache_invalidator. --- gdb/ChangeLog | 7 +++++++ gdb/regcache.c | 56 ++++++++++++++++++++++++++++++-------------------------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index ab6a651..46d8cfb 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -241,31 +241,36 @@ regcache_get_ptid (const struct regcache *regcache) return regcache->ptid (); } -/* Cleanup routines for invalidating a register. */ +/* Cleanup class for invalidating a register. */ -struct register_to_invalidate +class regcache_invalidator { - struct regcache *regcache; - int regnum; -}; +public: -static void -do_regcache_invalidate (void *data) -{ - struct register_to_invalidate *reg = (struct register_to_invalidate *) data; + regcache_invalidator (struct regcache *regcache, int regnum) + : m_regcache (regcache), + m_regnum (regnum) + { + } - regcache_invalidate (reg->regcache, reg->regnum); -} + ~regcache_invalidator () + { + if (m_regcache != nullptr) + regcache_invalidator (m_regcache, m_regnum); + } -static struct cleanup * -make_cleanup_regcache_invalidate (struct regcache *regcache, int regnum) -{ - struct register_to_invalidate* reg = XNEW (struct register_to_invalidate); + DISABLE_COPY_AND_ASSIGN (regcache_invalidator); - reg->regcache = regcache; - reg->regnum = regnum; - return make_cleanup_dtor (do_regcache_invalidate, (void *) reg, xfree); -} + void release () + { + m_regcache = nullptr; + } + +private: + + struct regcache *m_regcache; + int m_regnum; +}; /* Return REGCACHE's architecture. */ @@ -860,7 +865,6 @@ regcache_raw_write (struct regcache *regcache, int regnum, void regcache::raw_write (int regnum, const gdb_byte *buf) { - struct cleanup *old_chain; gdb_assert (buf != NULL); gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); @@ -881,15 +885,15 @@ regcache::raw_write (int regnum, const gdb_byte *buf) target_prepare_to_store (this); raw_set_cached_value (regnum, buf); - /* Register a cleanup function for invalidating the register after it is - written, in case of a failure. */ - old_chain = make_cleanup_regcache_invalidate (this, regnum); + /* Invalidate the register after it is written, in case of a + failure. */ + regcache_invalidator invalidator (this, regnum); target_store_registers (this, regnum); - /* The target did not throw an error so we can discard invalidating the - register and restore the cleanup chain to what it was. */ - discard_cleanups (old_chain); + /* The target did not throw an error so we can discard invalidating + the register. */ + invalidator.release (); } void