Patchwork [5/8] Add aarch64 psuedo help functions

login
register
mail settings
Submitter Alan Hayward
Date May 11, 2018, 10:52 a.m.
Message ID <20180511105256.27388-6-alan.hayward@arm.com>
Download mbox | patch
Permalink /patch/27236/
State New
Headers show

Comments

Alan Hayward - May 11, 2018, 10:52 a.m.
Reduce code copy/paste by adding two helper functions for
aarch64_pseudo_read_value and aarch64_pseudo_write
The patch does not change any functionality.

2018-05-11  Alan Hayward  <alan.hayward@arm.com>

	* aarch64-tdep.c (aarch64_pseudo_read_value_2): New helper func.
	(aarch64_pseudo_write_2): Likewise.
	(aarch64_pseudo_read_value): Use helper.
	(aarch64_pseudo_write): Likewise.
---
 gdb/aarch64-tdep.c | 173 +++++++++++++++++------------------------------------
 1 file changed, 54 insertions(+), 119 deletions(-)
Simon Marchi - May 31, 2018, 12:06 p.m.
psuedo -> pseudo in the title.

On 2018-05-11 06:52 AM, Alan Hayward wrote:
> Reduce code copy/paste by adding two helper functions for
> aarch64_pseudo_read_value and aarch64_pseudo_write
> The patch does not change any functionality.
> 
> 2018-05-11  Alan Hayward  <alan.hayward@arm.com>
> 
> 	* aarch64-tdep.c (aarch64_pseudo_read_value_2): New helper func.
> 	(aarch64_pseudo_write_2): Likewise.
> 	(aarch64_pseudo_read_value): Use helper.
> 	(aarch64_pseudo_write): Likewise.
> ---
>  gdb/aarch64-tdep.c | 173 +++++++++++++++++------------------------------------
>  1 file changed, 54 insertions(+), 119 deletions(-)
> 
> diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
> index 7893579d58..003fefb3c9 100644
> --- a/gdb/aarch64-tdep.c
> +++ b/gdb/aarch64-tdep.c
> @@ -2247,109 +2247,67 @@ aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>    return group == all_reggroup;
>  }
>  
> +/* Inner version of aarch64_pseudo_read_value.  */
> +
> +static struct value *
> +aarch64_pseudo_read_value_2 (readable_regcache *regcache, int regnum_offset,
> +			     int regsize, struct value *result_value)

It's not a big deal, but in other GDB parts we actually often use the _1 suffix
for the helper functions.

But otherwise, LGTM.

Simon
Pedro Alves - May 31, 2018, 2:57 p.m.
On 05/31/2018 01:06 PM, Simon Marchi wrote:

>> +/* Inner version of aarch64_pseudo_read_value.  */
>> +
>> +static struct value *
>> +aarch64_pseudo_read_value_2 (readable_regcache *regcache, int regnum_offset,
>> +			     int regsize, struct value *result_value)
> 
> It's not a big deal, but in other GDB parts we actually often use the _1 suffix
> for the helper functions.
> 

Also, I'd think "Helper for aarch64_pseudo_read_value." would be clearer,
because "inner version" sounds a bit odd to me.

> But otherwise, LGTM.

To me too.

Thanks,
Pedro Alves
Alan Hayward - June 4, 2018, 1:13 p.m.
Pushed with minor changes as suggested below.

> On 31 May 2018, at 13:06, Simon Marchi <simon.marchi@ericsson.com> wrote:
> 
> psuedo -> pseudo in the title.

Ok.

> 
> On 2018-05-11 06:52 AM, Alan Hayward wrote:
>> Reduce code copy/paste by adding two helper functions for
>> aarch64_pseudo_read_value and aarch64_pseudo_write
>> The patch does not change any functionality.
>> 
>> 2018-05-11  Alan Hayward  <alan.hayward@arm.com>
>> 
>> 	* aarch64-tdep.c (aarch64_pseudo_read_value_2): New helper func.
>> 	(aarch64_pseudo_write_2): Likewise.
>> 	(aarch64_pseudo_read_value): Use helper.
>> 	(aarch64_pseudo_write): Likewise.
>> ---
>> gdb/aarch64-tdep.c | 173 +++++++++++++++++------------------------------------
>> 1 file changed, 54 insertions(+), 119 deletions(-)
>> 
>> diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
>> index 7893579d58..003fefb3c9 100644
>> --- a/gdb/aarch64-tdep.c
>> +++ b/gdb/aarch64-tdep.c
>> @@ -2247,109 +2247,67 @@ aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>>   return group == all_reggroup;
>> }
>> 
>> +/* Inner version of aarch64_pseudo_read_value.  */
>> +
>> +static struct value *
>> +aarch64_pseudo_read_value_2 (readable_regcache *regcache, int regnum_offset,
>> +			     int regsize, struct value *result_value)
> 
> It's not a big deal, but in other GDB parts we actually often use the _1 suffix
> for the helper functions.

Changed to aarch64_pseudo_read_value_1 and aarch64_pseudo_write_1.

> 
> But otherwise, LGTM.
> 
> Simon


> 
> On 31 May 2018, at 15:57, Pedro Alves <palves@redhat.com> wrote:
> 
> On 05/31/2018 01:06 PM, Simon Marchi wrote:
> 
>>> +/* Inner version of aarch64_pseudo_read_value.  */
>>> +
>>> +static struct value *
>>> +aarch64_pseudo_read_value_2 (readable_regcache *regcache, int regnum_offset,
>>> +			     int regsize, struct value *result_value)
>> 
>> It's not a big deal, but in other GDB parts we actually often use the _1 suffix
>> for the helper functions.
>> 
> 
> Also, I'd think "Helper for aarch64_pseudo_read_value." would be clearer,
> because "inner version" sounds a bit odd to me.

Updated as suggested. Also updated write function too.

> 
>> But otherwise, LGTM.
> 
> To me too.
> 
> Thanks,
> Pedro Alves


Thanks!
Alan.

Patch

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 7893579d58..003fefb3c9 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -2247,109 +2247,67 @@  aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
   return group == all_reggroup;
 }
 
+/* Inner version of aarch64_pseudo_read_value.  */
+
+static struct value *
+aarch64_pseudo_read_value_2 (readable_regcache *regcache, int regnum_offset,
+			     int regsize, struct value *result_value)
+{
+  gdb_byte reg_buf[V_REGISTER_SIZE];
+  unsigned v_regnum = AARCH64_V0_REGNUM + regnum_offset;
+
+  if (regcache->raw_read (v_regnum, reg_buf) != REG_VALID)
+    mark_value_bytes_unavailable (result_value, 0,
+				  TYPE_LENGTH (value_type (result_value)));
+  else
+    memcpy (value_contents_raw (result_value), reg_buf, regsize);
+  return result_value;
+ }
+
 /* Implement the "pseudo_register_read_value" gdbarch method.  */
 
 static struct value *
