* [PATCH] gdbserver: extract code out of regcache's registers_to_string
@ 2023-06-20 12:49 Tankut Baris Aktemur
2023-06-20 14:23 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Tankut Baris Aktemur @ 2023-06-20 12:49 UTC (permalink / raw)
To: gdb-patches
Extract out code from regcache's registers_to_string to dump a single
register value to a string. Reuse the new method in
'collect_register_as_string' so that unavailable registers are dumped
as 'xx...x' instead of arbitrary values.
---
gdbserver/regcache.cc | 34 +++++++++++++++++++---------------
gdbserver/regcache.h | 5 +++++
2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 0b1141662ac..82accdb89fc 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -205,29 +205,34 @@ find_register_by_number (const struct target_desc *tdesc, int n)
return tdesc->reg_defs[n];
}
+static unsigned char *register_data (const regcache *regcache, int n);
+
#ifndef IN_PROCESS_AGENT
+void
+register_to_string (struct regcache *regcache, int n, char *buf)
+{
+ int reg_size = register_size (regcache->tdesc, n);
+
+ if (regcache->register_status[n] == REG_VALID)
+ bin2hex (register_data (regcache, n), buf, reg_size);
+ else
+ memset (buf, 'x', reg_size * 2);
+
+ buf += reg_size * 2;
+ *buf = '\0';
+}
+
void
registers_to_string (struct regcache *regcache, char *buf)
{
- unsigned char *registers = regcache->registers;
const struct target_desc *tdesc = regcache->tdesc;
for (int i = 0; i < tdesc->reg_defs.size (); ++i)
{
- if (regcache->register_status[i] == REG_VALID)
- {
- bin2hex (registers, buf, register_size (tdesc, i));
- buf += register_size (tdesc, i) * 2;
- }
- else
- {
- memset (buf, 'x', register_size (tdesc, i) * 2);
- buf += register_size (tdesc, i) * 2;
- }
- registers += register_size (tdesc, i);
+ register_to_string (regcache, i, buf);
+ buf += register_size (tdesc, i) * 2;
}
- *buf = '\0';
}
void
@@ -472,8 +477,7 @@ regcache_raw_get_unsigned_by_name (struct regcache *regcache,
void
collect_register_as_string (struct regcache *regcache, int n, char *buf)
{
- bin2hex (register_data (regcache, n), buf,
- register_size (regcache->tdesc, n));
+ register_to_string (regcache, n, buf);
}
void
diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h
index 7248bcf5808..fba9498712a 100644
--- a/gdbserver/regcache.h
+++ b/gdbserver/regcache.h
@@ -93,6 +93,11 @@ void regcache_invalidate (void);
void regcache_release (void);
+/* Convert the register N's value to a string in the currently
+ specified remote format. */
+
+void register_to_string (regcache *regcache, int n, char *buf);
+
/* Convert all registers to a string in the currently specified remote
format. */
--
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
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdbserver: extract code out of regcache's registers_to_string
2023-06-20 12:49 [PATCH] gdbserver: extract code out of regcache's registers_to_string Tankut Baris Aktemur
@ 2023-06-20 14:23 ` Tom Tromey
2023-06-20 15:58 ` Aktemur, Tankut Baris
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2023-06-20 14:23 UTC (permalink / raw)
To: Tankut Baris Aktemur via Gdb-patches; +Cc: Tankut Baris Aktemur
>>>>> "Tankut" == Tankut Baris Aktemur via Gdb-patches <gdb-patches@sourceware.org> writes:
Tankut> Extract out code from regcache's registers_to_string to dump a single
Tankut> register value to a string. Reuse the new method in
Tankut> 'collect_register_as_string' so that unavailable registers are dumped
Tankut> as 'xx...x' instead of arbitrary values.
Seems like a good idea.
Tankut> void
Tankut> collect_register_as_string (struct regcache *regcache, int n, char *buf)
Tankut> {
Tankut> - bin2hex (register_data (regcache, n), buf,
Tankut> - register_size (regcache->tdesc, n));
Tankut> + register_to_string (regcache, n, buf);
This is just a wrapper now, so I wonder if it could just be removed; or
if register_to_string should be renamed to collect_register_as_string.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] gdbserver: extract code out of regcache's registers_to_string
2023-06-20 14:23 ` Tom Tromey
@ 2023-06-20 15:58 ` Aktemur, Tankut Baris
0 siblings, 0 replies; 3+ messages in thread
From: Aktemur, Tankut Baris @ 2023-06-20 15:58 UTC (permalink / raw)
To: Tom Tromey, Tankut Baris Aktemur via Gdb-patches
On Tuesday, June 20, 2023 4:23 PM, Tom Tromey wrote:
> >>>>> "Tankut" == Tankut Baris Aktemur via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Tankut> Extract out code from regcache's registers_to_string to dump a single
> Tankut> register value to a string. Reuse the new method in
> Tankut> 'collect_register_as_string' so that unavailable registers are dumped
> Tankut> as 'xx...x' instead of arbitrary values.
>
> Seems like a good idea.
>
> Tankut> void
> Tankut> collect_register_as_string (struct regcache *regcache, int n, char *buf)
> Tankut> {
> Tankut> - bin2hex (register_data (regcache, n), buf,
> Tankut> - register_size (regcache->tdesc, n));
> Tankut> + register_to_string (regcache, n, buf);
>
>
> This is just a wrapper now, so I wonder if it could just be removed; or
> if register_to_string should be renamed to collect_register_as_string.
Thanks for the comment. I followed the latter suggestion and revised the
patch in V2 accordingly:
https://sourceware.org/pipermail/gdb-patches/2023-June/200377.html
-Baris
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
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-20 15:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-20 12:49 [PATCH] gdbserver: extract code out of regcache's registers_to_string Tankut Baris Aktemur
2023-06-20 14:23 ` Tom Tromey
2023-06-20 15:58 ` Aktemur, Tankut Baris
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).