[PATCH 10/26] gdbserver: convert registers_to_string into regcache::registers_to_string

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

Convert the free `registers_to_string` function into a method of
the regcache struct.
---
gdbserver/regcache.cc | 12 +++++-------
gdbserver/regcache.h | 9 ++++-----
gdbserver/server.cc | 4 ++--
3 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 1db78951cc2..92dc6fc921c 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -214,16 +214,14 @@ find_register_by_number (const struct target_desc *tdesc, int n)
#ifndef IN_PROCESS_AGENT

void
-registers_to_string (struct regcache *regcache, char *buf)
+regcache::registers_to_string (char *buf)
{
- unsigned char *registers = regcache->registers;
- const struct target_desc *tdesc = regcache->tdesc;
-
+ unsigned char *regs = registers;
for (int i = 0; i < tdesc->reg_defs.size (); ++i)
{
- if (regcache->register_status[i] == REG_VALID)
+ if (register_status[i] == REG_VALID)
{
- bin2hex (registers, buf, register_size (tdesc, i));
+ bin2hex (regs, buf, register_size (tdesc, i));
buf += register_size (tdesc, i) * 2;
}
else
@@ -231,7 +229,7 @@ registers_to_string (struct regcache *regcache, char *buf)
memset (buf, 'x', register_size (tdesc, i) * 2);
buf += register_size (tdesc, i) * 2;
}
- registers += register_size (tdesc, i);
+ regs += register_size (tdesc, i);
}
*buf = '\0';
}
diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h
index b4a9d8864ae..bed3151dcad 100644
--- a/gdbserver/regcache.h
+++ b/gdbserver/regcache.h
@@ -84,6 +84,10 @@ struct regcache : public reg_buffer_common

/* Discard the cache without storing the registers to the target. */
void discard ();
+
+ /* Convert all registers to a string in the currently specified remote
+ format. */
+ void registers_to_string (char *buf);
};

regcache *get_thread_regcache (thread_info *thread, bool fetch = true);
@@ -106,11 +110,6 @@ void regcache_invalidate (void);

void regcache_release (void);

-/* Convert all registers to a string in the currently specified remote
- format. */
-
-void registers_to_string (struct regcache *regcache, char *buf);
-
/* Convert a string to register values and fill our register cache. */

void registers_from_string (struct regcache *regcache, char *buf);
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 521f13c07d7..f540cc86f7b 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -4241,7 +4241,7 @@ process_serial_event (void)

if (fetch_traceframe_registers (cs.current_traceframe,
&a_regcache, -1) == 0)
- registers_to_string (&a_regcache, cs.own_buf);
+ a_regcache.registers_to_string (cs.own_buf);
else
write_enn (cs.own_buf);
}
@@ -4254,7 +4254,7 @@ process_serial_event (void)
else
{
regcache = get_thread_regcache (current_thread);
- registers_to_string (regcache, cs.own_buf);
+ regcache->registers_to_string (cs.own_buf);
}
}
break;
--
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