aboutsummaryrefslogtreecommitdiff
path: root/gdb/regcache.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-09-23 15:53:30 -0600
committerTom Tromey <tom@tromey.com>2017-09-25 19:54:08 -0600
commitb292235f666ff2123e26794db73d5a27a685e7be (patch)
tree51df281436efbdbff9c449f3ab5928c2ecd90174 /gdb/regcache.c
parent9ac86b52da268147b2565e4920357432bb7a34c3 (diff)
downloadfsf-binutils-gdb-b292235f666ff2123e26794db73d5a27a685e7be.zip
fsf-binutils-gdb-b292235f666ff2123e26794db73d5a27a685e7be.tar.gz
fsf-binutils-gdb-b292235f666ff2123e26794db73d5a27a685e7be.tar.bz2
Remove make_cleanup_regcache_invalidate
This removes make_cleanup_regcache_invalidate in favor of a simple RAII class that handles register invalidation. gdb/ChangeLog 2017-09-25 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.
Diffstat (limited to 'gdb/regcache.c')
-rw-r--r--gdb/regcache.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/gdb/regcache.c b/gdb/regcache.c
index ab6a651..3dae6f7 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_invalidate (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