From: Yao Qi <yao@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: [patch] Handle return small struct in rs600 (size is not 4/8)
Date: Mon, 15 Aug 2011 15:22:00 -0000 [thread overview]
Message-ID: <4E4939A9.70000@codesourcery.com> (raw)
[-- 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
next reply other threads:[~2011-08-15 15:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-15 15:22 Yao Qi [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E4939A9.70000@codesourcery.com \
--to=yao@codesourcery.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox