public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix fixed-point "return" on ARM
@ 2023-10-30 13:50 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-10-30 13:50 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a23cf0c2ece4812232cf9434bdc77fbb70ae3f6b

commit a23cf0c2ece4812232cf9434bdc77fbb70ae3f6b
Author: Tom Tromey <tromey@adacore.com>
Date:   Wed Sep 20 11:29:53 2023 -0600

    Fix fixed-point "return" on ARM
    
    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.
    
    Approved-By: Luis Machado <luis.machado@arm.com>

Diff:
---
 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-30 13:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-30 13:50 [binutils-gdb] Fix fixed-point "return" on ARM Tom Tromey

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).