From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 4/5] Remove make_cleanup_regcache_invalidate
Date: Sun, 24 Sep 2017 02:46:00 -0000 [thread overview]
Message-ID: <20170924024608.4346-5-tom@tromey.com> (raw)
In-Reply-To: <20170924024608.4346-1-tom@tromey.com>
This removes make_cleanup_regcache_invalidate in favor of a simple
RAII class that handles register invalidation.
ChangeLog
2017-09-23 Tom Tromey <tom@tromey.com>
* 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
--
2.9.5
next prev parent reply other threads:[~2017-09-24 2:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-24 2:46 [RFA 0/5] remove cleanups from regcache Tom Tromey
2017-09-24 2:46 ` Tom Tromey [this message]
2017-09-25 20:04 ` [RFA 4/5] Remove make_cleanup_regcache_invalidate Yao Qi
2017-09-26 1:36 ` Tom Tromey
2017-09-26 1:56 ` Tom Tromey
2017-09-24 2:46 ` [RFA 5/5] Remove the last cleanup from regcache.c Tom Tromey
2017-09-24 2:46 ` [RFA 1/5] Remove regcache_xmalloc Tom Tromey
2017-09-26 4:55 ` Tom Tromey
2017-09-26 5:10 ` Sergio Durigan Junior
2017-09-24 2:46 ` [RFA 3/5] Remove make_cleanup_regcache_xfree Tom Tromey
2017-09-24 2:46 ` [RFA 2/5] Remove regcache_xfree Tom Tromey
2017-09-26 0:08 ` [RFA 0/5] remove cleanups from regcache Yao Qi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170924024608.4346-5-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox