Blame SOURCES/gdb-rhbz1182151-ibm-z13-15of22.patch

01917d
commit 4e65a17e62c7c2f3c0409d9769cca2e916a88379
01917d
Author: Andreas Arnez <arnez@linux.vnet.ibm.com>
01917d
Date:   Mon Apr 27 11:38:47 2015 +0200
01917d
01917d
    S390: Re-arrange implementation of s390_return_value
01917d
    
01917d
    Move related logic in the implementation of s390_return_value closer
01917d
    together.  This makes it easier to read and extend.
01917d
    
01917d
    gdb/ChangeLog:
01917d
    
01917d
    	* s390-linux-tdep.c (s390_return_value_convention): Remove
01917d
    	function.  Inline its logic...
01917d
    	(s390_return_value): ...here.  Instead, move the handling of the
01917d
    	"register" return value convention...
01917d
    	(s390_register_return_value): ...here.  New function.
01917d
01917d
### a/gdb/ChangeLog
01917d
### b/gdb/ChangeLog
01917d
## -1,5 +1,13 @@
01917d
 2015-04-27  Andreas Arnez  <arnez@linux.vnet.ibm.com>
01917d
 
01917d
+	* s390-linux-tdep.c (s390_return_value_convention): Remove
01917d
+	function.  Inline its logic...
01917d
+	(s390_return_value): ...here.  Instead, move the handling of the
01917d
+	"register" return value convention...
01917d
+	(s390_register_return_value): ...here.  New function.
01917d
+
01917d
+2015-04-27  Andreas Arnez  <arnez@linux.vnet.ibm.com>
01917d
+
01917d
 	* s390-linux-tdep.c
01917d
 	(is_float_singleton): Remove function.  Move the "singleton" part
01917d
 	of the logic...
01917d
Index: gdb-7.6.1/gdb/s390-tdep.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/s390-tdep.c	2016-02-21 22:31:47.311935241 +0100
01917d
+++ gdb-7.6.1/gdb/s390-tdep.c	2016-02-21 22:31:59.326029901 +0100
01917d
@@ -2865,110 +2865,98 @@
01917d
 }
01917d
 
01917d
 
01917d
-/* Function return value access.  */
01917d
+/* Helper for s390_return_value: Set or retrieve a function return
01917d
+   value if it resides in a register.  */
01917d
 
01917d
-static enum return_value_convention
01917d
-s390_return_value_convention (struct gdbarch *gdbarch, struct type *type)
01917d
+static void
01917d
+s390_register_return_value (struct gdbarch *gdbarch, struct type *type,
01917d
+			    struct regcache *regcache,
01917d
+			    gdb_byte *out, const gdb_byte *in)
01917d
 {
01917d
-  if (TYPE_LENGTH (type) > 8)
01917d
-    return RETURN_VALUE_STRUCT_CONVENTION;
01917d
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01917d
+  int word_size = gdbarch_ptr_bit (gdbarch) / 8;
01917d
+  int length = TYPE_LENGTH (type);
01917d
+  int code = TYPE_CODE (type);
01917d
 
01917d
-  switch (TYPE_CODE (type))
01917d
+  if (code == TYPE_CODE_FLT || code == TYPE_CODE_DECFLOAT)
01917d
     {
01917d
-    case TYPE_CODE_STRUCT:
01917d
-    case TYPE_CODE_UNION:
01917d
-    case TYPE_CODE_ARRAY:
01917d
-    case TYPE_CODE_COMPLEX:
01917d
-      return RETURN_VALUE_STRUCT_CONVENTION;
01917d
-
01917d
-    default:
01917d
-      return RETURN_VALUE_REGISTER_CONVENTION;
01917d
+      /* Float-like value: left-aligned in f0.  */
01917d
+      if (in != NULL)
01917d
+	regcache_cooked_write_part (regcache, S390_F0_REGNUM,
01917d
+				    0, length, in);
01917d
+      else
01917d
+	regcache_cooked_read_part (regcache, S390_F0_REGNUM,
01917d
+				   0, length, out);
01917d
+    }
01917d
+  else if (length <= word_size)
01917d
+    {
01917d
+      /* Integer: zero- or sign-extended in r2.  */
01917d
+      if (out != NULL)
01917d
+	regcache_cooked_read_part (regcache, S390_R2_REGNUM,
01917d
+				   word_size - length, length, out);
01917d
+      else if (TYPE_UNSIGNED (type))
01917d
+	regcache_cooked_write_unsigned
01917d
+	  (regcache, S390_R2_REGNUM,
01917d
+	   extract_unsigned_integer (in, length, byte_order));
01917d
+      else
01917d
+	regcache_cooked_write_signed
01917d
+	  (regcache, S390_R2_REGNUM,
01917d
+	   extract_signed_integer (in, length, byte_order));
01917d
     }
01917d
+  else if (length == 2 * word_size)
01917d
+    {
01917d
+      /* Double word: in r2 and r3.  */
01917d
+      if (in != NULL)
01917d
+	{
01917d
+	  regcache_cooked_write (regcache, S390_R2_REGNUM, in);
01917d
+	  regcache_cooked_write (regcache, S390_R3_REGNUM,
01917d
+				 in + word_size);
01917d
+	}
01917d
+      else
01917d
+	{
01917d
+	  regcache_cooked_read (regcache, S390_R2_REGNUM, out);
01917d
+	  regcache_cooked_read (regcache, S390_R3_REGNUM,
01917d
+				out + word_size);
01917d
+	}
01917d
+    }
01917d
+  else
01917d
+    internal_error (__FILE__, __LINE__, _("invalid return type"));
01917d
 }
01917d
 
01917d
+
01917d
+/* Implement the 'return_value' gdbarch method.  */
01917d
+
01917d
 static enum return_value_convention
01917d
 s390_return_value (struct gdbarch *gdbarch, struct value *function,
01917d
 		   struct type *type, struct regcache *regcache,
01917d
 		   gdb_byte *out, const gdb_byte *in)
01917d
 {
01917d
-  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01917d
-  int word_size = gdbarch_ptr_bit (gdbarch) / 8;
01917d
   enum return_value_convention rvc;
01917d
-  int length;
01917d
 
01917d
   type = check_typedef (type);
01917d
-  rvc = s390_return_value_convention (gdbarch, type);
01917d
-  length = TYPE_LENGTH (type);
01917d
 
01917d
-  if (in)
01917d
+  switch (TYPE_CODE (type))
01917d
     {
01917d
-      switch (rvc)
01917d
-	{
01917d
-	case RETURN_VALUE_REGISTER_CONVENTION:
01917d
-	  if (TYPE_CODE (type) == TYPE_CODE_FLT
01917d
-	      || TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
01917d
-	    {
01917d
-	      /* When we store a single-precision value in an FP register,
01917d
-		 it occupies the leftmost bits.  */
01917d
-	      regcache_cooked_write_part (regcache, S390_F0_REGNUM, 
01917d
-					  0, length, in);
01917d
-	    }
01917d
-	  else if (length <= word_size)
01917d
-	    {
01917d
-	      /* Integer arguments are always extended to word size.  */
01917d
-	      if (TYPE_UNSIGNED (type))
01917d
-		regcache_cooked_write_unsigned (regcache, S390_R2_REGNUM,
01917d
-			extract_unsigned_integer (in, length, byte_order));
01917d
-	      else
01917d
-		regcache_cooked_write_signed (regcache, S390_R2_REGNUM,
01917d
-			extract_signed_integer (in, length, byte_order));
01917d
-	    }
01917d
-	  else if (length == 2*word_size)
01917d
-	    {
01917d
-	      regcache_cooked_write (regcache, S390_R2_REGNUM, in);
01917d
-	      regcache_cooked_write (regcache, S390_R3_REGNUM, in + word_size);
01917d
-	    }
01917d
-	  else
01917d
-	    internal_error (__FILE__, __LINE__, _("invalid return type"));
01917d
-	  break;
01917d
-
01917d
-	case RETURN_VALUE_STRUCT_CONVENTION:
01917d
-	  error (_("Cannot set function return value."));
01917d
-	  break;
01917d
-	}
01917d
+    case TYPE_CODE_STRUCT:
01917d
+    case TYPE_CODE_UNION:
01917d
+    case TYPE_CODE_ARRAY:
01917d
+    case TYPE_CODE_COMPLEX:
01917d
+      rvc = RETURN_VALUE_STRUCT_CONVENTION;
01917d
+      break;
01917d
+    default:
01917d
+      rvc = TYPE_LENGTH (type) <= 8
01917d
+	? RETURN_VALUE_REGISTER_CONVENTION
01917d
+	: RETURN_VALUE_STRUCT_CONVENTION;
01917d
     }
01917d
-  else if (out)
01917d
+
01917d
+  if (in != NULL || out != NULL)
01917d
     {
01917d
-      switch (rvc)
01917d
-	{
01917d
-	case RETURN_VALUE_REGISTER_CONVENTION:
01917d
-	  if (TYPE_CODE (type) == TYPE_CODE_FLT
01917d
-	      || TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
01917d
-	    {
01917d
-	      /* When we store a single-precision value in an FP register,
01917d
-		 it occupies the leftmost bits.  */
01917d
-	      regcache_cooked_read_part (regcache, S390_F0_REGNUM, 
01917d
-					 0, length, out);
01917d
-	    }
01917d
-	  else if (length <= word_size)
01917d
-	    {
01917d
-	      /* Integer arguments occupy the rightmost bits.  */
01917d
-	      regcache_cooked_read_part (regcache, S390_R2_REGNUM, 
01917d
-					 word_size - length, length, out);
01917d
-	    }
01917d
-	  else if (length == 2*word_size)
01917d
-	    {
01917d
-	      regcache_cooked_read (regcache, S390_R2_REGNUM, out);
01917d
-	      regcache_cooked_read (regcache, S390_R3_REGNUM, out + word_size);
01917d
-	    }
01917d
-	  else
01917d
-	    internal_error (__FILE__, __LINE__, _("invalid return type"));
01917d
-	  break;
01917d
-
01917d
-	case RETURN_VALUE_STRUCT_CONVENTION:
01917d
-	  error (_("Function return value unknown."));
01917d
-	  break;
01917d
-	}
01917d
+      if (rvc == RETURN_VALUE_REGISTER_CONVENTION)
01917d
+	s390_register_return_value (gdbarch, type, regcache, out, in);
01917d
+      else if (in != NULL)
01917d
+	error (_("Cannot set function return value."));
01917d
+      else
01917d
+	error (_("Function return value unknown."));
01917d
     }
01917d
 
01917d
   return rvc;