Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] Handle return small struct in rs600 (size is not 4/8)
@ 2011-08-15 15:22 Yao Qi
  2011-08-15 15:42 ` [patch] Handle return small struct in ppc " Yao Qi
  2011-08-15 16:06 ` [patch] Handle return small struct in rs600 " Mark Kettenis
  0 siblings, 2 replies; 8+ messages in thread
From: Yao Qi @ 2011-08-15 15:22 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1276 bytes --]

Hi,
It looks to me that ppc-sysv-tdep.c:do_ppc_sysv_return_value doesn't
consider the case that returning a small struct (size <= 8) whose size
is not 4 or 8.

Supposing we have a struct defined as below,

struct C
{char c1; char c2; char c3;};
struct C c;
c.c1 = 'a'; c.c2 = 'b'; c.c3 = 'c';

The raw memory content of c is 0x616263XX (big-endian) or 0xXX636261
(little-endian).  When returning c, according to Power Arch ABI:
"Aggregates or unions whose size is less than or equal to eight bytes
shall be returned in r3 and r4, as if they were first stored in memory
area and then the low-addressed word were loaded in r3 and the
high-addressed word were loaded into r4.", the content of r3 should be
0x616263 (big-endian) or 0x636261 (little-endian).

When gdb reads r3's content via regcache_cooked_read into a buf, the
content of buf looks like this,
           buf:  [0] [1] [2] [3]
big-endian    :  00  61  62  63
little-endian :  61  62  63  00

later, when we copy the contents of buf to readbuf, we should skip 00.
Current code in gdb doesn't consider this, but it works in
little-endian.  This patch is going to fix this issue.

Regression tested on a powerpc variant board.  Many fails in
gdb.base/structs.exp are fixed.  Is this patch OK?

-- 
Yao (齐尧)

[-- Attachment #2: 0001-return_value-read-write-endianess.patch --]
[-- Type: text/x-patch, Size: 1889 bytes --]


	gdb/
	* ppc-sysv-tdep.c (do_ppc_sysv_return_value): Handle return small struct whose size is not 4 or 8.
---
 gdb/ppc-sysv-tdep.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index afe3bd2..48afc7a 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -795,12 +795,18 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct value *function,
 	  /* The value is right-padded to 8 bytes and then loaded, as
 	     two "words", into r3/r4.  */
 	  gdb_byte regvals[MAX_REGISTER_SIZE * 2];
+	  int offset = (2 * tdep->wordsize - TYPE_LENGTH (type)) % tdep->wordsize;
+
 	  regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3,
 				regvals + 0 * tdep->wordsize);
 	  if (TYPE_LENGTH (type) > tdep->wordsize)
 	    regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
 				  regvals + 1 * tdep->wordsize);
-	  memcpy (readbuf, regvals, TYPE_LENGTH (type));
+
+	  if (byte_order == BFD_ENDIAN_BIG)
+	    memcpy (readbuf, regvals + offset, TYPE_LENGTH (type));
+	  else
+	    memcpy (readbuf, regvals, TYPE_LENGTH (type));
 	}
       if (writebuf)
 	{
@@ -808,8 +814,14 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct value *function,
 	  /* The value is padded out to 8 bytes and then loaded, as
 	     two "words" into r3/r4.  */
 	  gdb_byte regvals[MAX_REGISTER_SIZE * 2];
+	  int offset = (2 * tdep->wordsize - TYPE_LENGTH (type)) % tdep->wordsize;
+
 	  memset (regvals, 0, sizeof regvals);
-	  memcpy (regvals, writebuf, TYPE_LENGTH (type));
+	  if (byte_order == BFD_ENDIAN_BIG)
+	    memcpy (regvals + offset, writebuf, TYPE_LENGTH (type));
+	  else
+	    memcpy (regvals, writebuf, TYPE_LENGTH (type));
+
 	  regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
 				 regvals + 0 * tdep->wordsize);
 	  if (TYPE_LENGTH (type) > tdep->wordsize)
-- 
1.7.0.4


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-08-16  1:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-15 15:22 [patch] Handle return small struct in rs600 (size is not 4/8) Yao Qi
2011-08-15 15:42 ` [patch] Handle return small struct in ppc " Yao Qi
2011-08-15 16:06 ` [patch] Handle return small struct in rs600 " Mark Kettenis
2011-08-15 16:56   ` Yao Qi
2011-08-15 17:27     ` Pedro Alves
2011-08-15 18:54     ` Andreas Schwab
2011-08-16  1:41       ` Yao Qi
2011-08-15 17:57   ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox