This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[commit] [1/2] Complete transition to gdbarch_return_value


Hello,

nearly all platforms have now moved to the new-style gdbarch_return_value
method, the only remaining ones are avr, frv, and ia64.  This patch converts
those as well, clearing the way to remove the old-style return value 
functions.  The new code on avr and frv should be exactly equivalent to
the old behaviour, and on ia64 I've added some missing functionality.

Tested on ia64-linux, committed to mainline.

Bye,
Ulrich


ChangeLog:

	* avr-tdep.c (avr_return_value): New function.
	(avr_gdbarch_init): Call set_gdbarch_return_value instead of
	set_gdbarch_extract_return_value.

	* fvr-tdep.c (frv_return_value): New function.
	(frv_gdbarch_init): Call set_gdbarch_return_value instead of
	set_gdbarch_extract_return_value, set_gdbarch_store_return_value,
	and set_gdbarch_deprecated_use_struct_convention.

	* ia64-tdep.c (ia64_use_struct_convention): Make static.
	Add check for structure, union, or array types.
	(ia64_extract_return_value): Make static.
	(ia64_store_return_value): Make static.  Support multi-word values.
	(ia64_return_value): New function.
	(ia64_gdbarch_init): Call set_gdbarch_return_value instead of
	set_gdbarch_extract_return_value, set_gdbarch_store_return_value,
	and set_gdbarch_deprecated_use_struct_convention.


diff -urNp gdb-orig/gdb/avr-tdep.c gdb-head/gdb/avr-tdep.c
--- gdb-orig/gdb/avr-tdep.c	2007-08-23 20:08:26.000000000 +0200
+++ gdb-head/gdb/avr-tdep.c	2007-10-12 21:48:57.000000000 +0200
@@ -827,6 +827,44 @@ avr_extract_return_value (struct type *t
     }
 }
 
+/* Determine, for architecture GDBARCH, how a return value of TYPE
+   should be returned.  If it is supposed to be returned in registers,
+   and READBUF is non-zero, read the appropriate value from REGCACHE,
+   and copy it into READBUF.  If WRITEBUF is non-zero, write the value
+   from WRITEBUF into REGCACHE.  */
+
+enum return_value_convention
+avr_return_value (struct gdbarch *gdbarch, struct type *valtype,
+		  struct regcache *regcache, gdb_byte *readbuf,
+		  const gdb_byte *writebuf)
+{
+  int struct_return = ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
+			|| TYPE_CODE (valtype) == TYPE_CODE_UNION
+			|| TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
+		       && !(TYPE_LENGTH (valtype) == 1
+			    || TYPE_LENGTH (valtype) == 2
+			    || TYPE_LENGTH (valtype) == 4
+			    || TYPE_LENGTH (valtype) == 8));
+
+  if (writebuf != NULL)
+    {
+      gdb_assert (!struct_return);
+      error (_("Cannot store return value."));
+    }
+
+  if (readbuf != NULL)
+    {
+      gdb_assert (!struct_return);
+      avr_extract_return_value (valtype, regcache, readbuf);
+    }
+
+  if (struct_return)
+    return RETURN_VALUE_STRUCT_CONVENTION;
+  else
+    return RETURN_VALUE_REGISTER_CONVENTION;
+}
+
+
 /* Put here the code to store, into fi->saved_regs, the addresses of
    the saved registers of frame described by FRAME_INFO.  This
    includes special registers such as pc and fp saved in special ways
@@ -1271,7 +1309,7 @@ avr_gdbarch_init (struct gdbarch_info in
   set_gdbarch_register_name (gdbarch, avr_register_name);
   set_gdbarch_register_type (gdbarch, avr_register_type);
 
-  set_gdbarch_extract_return_value (gdbarch, avr_extract_return_value);
+  set_gdbarch_return_value (gdbarch, avr_return_value);
   set_gdbarch_print_insn (gdbarch, print_insn_avr);
 
   set_gdbarch_push_dummy_call (gdbarch, avr_push_dummy_call);
diff -urNp gdb-orig/gdb/frv-tdep.c gdb-head/gdb/frv-tdep.c
--- gdb-orig/gdb/frv-tdep.c	2007-08-23 20:08:31.000000000 +0200
+++ gdb-head/gdb/frv-tdep.c	2007-10-12 21:48:57.000000000 +0200
@@ -1247,6 +1247,33 @@ frv_store_return_value (struct type *typ
                     _("Don't know how to return a %d-byte value."), len);
 }
 
+enum return_value_convention
+frv_return_value (struct gdbarch *gdbarch, struct type *valtype,
+		  struct regcache *regcache, gdb_byte *readbuf,
+		  const gdb_byte *writebuf)
+{
+  int struct_return = TYPE_CODE (valtype) == TYPE_CODE_STRUCT
+		      || TYPE_CODE (valtype) == TYPE_CODE_UNION
+		      || TYPE_CODE (valtype) == TYPE_CODE_ARRAY;
+
+  if (writebuf != NULL)
+    {
+      gdb_assert (!struct_return);
+      frv_store_return_value (valtype, regcache, writebuf);
+    }
+
+  if (readbuf != NULL)
+    {
+      gdb_assert (!struct_return);
+      frv_extract_return_value (valtype, regcache, readbuf);
+    }
+
+  if (struct_return)
+    return RETURN_VALUE_STRUCT_CONVENTION;
+  else
+    return RETURN_VALUE_REGISTER_CONVENTION;
+}
+
 
 /* Hardware watchpoint / breakpoint support for the FR500
    and FR400.  */
@@ -1488,10 +1515,7 @@ frv_gdbarch_init (struct gdbarch_info in
   set_gdbarch_adjust_breakpoint_address
     (gdbarch, frv_adjust_breakpoint_address);
 
-  set_gdbarch_deprecated_use_struct_convention (gdbarch, always_use_struct_convention);
-  set_gdbarch_extract_return_value (gdbarch, frv_extract_return_value);
-
-  set_gdbarch_store_return_value (gdbarch, frv_store_return_value);
+  set_gdbarch_return_value (gdbarch, frv_return_value);
 
   /* Frame stuff.  */
   set_gdbarch_unwind_pc (gdbarch, frv_unwind_pc);
diff -urNp gdb-orig/gdb/ia64-tdep.c gdb-head/gdb/ia64-tdep.c
--- gdb-orig/gdb/ia64-tdep.c	2007-10-08 14:51:54.000000000 +0200
+++ gdb-head/gdb/ia64-tdep.c	2007-10-12 21:51:49.000000000 +0200
@@ -2929,14 +2929,18 @@ static struct libunwind_descr ia64_libun
 
 #endif /* HAVE_LIBUNWIND_IA64_H  */
 
-/* Should we use DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS instead of
-   gdbarch_extract_return_value?  GCC_P is true if compiled with gcc and TYPE
-   is the type (which is known to be struct, union or array).  */
-int
-ia64_use_struct_convention (int gcc_p, struct type *type)
+static int
+ia64_use_struct_convention (struct type *type)
 {
   struct type *float_elt_type;
 
+  /* Don't use the struct convention for anything but structure,
+     union, or array types.  */
+  if (!(TYPE_CODE (type) == TYPE_CODE_STRUCT
+	|| TYPE_CODE (type) == TYPE_CODE_UNION
+	|| TYPE_CODE (type) == TYPE_CODE_ARRAY))
+    return 0;
+
   /* HFAs are structures (or arrays) consisting entirely of floating
      point values of the same length.  Up to 8 of these are returned
      in registers.  Don't use the struct convention when this is the
@@ -2951,7 +2955,7 @@ ia64_use_struct_convention (int gcc_p, s
   return TYPE_LENGTH (type) > 32;
 }
 
-void
+static void
 ia64_extract_return_value (struct type *type, struct regcache *regcache,
 			   gdb_byte *valbuf)
 {
@@ -3001,6 +3005,80 @@ ia64_extract_return_value (struct type *
     }
 }
 
+static void
+ia64_store_return_value (struct type *type, struct regcache *regcache, 
+			 const gdb_byte *valbuf)
+{
+  struct type *float_elt_type;
+
+  float_elt_type = is_float_or_hfa_type (type);
+  if (float_elt_type != NULL)
+    {
+      char to[MAX_REGISTER_SIZE];
+      int offset = 0;
+      int regnum = IA64_FR8_REGNUM;
+      int n = TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type);
+
+      while (n-- > 0)
+	{
+	  convert_typed_floating ((char *)valbuf + offset, float_elt_type,
+				  to, builtin_type_ia64_ext);
+	  regcache_cooked_write (regcache, regnum, to);
+	  offset += TYPE_LENGTH (float_elt_type);
+	  regnum++;
+	}
+    }
+  else
+    {
+      ULONGEST val;
+      int offset = 0;
+      int regnum = IA64_GR8_REGNUM;
+      int reglen = TYPE_LENGTH (register_type (get_regcache_arch (regcache),
+					       IA64_GR8_REGNUM));
+      int n = TYPE_LENGTH (type) / reglen;
+      int m = TYPE_LENGTH (type) % reglen;
+
+      while (n-- > 0)
+	{
+	  ULONGEST val;
+	  memcpy (&val, (char *)valbuf + offset, reglen);
+	  regcache_cooked_write_unsigned (regcache, regnum, val);
+	  offset += reglen;
+	  regnum++;
+	}
+
+      if (m)
+	{
+	  memcpy (&val, (char *)valbuf + offset, m);
+          regcache_cooked_write_unsigned (regcache, regnum, val);
+	}
+    }
+}
+  
+static enum return_value_convention
+ia64_return_value (struct gdbarch *gdbarch, struct type *valtype,
+		   struct regcache *regcache, gdb_byte *readbuf,
+		   const gdb_byte *writebuf)
+{
+  int struct_return = ia64_use_struct_convention (valtype);
+
+  if (writebuf != NULL)
+    {
+      gdb_assert (!struct_return);
+      ia64_store_return_value (valtype, regcache, writebuf);
+    }
+
+  if (readbuf != NULL)
+    {
+      gdb_assert (!struct_return);
+      ia64_extract_return_value (valtype, regcache, readbuf);
+    }
+
+  if (struct_return)
+    return RETURN_VALUE_STRUCT_CONVENTION;
+  else
+    return RETURN_VALUE_REGISTER_CONVENTION;
+}
 
 static int
 is_float_or_hfa_type_recurse (struct type *t, struct type **etp)
@@ -3462,21 +3540,6 @@ ia64_unwind_pc (struct gdbarch *gdbarch,
   return pc;
 }
 
-static void
-ia64_store_return_value (struct type *type, struct regcache *regcache, 
-			const gdb_byte *valbuf)
-{
-  if (TYPE_CODE (type) == TYPE_CODE_FLT)
-    {
-      char to[MAX_REGISTER_SIZE];
-      convert_typed_floating (valbuf, type, to, builtin_type_ia64_ext);
-      regcache_cooked_write (regcache, IA64_FR8_REGNUM, (void *)to);
-      target_store_registers (regcache, IA64_FR8_REGNUM);
-    }
-  else
-    regcache_cooked_write (regcache, IA64_GR8_REGNUM, valbuf);
-}
-
 static int
 ia64_print_insn (bfd_vma memaddr, struct disassemble_info *info)
 {
@@ -3544,10 +3607,7 @@ ia64_gdbarch_init (struct gdbarch_info i
 
   set_gdbarch_skip_prologue (gdbarch, ia64_skip_prologue);
 
-  set_gdbarch_deprecated_use_struct_convention (gdbarch, ia64_use_struct_convention);
-  set_gdbarch_extract_return_value (gdbarch, ia64_extract_return_value);
-
-  set_gdbarch_store_return_value (gdbarch, ia64_store_return_value);
+  set_gdbarch_return_value (gdbarch, ia64_return_value);
 
   set_gdbarch_memory_insert_breakpoint (gdbarch, ia64_memory_insert_breakpoint);
   set_gdbarch_memory_remove_breakpoint (gdbarch, ia64_memory_remove_breakpoint);
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]