[PATCH]: Promote float args on i386 (attn Hurd, Cygwin, DJGPP...)

Michael Snyder msnyder@cygnus.com
Thu May 11 22:58:00 GMT 2000


Hello, 

>From the evidence, it appears that i386-gcc passes floats on the
stack after promoting them to doubles.  At least I've verified this
on Linux, Solaris and Unixware.  This patch fixes five testsuite 
failures by making GDB pass floats as doubles when it calls a 
target function.  I'd appreciate verification / approval from the
maintainers of other x86 platforms such as Hurd, DJGPP, Cygwin, 
BSD etc.  If this change isn't good for some of you, we can
move the #define PUSH_ARGUMENTS into the individual tm.h files.

2000-05-11  Michael Snyder  <msnyder@cleaver.cygnus.com>

	* i386-tdep.c (i386_push_arguments): New function; differs from
	default_push_arguments in that it promotes floats to doubles.
	* valops.c (value_push): Export.
	* value.h (value_push): Declare.
	* config/i386/tm-i386.h (PUSH_ARGUMENTS): Define.


Index: value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.4
diff -p -r1.4 value.h
*** value.h	2000/04/27 15:33:01	1.4
--- value.h	2000/05/12 05:47:05
*************** extern int baseclass_offset PARAMS ((str
*** 548,553 ****
--- 548,555 ----
  
  /* From valops.c */
  
+ extern CORE_ADDR value_push PARAMS ((CORE_ADDR, value_ptr));
+ 
  extern value_ptr varying_to_slice PARAMS ((value_ptr));
  
  extern value_ptr value_slice PARAMS ((value_ptr, int, int));
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.12
diff -p -r1.12 valops.c
*** valops.c	2000/04/22 06:44:39	1.12
--- valops.c	2000/05/12 05:47:06
*************** static CORE_ADDR find_function_addr PARA
*** 47,54 ****
  static value_ptr value_arg_coerce PARAMS ((value_ptr, struct type *, int));
  
  
- static CORE_ADDR value_push PARAMS ((CORE_ADDR, value_ptr));
- 
  static value_ptr search_struct_field PARAMS ((char *, value_ptr, int,
  					      struct type *, int));
  
--- 47,52 ----
*************** push_bytes (sp, buffer, len)
*** 1072,1078 ****
  /* Push onto the stack the specified value VALUE.  Pad it correctly for
     it to be an argument to a function.  */
  
! static CORE_ADDR
  value_push (sp, arg)
       register CORE_ADDR sp;
       value_ptr arg;
--- 1070,1076 ----
  /* Push onto the stack the specified value VALUE.  Pad it correctly for
     it to be an argument to a function.  */
  
! CORE_ADDR
  value_push (sp, arg)
       register CORE_ADDR sp;
       value_ptr arg;
Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.9
diff -p -r1.9 i386-tdep.c
*** i386-tdep.c	2000/03/26 21:21:50	1.9
--- i386-tdep.c	2000/05/12 05:47:06
*************** i386_push_dummy_frame ()
*** 636,641 ****
--- 636,668 ----
    write_register (SP_REGNUM, sp);
  }
  
+ /* PUSH_ARGUMENTS for the 386 differs from the default in that
+    floats are promoted to doubles.  MVS  5/11/2000 */
+ 
+ CORE_ADDR
+ i386_push_arguments (nargs, args, sp, struct_return, struct_addr)
+      int nargs;
+      value_ptr *args;
+      CORE_ADDR sp;
+      int struct_return;
+      CORE_ADDR struct_addr;
+ {
+   /* ASSERT ( !struct_return); */
+   int i;
+ 
+   for (i = nargs - 1; i >= 0; i--)
+     {
+       value_ptr copyarg = args[i];
+       struct type *argtype = check_typedef (VALUE_TYPE (copyarg));
+ 
+       if (TYPE_CODE (argtype) == TYPE_CODE_FLT && TYPE_LENGTH (argtype) == 4)
+ 	copyarg = value_cast (builtin_type_double, copyarg);
+ 
+       sp = value_push (sp, copyarg);
+     }
+   return sp;
+ }
+ 
  void
  i386_pop_frame ()
  {
Index: config/i386/tm-i386.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/tm-i386.h,v
retrieving revision 1.5
diff -p -r1.5 tm-i386.h
*** tm-i386.h	2000/04/14 19:13:07	1.5
--- tm-i386.h	2000/05/12 05:47:06
*************** extern void print_387_status_word PARAMS
*** 428,431 ****
--- 428,438 ----
  
  #define SP_ARG0 (1 * 4)
  
+ /* Don't use the default push_arguments.
+    i386 requires floats to be passed as longs.  */
+ 
+ struct value;
+ #define PUSH_ARGUMENTS i386_push_arguments
+ extern CORE_ADDR i386_push_arguments PARAMS ((int, struct value **,
+ 					      CORE_ADDR, int, CORE_ADDR));
  #endif /* ifndef TM_I386_H */


More information about the Gdb-patches mailing list