[v2,01/11] gdbserver: dump 'xx...x' in collect_register_as_string for unavailable register

Message ID 20241230-upstream-gdbserver-regcache-v2-1-020a9514fcf0@intel.com
State New
Headers
Series gdbserver: refactor regcache |

Commit Message

Aktemur, Tankut Baris Dec. 30, 2024, 10:49 a.m. UTC
  Fix 'collect_register_as_string' so that unavailable registers are
dumped as 'xx...x' instead of arbitrary values.  This gives the
opportunity that we can reuse 'collect_register_as_string' in
'registers_to_string' for additional code simplification.

Note: This patch is also included in the "A new target to debug Intel GPUs"
series at
  https://sourceware.org/pipermail/gdb-patches/2024-December/214029.html

Reviewed-By: Luis Machado <luis.machado@arm.com>
---
 gdbserver/regcache.cc | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
  

Comments

Simon Marchi Jan. 6, 2025, 9:28 p.m. UTC | #1
On 2024-12-30 05:49, Tankut Baris Aktemur wrote:
> Fix 'collect_register_as_string' so that unavailable registers are
> dumped as 'xx...x' instead of arbitrary values.  This gives the
> opportunity that we can reuse 'collect_register_as_string' in
> 'registers_to_string' for additional code simplification.
> 
> Note: This patch is also included in the "A new target to debug Intel GPUs"
> series at
>   https://sourceware.org/pipermail/gdb-patches/2024-December/214029.html
> 
> Reviewed-By: Luis Machado <luis.machado@arm.com>

Can you please clarify in the commit message where the impact of the
change is?  I initially assumed (don't know why) this was fixing some
debug output.  I dug a bit, and it seems like it specifically changes
the behavior when sending expedited regs.

Otherwise, the code changes LGTM:

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon
  
Aktemur, Tankut Baris Jan. 9, 2025, 8:35 a.m. UTC | #2
On Monday, January 6, 2025 10:28 PM, Simon Marchi wrote:
> On 2024-12-30 05:49, Tankut Baris Aktemur wrote:
> > Fix 'collect_register_as_string' so that unavailable registers are
> > dumped as 'xx...x' instead of arbitrary values.  This gives the
> > opportunity that we can reuse 'collect_register_as_string' in
> > 'registers_to_string' for additional code simplification.
> >
> > Note: This patch is also included in the "A new target to debug Intel GPUs"
> > series at
> >   https://sourceware.org/pipermail/gdb-patches/2024-December/214029.html
> >
> > Reviewed-By: Luis Machado <luis.machado@arm.com>
> 
> Can you please clarify in the commit message where the impact of the
> change is?  I initially assumed (don't know why) this was fixing some
> debug output.  I dug a bit, and it seems like it specifically changes
> the behavior when sending expedited regs.

Yes.  I updated the commit message to include this information and pushed.
Thank you.

-Baris

> Otherwise, the code changes LGTM:
> 
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
> 
> Simon
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  

Patch

diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 5b064ae04d1e954144a76a06e92325bced5b62c2..b5c3b7e9cbaf6c267bf1b4a3d3a5ecf4f8788135 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -209,24 +209,13 @@  find_register_by_number (const struct target_desc *tdesc, int n)
 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);
+      collect_register_as_string (regcache, i, buf);
+      buf += register_size (tdesc, i) * 2;
     }
-  *buf = '\0';
 }
 
 void
@@ -492,7 +481,15 @@  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);
+  int reg_size = register_size (regcache->tdesc, n);
+
+  if (regcache->get_register_status (n) == REG_VALID)
+    bin2hex (register_data (regcache, n), buf);
+  else
+    memset (buf, 'x', reg_size * 2);
+
+  buf += reg_size * 2;
+  *buf = '\0';
 }
 
 void