-aarch64_pseudo_read_value (struct gdbarch *gdbarch,
-			   readable_regcache *regcache,
+aarch64_pseudo_read_value (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int regnum)
 {
-  gdb_byte reg_buf[V_REGISTER_SIZE];
-  struct value *result_value;
-  gdb_byte *buf;
+  struct value *result_value = allocate_value (register_type (gdbarch, regnum));
 
-  result_value = allocate_value (register_type (gdbarch, regnum));
   VALUE_LVAL (result_value) = lval_register;
   VALUE_REGNUM (result_value) = regnum;
-  buf = value_contents_raw (result_value);
 
   regnum -= gdbarch_num_regs (gdbarch);
 
   if (regnum >= AARCH64_Q0_REGNUM && regnum < AARCH64_Q0_REGNUM + 32)
-    {
-      enum register_status status;
-      unsigned v_regnum;
-
-      v_regnum = AARCH64_V0_REGNUM + regnum - AARCH64_Q0_REGNUM;
-      status = regcache->raw_read (v_regnum, reg_buf);
-      if (status != REG_VALID)
-	mark_value_bytes_unavailable (result_value, 0,
-				      TYPE_LENGTH (value_type (result_value)));
-      else
-	memcpy (buf, reg_buf, Q_REGISTER_SIZE);
-      return result_value;
-    }
+    return aarch64_pseudo_read_value_2 (regcache, regnum - AARCH64_Q0_REGNUM,
+					Q_REGISTER_SIZE, result_value);
 
   if (regnum >= AARCH64_D0_REGNUM && regnum < AARCH64_D0_REGNUM + 32)
-    {
-      enum register_status status;
-      unsigned v_regnum;
-
-      v_regnum = AARCH64_V0_REGNUM + regnum - AARCH64_D0_REGNUM;
-      status = regcache->raw_read (v_regnum, reg_buf);
-      if (status != REG_VALID)
-	mark_value_bytes_unavailable (result_value, 0,
-				      TYPE_LENGTH (value_type (result_value)));
-      else
-	memcpy (buf, reg_buf, D_REGISTER_SIZE);
-      return result_value;
-    }
+    return aarch64_pseudo_read_value_2 (regcache, regnum - AARCH64_D0_REGNUM,
+					D_REGISTER_SIZE, result_value);
 
   if (regnum >= AARCH64_S0_REGNUM && regnum < AARCH64_S0_REGNUM + 32)
-    {
-      enum register_status status;
-      unsigned v_regnum;
-
-      v_regnum = AARCH64_V0_REGNUM + regnum - AARCH64_S0_REGNUM;
-      status = regcache->raw_read (v_regnum, reg_buf);
-      if (status != REG_VALID)
-	mark_value_bytes_unavailable (result_value, 0,
-				      TYPE_LENGTH (value_type (result_value)));
-      else
-	memcpy (buf, reg_buf, S_REGISTER_SIZE);
-      return result_value;
-    }
+    return aarch64_pseudo_read_value_2 (regcache, regnum - AARCH64_S0_REGNUM,
+					S_REGISTER_SIZE, result_value);
 
   if (regnum >= AARCH64_H0_REGNUM && regnum < AARCH64_H0_REGNUM + 32)
-    {
-      enum register_status status;
-      unsigned v_regnum;
-
-      v_regnum = AARCH64_V0_REGNUM + regnum - AARCH64_H0_REGNUM;
-      status = regcache->raw_read (v_regnum, reg_buf);
-      if (status != REG_VALID)
-	mark_value_bytes_unavailable (result_value, 0,
-				      TYPE_LENGTH (value_type (result_value)));
-      else
-	memcpy (buf, reg_buf, H_REGISTER_SIZE);
-      return result_value;
-    }
+    return aarch64_pseudo_read_value_2 (regcache, regnum - AARCH64_H0_REGNUM,
+					H_REGISTER_SIZE, result_value);
 
   if (regnum >= AARCH64_B0_REGNUM && regnum < AARCH64_B0_REGNUM + 32)
-    {
-      enum register_status status;
-      unsigned v_regnum;
-
-      v_regnum = AARCH64_V0_REGNUM + regnum - AARCH64_B0_REGNUM;
-      status = regcache->raw_read (v_regnum, reg_buf);
-      if (status != REG_VALID)
-	mark_value_bytes_unavailable (result_value, 0,
-				      TYPE_LENGTH (value_type (result_value)));
-      else
-	memcpy (buf, reg_buf, B_REGISTER_SIZE);
-      return result_value;
-    }
+    return aarch64_pseudo_read_value_2 (regcache, regnum - AARCH64_B0_REGNUM,
+					B_REGISTER_SIZE, result_value);
 
   gdb_assert_not_reached ("regnum out of bound");
 }
 
-/* Implement the "pseudo_register_write" gdbarch method.  */
+/* Inner version of aarch64_pseudo_write.  */
 
 static void
-aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
-		      int regnum, const gdb_byte *buf)
+aarch64_pseudo_write_2 (struct regcache *regcache, int regnum_offset,
+			int regsize, const gdb_byte *buf)
 {
   gdb_byte reg_buf[V_REGISTER_SIZE];
+  unsigned v_regnum = AARCH64_V0_REGNUM + regnum_offset;
 
   /* Ensure the register buffer is zero, we want gdb writes of the
      various 'scalar' pseudo registers to behavior like architectural
@@ -2357,61 +2315,38 @@  aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
      zero.  */
   memset (reg_buf, 0, sizeof (reg_buf));
 
+  memcpy (reg_buf, buf, regsize);
+  regcache->raw_write (v_regnum, reg_buf);
+}
+
+/* Implement the "pseudo_register_write" gdbarch method.  */
+
+static void
+aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
+		      int regnum, const gdb_byte *buf)
+{
+
   regnum -= gdbarch_num_regs (gdbarch);
 
   if (regnum >= AARCH64_Q0_REGNUM && regnum < AARCH64_Q0_REGNUM + 32)
-    {
-      /* pseudo Q registers */
-      unsigned v_regnum;
-
-      v_regnum = AARCH64_V0_REGNUM + regnum - AARCH64_Q0_REGNUM;
-      memcpy (reg_buf, buf, Q_REGISTER_SIZE);
-      regcache_raw_write (regcache, v_regnum, reg_buf);
-      return;
-    }
+    return aarch64_pseudo_write_2 (regcache, regnum - AARCH64_Q0_REGNUM,
+				   Q_REGISTER_SIZE, buf);
 
   if (regnum >= AARCH64_D0_REGNUM && regnum < AARCH64_D0_REGNUM + 32)
-    {
-      /* pseudo D registers */
-      unsigned v_regnum;
-
-      v_regnum = AARCH64_V0_REGNUM + regnum - AARCH64_D0_REGNUM;
-      memcpy (reg_buf, buf, D_REGISTER_SIZE);
-      regcache_raw_write (regcache, v_regnum, reg_buf);
-      return;
-    }
+    return aarch64_pseudo_write_2 (regcache, regnum - AARCH64_D0_REGNUM,
+				   D_REGISTER_SIZE, buf);
 
   if (regnum >= AARCH64_S0_REGNUM && regnum < AARCH64_S0_REGNUM + 32)
-    {
-      unsigned v_regnum;
-
-      v_regnum = AARCH64_V0_REGNUM + regnum - AARCH64_S0_REGNUM;
-      memcpy (reg_buf, buf, S_REGISTER_SIZE);
-      regcache_raw_write (regcache, v_regnum, reg_buf);
-      return;
-    }
+    return aarch64_pseudo_write_2 (regcache, regnum - AARCH64_S0_REGNUM,
+				   S_REGISTER_SIZE, buf);
 
   if (regnum >= AARCH64_H0_REGNUM && regnum < AARCH64_H0_REGNUM + 32)
-    {
-      /* pseudo H registers */
-      unsigned v_regnum;
-
-      v_regnum = AARCH64_V0_REGNUM + regnum - AARCH64_H0_REGNUM;
-      memcpy (reg_buf, buf, H_REGISTER_SIZE);
-      regcache_raw_write (regcache, v_regnum, reg_buf);
-      return;
-    }
+    return aarch64_pseudo_write_2 (regcache, regnum - AARCH64_H0_REGNUM,
+				   H_REGISTER_SIZE, buf);
 
   if (regnum >= AARCH64_B0_REGNUM && regnum < AARCH64_B0_REGNUM + 32)
-    {
-      /* pseudo B registers */
-      unsigned v_regnum;
-
-      v_regnum = AARCH64_V0_REGNUM + regnum - AARCH64_B0_REGNUM;
-      memcpy (reg_buf, buf, B_REGISTER_SIZE);
-      regcache_raw_write (regcache, v_regnum, reg_buf);
-      return;
-    }
+    return aarch64_pseudo_write_2 (regcache, regnum - AARCH64_B0_REGNUM,
+				   B_REGISTER_SIZE, buf);
 
   gdb_assert_not_reached ("regnum out of bound");
 }