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

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