[PATCH 02/26] gdbserver: convert new_register_cache into a regcache constructor

Tankut Baris Aktemur via Gdb-patches
2023-02-28T11:29:14Z

Convert the `new_register_cache` function into a constructor of the
regcache struct. Also define a default ctor because it is used in
other places, in particular, tracepoint.cc.
---
gdbserver/regcache.cc | 11 +++--------
gdbserver/regcache.h | 8 ++++----
gdbserver/server.cc | 2 +-
3 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 7987c406ab4..1410dd96551 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -43,7 +43,7 @@ get_thread_regcache (struct thread_info *thread, int fetch)

gdb_assert (proc->tdesc != NULL);

- regcache = new_register_cache (proc->tdesc);
+ regcache = new struct regcache (proc->tdesc);
set_thread_regcache_data (thread, regcache);
}

@@ -151,15 +151,10 @@ regcache::initialize (const target_desc *tdesc,

#ifndef IN_PROCESS_AGENT

-struct regcache *
-new_register_cache (const struct target_desc *tdesc)
+regcache::regcache (const target_desc *tdesc)
{
- struct regcache *regcache = new struct regcache;
-
gdb_assert (tdesc->registers_size != 0);
- regcache->initialize (tdesc, nullptr);
-
- return regcache;
+ initialize (tdesc, nullptr);
}

void
diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h
index 15b7e2b4dff..0002726ed00 100644
--- a/gdbserver/regcache.h
+++ b/gdbserver/regcache.h
@@ -44,6 +44,10 @@ struct regcache : public reg_buffer_common
#ifndef IN_PROCESS_AGENT
/* One of REG_UNAVAILABLE or REG_VALID. */
unsigned char *register_status = nullptr;
+
+ /* Constructors. */
+ regcache () = default;
+ regcache (const target_desc *tdesc);
#endif

/* Init the regcache data. */
@@ -64,10 +68,6 @@ struct regcache : public reg_buffer_common

void regcache_cpy (struct regcache *dst, struct regcache *src);

-/* Create a new register cache for INFERIOR. */
-
-struct regcache *new_register_cache (const struct target_desc *tdesc);
-
struct regcache *get_thread_regcache (struct thread_info *thread, int fetch);

/* Release all memory associated with the register cache for INFERIOR. */
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 949849b63a2..f85d7ed9cf5 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -4238,7 +4238,7 @@ process_serial_event (void)
if (cs.current_traceframe >= 0)
{
struct regcache *regcache
- = new_register_cache (current_target_desc ());
+ = new struct regcache (current_target_desc ());

if (fetch_traceframe_registers (cs.current_traceframe,
regcache, -1) == 0)
--
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