This is the mail archive of the gdb-patches@sources.redhat.com 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]

[RFA] sh-tdep.c: parse_dwarf2_calling_convention function


Hi,

finally the first implementation of a parse_dwarf2_calling_convention
function.  This is sh_parse_dwarf2_calling_convention, which contains
hopefully enough comment to make clear how that's supposed to work.

The function only evaluates the information given in the dwarf2 info into
a calling_convention value which is sensible for the given target.
Note that in theory it's possible just to copy the value of the dwarf2
attribute to calling_convention, but it makes sense to decouple the
value of calling_convention from the debug information for hopefully
obvious reasons.

So the below patch sets the calling_convention value to 0 for the GCC
ABI and to non-0 for the Renesas native ABI.  The next patch introduces
a simple function call which allows to request the ABI in a useful
way for functions as sh_return_value_[no]fpu and sh_push_dummy_call.

Oh, btw., the value DW_CC_GNU_renesas_sh has been defined in GCC mainline
and elf/dwarf2.h now contains this value.  This value is used by GCC
to indicate that a function is using the Renesas ABI.


Corinna

	* sh-tdep.c: Include elf/dwarf2.h.
	(sh_parse_dwarf2_calling_convention): New function.
	(sh_gdbarch_init): Install sh_parse_dwarf2_calling_convention as
	parse_dwarf2_calling_convention function.

Index: sh-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sh-tdep.c,v
retrieving revision 1.177
diff -u -p -r1.177 sh-tdep.c
--- sh-tdep.c	6 Oct 2004 08:59:02 -0000	1.177
+++ sh-tdep.c	12 Oct 2004 15:27:32 -0000
@@ -43,6 +43,7 @@
 #include "regcache.h"
 #include "doublest.h"
 #include "osabi.h"
+#include "elf/dwarf2.h"
 
 #include "sh-tdep.h"
 
@@ -1282,10 +1283,12 @@ sh3e_sh4_store_return_value (struct type
 }
 
 static enum return_value_convention
-sh_return_value_nofpu (struct gdbarch *gdbarch, struct type *type,
+sh_return_value_nofpu (struct gdbarch *gdbarch, struct type *functype,
 		       struct regcache *regcache,
 		       void *readbuf, const void *writebuf)
 {
+  struct type *type = check_typedef (TYPE_TARGET_TYPE (functype));
+
   if (sh_use_struct_convention (0, type))
     return RETURN_VALUE_STRUCT_CONVENTION;
   if (writebuf)
@@ -1296,10 +1299,12 @@ sh_return_value_nofpu (struct gdbarch *g
 }
 
 static enum return_value_convention
-sh_return_value_fpu (struct gdbarch *gdbarch, struct type *type,
+sh_return_value_fpu (struct gdbarch *gdbarch, struct type *functype,
 		     struct regcache *regcache,
 		     void *readbuf, const void *writebuf)
 {
+  struct type *type = check_typedef (TYPE_TARGET_TYPE (functype));
+
   if (sh_use_struct_convention (0, type))
     return RETURN_VALUE_STRUCT_CONVENTION;
   if (writebuf)
@@ -2509,6 +2514,26 @@ sh_in_function_epilogue_p (struct gdbarc
   return 0;
 }
 
+static void
+sh_parse_dwarf2_calling_convention (struct gdbarch *gdbarch, int has_attr,
+				    unsigned long attr_val,
+				    const char *producer,
+				    struct type *func_type)
+{
+  /* That's the case we're hoping for.  If an DW_AT_calling_convention
+     attribute is given, use it.  */
+  if (has_attr)
+    TYPE_CALLING_CONVENTION (func_type) = (attr_val == DW_CC_GNU_renesas_sh);
+  /* Otherwise, if the producer string exists and doesn't start with "GNU",
+     assume a native compiler.  */
+  else if (producer && strncmp (producer, "GNU ", 4) != 0)
+    TYPE_CALLING_CONVENTION (func_type) = 1;
+  /* Otherwise default to GCC.  */
+  else
+    TYPE_CALLING_CONVENTION (func_type) = 0;
+}   
+
+
 static gdbarch_init_ftype sh_gdbarch_init;
 
 static struct gdbarch *
@@ -2617,6 +2642,8 @@ sh_gdbarch_init (struct gdbarch_info inf
 
   set_gdbarch_in_function_epilogue_p (gdbarch, sh_in_function_epilogue_p);
 
+  set_gdbarch_parse_dwarf2_calling_convention (gdbarch, sh_parse_dwarf2_calling_convention);
+
   switch (info.bfd_arch_info->mach)
     {
     case bfd_mach_sh:

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat, Inc.


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