[5/5] Fix fixed-point "return" on ARM

Message ID 20231020-arm-params-v1-5-19d4c89c11b6@adacore.com
State New
Headers
Series ARM function-calling / return fixes |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Testing failed
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Testing failed

Commit Message

Tom Tromey Oct. 20, 2023, 7:15 p.m. UTC
  On a big-endian ARM machine, the "return" command resulted in the
wrong value being returned when the function had a fixed-point return
type.  This patch fixes the problem by unpacking and repacking the
fixed-point type appropriately.
---
 gdb/arm-tdep.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
  

Comments

Luis Machado Oct. 23, 2023, 1:16 p.m. UTC | #1
On 10/20/23 20:15, Tom Tromey wrote:
> On a big-endian ARM machine, the "return" command resulted in the
> wrong value being returned when the function had a fixed-point return
> type.  This patch fixes the problem by unpacking and repacking the
> fixed-point type appropriately.
> ---
>  gdb/arm-tdep.c | 18 +++++++++++++++---
>  1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index 62412d92f85..a9c43b27265 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -9170,16 +9170,28 @@ arm_store_return_value (struct type *type, struct regcache *regs,
>  	   || type->code () == TYPE_CODE_BOOL
>  	   || type->code () == TYPE_CODE_PTR
>  	   || TYPE_IS_REFERENCE (type)
> -	   || type->code () == TYPE_CODE_ENUM)
> +	   || type->code () == TYPE_CODE_ENUM
> +	   || is_fixed_point_type (type))
>      {
>        if (type->length () <= 4)
>  	{
>  	  /* Values of one word or less are zero/sign-extended and
>  	     returned in r0.  */
>  	  bfd_byte tmpbuf[ARM_INT_REGISTER_SIZE];
> -	  LONGEST val = unpack_long (type, valbuf);
>  
> -	  store_signed_integer (tmpbuf, ARM_INT_REGISTER_SIZE, byte_order, val);
> +	  if (is_fixed_point_type (type))
> +	    {
> +	      gdb_mpz unscaled;
> +	      unscaled.read (gdb::make_array_view (valbuf, type->length ()),
> +			     byte_order, type->is_unsigned ());
> +	      unscaled.write (gdb::make_array_view (tmpbuf, sizeof (tmpbuf)),
> +			      byte_order, type->is_unsigned ());
> +	    }
> +	  else
> +	    {
> +	      LONGEST val = unpack_long (type, valbuf);
> +	      store_signed_integer (tmpbuf, ARM_INT_REGISTER_SIZE, byte_order, val);
> +	    }
>  	  regs->cooked_write (ARM_A1_REGNUM, tmpbuf);
>  	}
>        else
> 

Thanks. This is OK.

Approved-By: Luis Machado <luis.machado@arm.com>
  

Patch

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 62412d92f85..a9c43b27265 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -9170,16 +9170,28 @@  arm_store_return_value (struct type *type, struct regcache *regs,
 	   || type->code () == TYPE_CODE_BOOL
 	   || type->code () == TYPE_CODE_PTR
 	   || TYPE_IS_REFERENCE (type)
-	   || type->code () == TYPE_CODE_ENUM)
+	   || type->code () == TYPE_CODE_ENUM
+	   || is_fixed_point_type (type))
     {
       if (type->length () <= 4)
 	{
 	  /* Values of one word or less are zero/sign-extended and
 	     returned in r0.  */
 	  bfd_byte tmpbuf[ARM_INT_REGISTER_SIZE];
-	  LONGEST val = unpack_long (type, valbuf);
 
-	  store_signed_integer (tmpbuf, ARM_INT_REGISTER_SIZE, byte_order, val);
+	  if (is_fixed_point_type (type))
+	    {
+	      gdb_mpz unscaled;
+	      unscaled.read (gdb::make_array_view (valbuf, type->length ()),
+			     byte_order, type->is_unsigned ());
+	      unscaled.write (gdb::make_array_view (tmpbuf, sizeof (tmpbuf)),
+			      byte_order, type->is_unsigned ());
+	    }
+	  else
+	    {
+	      LONGEST val = unpack_long (type, valbuf);
+	      store_signed_integer (tmpbuf, ARM_INT_REGISTER_SIZE, byte_order, val);
+	    }
 	  regs->cooked_write (ARM_A1_REGNUM, tmpbuf);
 	}
       else