This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] ppc64le/gdbserver: Fix ppc_collect/supply_ptrace_register() routines
- From: Edjunior Barbosa Machado <emachado at linux dot vnet dot ibm dot com>
- To: gdb-patches at sourceware dot org
- Cc: Ulrich Weigand <uweigand at de dot ibm dot com>, Sergio Durigan Junior <sergiodj at redhat dot com>
- Date: Mon, 8 Sep 2014 11:38:56 -0300
- Subject: Re: [PATCH] ppc64le/gdbserver: Fix ppc_collect/supply_ptrace_register() routines
- Authentication-results: sourceware.org; auth=none
Thanks Sergio and Ulrich for the review. Here is the patch with the suggested
modifications.
Thanks and regards,
--
Edjunior
gdb/gdbserver/
2014-09-08 Edjunior Barbosa Machado <emachado@linux.vnet.ibm.com>
* linux-ppc-low.c (ppc_collect_ptrace_register): Adjust routine to take
endianness into account.
(ppc_supply_ptrace_register): Likewise.
---
gdb/gdbserver/linux-ppc-low.c | 45 ++++++++++++++++++++++++++++++++---------
1 file changed, 36 insertions(+), 9 deletions(-)
diff --git a/gdb/gdbserver/linux-ppc-low.c b/gdb/gdbserver/linux-ppc-low.c
index d743311..8fd4b38 100644
--- a/gdb/gdbserver/linux-ppc-low.c
+++ b/gdb/gdbserver/linux-ppc-low.c
@@ -202,25 +202,52 @@ ppc_cannot_fetch_register (int regno)
static void
ppc_collect_ptrace_register (struct regcache *regcache, int regno, char *buf)
{
- int size = register_size (regcache->tdesc, regno);
-
memset (buf, 0, sizeof (long));
- if (size < sizeof (long))
- collect_register (regcache, regno, buf + sizeof (long) - size);
+ if (__BYTE_ORDER == __LITTLE_ENDIAN)
+ {
+ /* Little-endian values always sit at the left end of the buffer. */
+ collect_register (regcache, regno, buf);
+ }
+ else if (__BYTE_ORDER == __BIG_ENDIAN)
+ {
+ /* Big-endian values sit at the right end of the buffer. In case of
+ registers whose sizes are smaller than sizeof (long), we must use a
+ padding to access them correctly. */
+ int size = register_size (regcache->tdesc, regno);
+
+ if (size < sizeof (long))
+ collect_register (regcache, regno, buf + sizeof (long) - size);
+ else
+ collect_register (regcache, regno, buf);
+ }
else
- collect_register (regcache, regno, buf);
+ perror_with_name ("Unexpected byte order");
}
static void
ppc_supply_ptrace_register (struct regcache *regcache,
int regno, const char *buf)
{
- int size = register_size (regcache->tdesc, regno);
- if (size < sizeof (long))
- supply_register (regcache, regno, buf + sizeof (long) - size);
+ if (__BYTE_ORDER == __LITTLE_ENDIAN)
+ {
+ /* Little-endian values always sit at the left end of the buffer. */
+ supply_register (regcache, regno, buf);
+ }
+ else if (__BYTE_ORDER == __BIG_ENDIAN)
+ {
+ /* Big-endian values sit at the right end of the buffer. In case of
+ registers whose sizes are smaller than sizeof (long), we must use a
+ padding to access them correctly. */
+ int size = register_size (regcache->tdesc, regno);
+
+ if (size < sizeof (long))
+ supply_register (regcache, regno, buf + sizeof (long) - size);
+ else
+ supply_register (regcache, regno, buf);
+ }
else
- supply_register (regcache, regno, buf);
+ perror_with_name ("Unexpected byte order");
}
--
1.7.9.5