[PATCH 06/26] gdbserver: turn part of get_thread_regcache into regcache::fetch

Tankut Baris Aktemur via Gdb-patches
2023-02-28T11:30:31Z

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(-)

diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 2a8dc17ed6a..89ecdfec6f3 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -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. */
diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h
index 053ed08b20f..7eae6cb724a 100644
--- a/gdbserver/regcache.h
+++ b/gdbserver/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);
--
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva