Blame SOURCES/gdb-rhbz1125820-ppc64le-enablement-36of37.patch

01917d
https://sourceware.org/ml/gdb-patches/2014-09/msg00156.html
01917d
Message-Id: <1409947102-32166-1-git-send-email-emachado@linux.vnet.ibm.com>
01917d
01917d
commit 2e4bb98a0e52acbb2da4ae441b89a568af26adf8
01917d
Author: Edjunior Barbosa Machado <emachado@linux.vnet.ibm.com>
01917d
Date:   Mon Sep 8 13:37:23 2014 -0300
01917d
01917d
    Fix ppc_collect/supply_ptrace_register() routines
01917d
    
01917d
    This patch fixes the routines to collect and supply ptrace registers on ppc64le
01917d
    gdbserver. Originally written for big endian arch, they were causing several
01917d
    issues on little endian. With this fix, the number of unexpected failures in
01917d
    the testsuite dropped from 263 to 72 on ppc64le.
01917d
    
01917d
    gdb/gdbserver/ChangeLog
01917d
    
01917d
    	* linux-ppc-low.c (ppc_collect_ptrace_register): Adjust routine to take
01917d
    	endianness into account.
01917d
    	(ppc_supply_ptrace_register): Likewise.
01917d
01917d
Index: gdb-7.6.1/gdb/gdbserver/linux-ppc-low.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/gdbserver/linux-ppc-low.c
01917d
+++ gdb-7.6.1/gdb/gdbserver/linux-ppc-low.c
01917d
@@ -170,25 +170,52 @@ ppc_cannot_fetch_register (int regno)
01917d
 static void
01917d
 ppc_collect_ptrace_register (struct regcache *regcache, int regno, char *buf)
01917d
 {
01917d
-  int size = register_size (regno);
01917d
-
01917d
   memset (buf, 0, sizeof (long));
01917d
 
01917d
-  if (size < sizeof (long))
01917d
-    collect_register (regcache, regno, buf + sizeof (long) - size);
01917d
+  if (__BYTE_ORDER == __LITTLE_ENDIAN)
01917d
+    {
01917d
+      /* Little-endian values always sit at the left end of the buffer.  */
01917d
+      collect_register (regcache, regno, buf);
01917d
+    }
01917d
+  else if (__BYTE_ORDER == __BIG_ENDIAN)
01917d
+    {
01917d
+      /* Big-endian values sit at the right end of the buffer.  In case of
01917d
+         registers whose sizes are smaller than sizeof (long), we must use a
01917d
+         padding to access them correctly.  */
01917d
+      int size = register_size (regno);
01917d
+
01917d
+      if (size < sizeof (long))
01917d
+	collect_register (regcache, regno, buf + sizeof (long) - size);
01917d
+      else
01917d
+	collect_register (regcache, regno, buf);
01917d
+    }
01917d
   else
01917d
-    collect_register (regcache, regno, buf);
01917d
+    perror_with_name ("Unexpected byte order");
01917d
 }
01917d
 
01917d
 static void
01917d
 ppc_supply_ptrace_register (struct regcache *regcache,
01917d
 			    int regno, const char *buf)
01917d
 {
01917d
-  int size = register_size (regno);
01917d
-  if (size < sizeof (long))
01917d
-    supply_register (regcache, regno, buf + sizeof (long) - size);
01917d
+  if (__BYTE_ORDER == __LITTLE_ENDIAN)
01917d
+    {
01917d
+      /* Little-endian values always sit at the left end of the buffer.  */
01917d
+      supply_register (regcache, regno, buf);
01917d
+    }
01917d
+  else if (__BYTE_ORDER == __BIG_ENDIAN)
01917d
+    {
01917d
+      /* Big-endian values sit at the right end of the buffer.  In case of
01917d
+         registers whose sizes are smaller than sizeof (long), we must use a
01917d
+         padding to access them correctly.  */
01917d
+      int size = register_size (regno);
01917d
+
01917d
+      if (size < sizeof (long))
01917d
+	supply_register (regcache, regno, buf + sizeof (long) - size);
01917d
+      else
01917d
+	supply_register (regcache, regno, buf);
01917d
+    }
01917d
   else
01917d
-    supply_register (regcache, regno, buf);
01917d
+    perror_with_name ("Unexpected byte order");
01917d
 }
01917d
 
01917d