Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Edjunior Barbosa Machado <emachado@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Cc: Ulrich Weigand <uweigand@de.ibm.com>,
	       Sergio Durigan Junior <sergiodj@redhat.com>
Subject: Re: [PATCH] ppc64le/gdbserver: Fix ppc_collect/supply_ptrace_register() routines
Date: Mon, 08 Sep 2014 14:40:00 -0000	[thread overview]
Message-ID: <1410187136-4222-1-git-send-email-emachado@linux.vnet.ibm.com> (raw)
In-Reply-To: <201409081151.s88BpOJX015412@d06av02.portsmouth.uk.ibm.com>

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


  reply	other threads:[~2014-09-08 14:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-05 20:00 Edjunior Barbosa Machado
2014-09-05 22:54 ` Sergio Durigan Junior
2014-09-08 11:51   ` Ulrich Weigand
2014-09-08 14:40     ` Edjunior Barbosa Machado [this message]
2014-09-08 14:43       ` Ulrich Weigand
2014-09-08 16:51         ` Edjunior Barbosa Machado
2014-09-08 15:20     ` Sergio Durigan Junior

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=1410187136-4222-1-git-send-email-emachado@linux.vnet.ibm.com \
    --to=emachado@linux.vnet.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sergiodj@redhat.com \
    --cc=uweigand@de.ibm.com \
    /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