Extract out a piece of code in get_thread_regcache that fetches the
registers from the target, and turn it into a method of 'regcache'.
---
gdbserver/regcache.cc | 23 +++++++++++++++--------
gdbserver/regcache.h | 3 +++
2 files changed, 18 insertions(+), 8 deletions(-)
@@ -48,19 +48,26 @@ get_thread_regcache (struct thread_info *thread, bool fetch)
regcache->thread = thread;
}
- if (fetch && regcache->registers_valid == 0)
+ if (fetch)
+ regcache->fetch ();
+
+ return regcache;
+}
+
+void
+regcache::fetch ()
+{
+ if (registers_valid == 0)
{
scoped_restore_current_thread restore_thread;
+ gdb_assert (this->thread != nullptr);
+ switch_to_thread (this->thread);
- switch_to_thread (thread);
/* Invalidate all registers, to prevent stale left-overs. */
- memset (regcache->register_status, REG_UNAVAILABLE,
- regcache->tdesc->reg_defs.size ());
- fetch_inferior_registers (regcache, -1);
- regcache->registers_valid = 1;
+ memset (register_status, REG_UNAVAILABLE, tdesc->reg_defs.size ());
+ fetch_inferior_registers (this, -1);
+ registers_valid = 1;
}
-
- return regcache;
}
/* See gdbsupport/common-regcache.h. */
@@ -67,6 +67,9 @@ struct regcache : public reg_buffer_common
/* See gdbsupport/common-regcache.h. */
bool raw_compare (int regnum, const void *buf, int offset) const override;
+
+ /* Fetch the registers from the target, if not done already. */
+ void fetch ();
};
void regcache_cpy (struct regcache *dst, struct regcache *src);