From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17235 invoked by alias); 23 Dec 2002 20:29:32 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 17216 invoked from network); 23 Dec 2002 20:29:27 -0000 Received: from unknown (HELO crack.them.org) (65.125.64.184) by 209.249.29.67 with SMTP; 23 Dec 2002 20:29:27 -0000 Received: from nevyn.them.org ([66.93.61.169] ident=mail) by crack.them.org with asmtp (Exim 3.12 #1 (Debian)) id 18Qb4w-00054A-00 for ; Mon, 23 Dec 2002 16:29:42 -0600 Received: from drow by nevyn.them.org with local (Exim 3.36 #1 (Debian)) id 18QZDb-000583-00 for ; Mon, 23 Dec 2002 15:30:31 -0500 Date: Mon, 23 Dec 2002 14:03:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sources.redhat.com Subject: RFC: Slay COERCE_FLOAT_TO_DOUBLE Message-ID: <20021223203031.GA18990@nevyn.them.org> Mail-Followup-To: gdb-patches@sources.redhat.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.1i X-SW-Source: 2002-12/txt/msg00645.txt.bz2 I'd like to see what people think of this patch. If there's a general sense of agreement, I'll apply it (probably in early January). Eli, I'm not entirely sure I put the documentation in the right place; thoughts? COERCE_FLOAT_TO_DOUBLE is a bit of a wart. It's a target macro, but it's not a target-dependent behavior; it's actually sensitive to the debug info. So what I chose to do was to rip it out entirely. The macro was originally used to decide what to do when passing a float argument to a function that wasn't prototyped. Nominally, of course, it gets promoted to double. That's how C works and most modern ABIs are modeled after this. What actually happens, however, is a little more complex: we don't know if the function is prototyped or not! Only DWARF and DWARF-2 tell us. Stabs compilers (I only checked GCC and Sun Workshop CC, but those are the two major ones) emit the call-as type in the debug information. I.E. an unprototyped function taking a float argument will have a type signature that says it takes a double. So the easy thing to do for stabs is to set TYPE_FLAG_PROTOTYPED always, with appropriate commentary. I've done this. It caused a minor bit of testsuite churn, since some ()'s became (void)'s; I think that's OK, we know they are really void functions anyway. DWARF and DWARF-2 tell us accurately. For hpread and mdebugread, the target macros were being used to enforce what stabs used to do: mark all C++ functions as prototyped. So I pushed that change down into the debug reader. These formats seem to produce the declared-as type so there's really nothing better we can do. Then, for good measure, I added a user-settable variable ("set coerce-float-to-double") so that the user can override the normal behavior for "unprototyped" functions. You need this to call a prototyped C function on HP/UX that wants a float. It used to be impossible; definitely a step up. This kills two XPASSes in stabs and four FAILs in DWARF-2, if I remember correctly, on i386-linux. I don't have test harnesses set up on Solaris or HP/UX at the moment but I verified that the debug info is as I expect. Overall, I'm pretty fond of it, and it brings me a little closer to my testsuite goals while improving GDB instead of playing with the testsuite. -- Daniel Jacobowitz MontaVista Software Debian GNU/Linux Developer 2002-12-23 Daniel Jacobowitz * buildsym.h (processing_hp_compilation): Remove obsolete variable. * gdbarch.sh Remove include of "value.h" in gdbarch.h. (COERCE_FLOAT_TO_DOUBLE): Remove. * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * Makefile.in: Remove value_h from gdbarch_h. * valops.c (coerce_float_to_double): New variable. (default_coerce_float_to_double): Remove. (standard_coerce_float_to_double): Remove. (value_arg_coerce): Use coerce_float_to_double. (_initialize_valops): Add "set coerce-float-to-double". * value.h (default_coerce_float_to_double): Remove prototype. (standard_coerce_float_to_double): Remove prototype. * hpread.c (hpread_process_one_debug_symbol): Mark C++ functions as prototyped. * mdebugread.c (parse_symbol): Likewise. * stabsread.c (define_symbol): Mark all functions as prototyped. * hppa-tdep.c (hppa_coerce_float_to_double): Remove. * alpha-tdep.c (alpha_gdbarch_init): Remove call to set_gdbarch_coerce_float_to_double. * arm-tdep.c (arm_gdbarch_init): Likewise. * frv-tdep.c (frv_gdbarch_init): Likewise. * h8300-tdep.c (h8300_gdbarch_init): Likewise (commented out). * i386-sol2-tdep.c (i386_sol2_init_abi): Likewise. * mips-tdep.c (mips_gdbarch_init): Likewise. (mips_coerce_float_to_double): Remove. * rs6000-tdep.c (rs6000_gdbarch_init): Likewise. (rs6000_coerce_float_to_double): Remove. * s390-tdep.c (s390_gdbarch_init): Likewise. * sh-tdep.c (sh_gdbarch_init): Likewise. (sh_coerce_float_to_double): Remove. * sparc-tdep.c (sparc_gdbarch_init): Likewise. (sparc_coerce_float_to_double): Remove. * v850-tdep.c (v850_gdbarch_init): Likewise. * xstormy16-tdep.c (xstormy16_gdbarch_init): Likewise. * config/m32r/tm-m32r.h (COERCE_FLOAT_TO_DOUBLE): Remove. * config/pa/tm-hppa.h: (COERCE_FLOAT_TO_DOUBLE): Remove. (hppa_coerce_float_to_double): Remove prototype. * config/sparc/tm-sparc.h (COERCE_FLOAT_TO_DOUBLE): Remove. 2002-12-23 Daniel Jacobowitz * gdb.texinfo (Controlling GDB): Add ABI section. Document "set coerce-float-to-double". * gdbint.texinfo (COERCE_FLOAT_TO_DOUBLE): Remove documentation. 2002-12-23 Daniel Jacobowitz * gdb.base/callfuncs.exp: Don't XFAIL unprototyped functions for stabs. * gdb.base/completion.exp: Allow marker1(void) as well as marker1(). * gdb.base/whatis.exp: Always allow (void) after function names. Index: alpha-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/alpha-tdep.c,v retrieving revision 1.48 diff -u -p -r1.48 alpha-tdep.c --- alpha-tdep.c 11 Dec 2002 02:26:34 -0000 1.48 +++ alpha-tdep.c 23 Dec 2002 17:53:58 -0000 @@ -1901,10 +1901,6 @@ alpha_gdbarch_init (struct gdbarch_info set_gdbarch_inner_than (gdbarch, core_addr_lessthan); set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); - /* Floats are always passed as doubles. */ - set_gdbarch_coerce_float_to_double (gdbarch, - standard_coerce_float_to_double); - set_gdbarch_breakpoint_from_pc (gdbarch, alpha_breakpoint_from_pc); set_gdbarch_decr_pc_after_break (gdbarch, 4); Index: arm-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/arm-tdep.c,v retrieving revision 1.84 diff -u -p -r1.84 arm-tdep.c --- arm-tdep.c 21 Dec 2002 19:58:07 -0000 1.84 +++ arm-tdep.c 23 Dec 2002 17:53:59 -0000 @@ -2914,8 +2914,6 @@ arm_gdbarch_init (struct gdbarch_info in set_gdbarch_push_return_address (gdbarch, arm_push_return_address); set_gdbarch_push_arguments (gdbarch, arm_push_arguments); - set_gdbarch_coerce_float_to_double (gdbarch, - standard_coerce_float_to_double); /* Frame handling. */ set_gdbarch_frame_chain_valid (gdbarch, arm_frame_chain_valid); Index: buildsym.h =================================================================== RCS file: /cvs/src/src/gdb/buildsym.h,v retrieving revision 1.7 diff -u -p -r1.7 buildsym.h --- buildsym.h 18 Nov 2002 19:14:10 -0000 1.7 +++ buildsym.h 23 Dec 2002 17:53:59 -0000 @@ -83,16 +83,6 @@ EXTERN unsigned char processing_gcc_comp EXTERN unsigned char processing_acc_compilation; -/* elz: added this flag to know when a block is compiled with HP - compilers (cc, aCC). This is necessary because of the macro - COERCE_FLOAT_TO_DOUBLE defined in tm_hppa.h, which causes a - coercion of float to double to always occur in parameter passing - for a function called by gdb (see the function value_arg_coerce in - valops.c). This is necessary only if the target was compiled with - gcc, not with HP compilers or with g++ */ - -EXTERN unsigned char processing_hp_compilation; - /* Count symbols as they are processed, for error messages. */ EXTERN unsigned int symnum; Index: frv-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/frv-tdep.c,v retrieving revision 1.11 diff -u -p -r1.11 frv-tdep.c --- frv-tdep.c 11 Dec 2002 02:26:35 -0000 1.11 +++ frv-tdep.c 23 Dec 2002 17:53:59 -0000 @@ -1097,8 +1097,6 @@ frv_gdbarch_init (struct gdbarch_info in /* Settings for calling functions in the inferior. */ set_gdbarch_call_dummy_length (gdbarch, 0); - set_gdbarch_coerce_float_to_double (gdbarch, - standard_coerce_float_to_double); set_gdbarch_push_arguments (gdbarch, frv_push_arguments); set_gdbarch_push_return_address (gdbarch, frv_push_return_address); set_gdbarch_pop_frame (gdbarch, frv_pop_frame); Index: gdbarch.c =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.c,v retrieving revision 1.173 diff -u -p -r1.173 gdbarch.c --- gdbarch.c 11 Dec 2002 20:19:39 -0000 1.173 +++ gdbarch.c 23 Dec 2002 17:54:00 -0000 @@ -199,7 +199,6 @@ struct gdbarch gdbarch_deprecated_init_frame_pc_ftype *deprecated_init_frame_pc; int believe_pcc_promotion; int believe_pcc_promotion_type; - gdbarch_coerce_float_to_double_ftype *coerce_float_to_double; gdbarch_get_saved_register_ftype *get_saved_register; gdbarch_register_convertible_ftype *register_convertible; gdbarch_register_convert_to_virtual_ftype *register_convert_to_virtual; @@ -427,7 +426,6 @@ struct gdbarch startup_gdbarch = 0, 0, 0, - 0, generic_in_function_epilogue_p, construct_inferior_arguments, 0, @@ -533,7 +531,6 @@ gdbarch_alloc (const struct gdbarch_info current_gdbarch->call_dummy_words = legacy_call_dummy_words; current_gdbarch->sizeof_call_dummy_words = legacy_sizeof_call_dummy_words; current_gdbarch->call_dummy_stack_adjust_p = -1; - current_gdbarch->coerce_float_to_double = default_coerce_float_to_double; current_gdbarch->register_convertible = generic_register_convertible_not; current_gdbarch->convert_register_p = legacy_convert_register_p; current_gdbarch->register_to_value = legacy_register_to_value; @@ -712,7 +709,6 @@ verify_gdbarch (struct gdbarch *gdbarch) fprintf_unfiltered (log, "\n\tfix_call_dummy"); /* Skip verify of deprecated_init_frame_pc_first, has predicate */ /* Skip verify of deprecated_init_frame_pc, has predicate */ - /* Skip verify of coerce_float_to_double, invalid_p == 0 */ /* Skip verify of get_saved_register, has predicate */ /* Skip verify of register_convertible, invalid_p == 0 */ /* Skip verify of register_convert_to_virtual, invalid_p == 0 */ @@ -1075,17 +1071,6 @@ gdbarch_dump (struct gdbarch *gdbarch, s (long) current_gdbarch->cannot_store_register /*CANNOT_STORE_REGISTER ()*/); #endif -#ifdef COERCE_FLOAT_TO_DOUBLE - fprintf_unfiltered (file, - "gdbarch_dump: %s # %s\n", - "COERCE_FLOAT_TO_DOUBLE(formal, actual)", - XSTRING (COERCE_FLOAT_TO_DOUBLE (formal, actual))); - if (GDB_MULTI_ARCH) - fprintf_unfiltered (file, - "gdbarch_dump: COERCE_FLOAT_TO_DOUBLE = <0x%08lx>\n", - (long) current_gdbarch->coerce_float_to_double - /*COERCE_FLOAT_TO_DOUBLE ()*/); -#endif #ifdef COFF_MAKE_MSYMBOL_SPECIAL #if GDB_MULTI_ARCH /* Macro might contain `[{}]' when not multi-arch */ @@ -3868,25 +3853,6 @@ set_gdbarch_believe_pcc_promotion_type ( int believe_pcc_promotion_type) { gdbarch->believe_pcc_promotion_type = believe_pcc_promotion_type; -} - -int -gdbarch_coerce_float_to_double (struct gdbarch *gdbarch, struct type *formal, struct type *actual) -{ - gdb_assert (gdbarch != NULL); - if (gdbarch->coerce_float_to_double == 0) - internal_error (__FILE__, __LINE__, - "gdbarch: gdbarch_coerce_float_to_double invalid"); - if (gdbarch_debug >= 2) - fprintf_unfiltered (gdb_stdlog, "gdbarch_coerce_float_to_double called\n"); - return gdbarch->coerce_float_to_double (formal, actual); -} - -void -set_gdbarch_coerce_float_to_double (struct gdbarch *gdbarch, - gdbarch_coerce_float_to_double_ftype coerce_float_to_double) -{ - gdbarch->coerce_float_to_double = coerce_float_to_double; } int Index: gdbarch.h =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.h,v retrieving revision 1.134 diff -u -p -r1.134 gdbarch.h --- gdbarch.h 11 Dec 2002 20:19:39 -0000 1.134 +++ gdbarch.h 23 Dec 2002 17:54:00 -0000 @@ -38,7 +38,6 @@ #include "dis-asm.h" /* Get defs for disassemble_info, which unfortunately is a typedef. */ #if !GDB_MULTI_ARCH /* Pull in function declarations refered to, indirectly, via macros. */ -#include "value.h" /* For default_coerce_float_to_double which is referenced by a macro. */ #include "inferior.h" /* For unsigned_address_to_pointer(). */ #endif @@ -1271,23 +1270,6 @@ extern void set_gdbarch_believe_pcc_prom #if GDB_MULTI_ARCH #if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) || !defined (BELIEVE_PCC_PROMOTION_TYPE) #define BELIEVE_PCC_PROMOTION_TYPE (gdbarch_believe_pcc_promotion_type (current_gdbarch)) -#endif -#endif - -/* Default (function) for non- multi-arch platforms. */ -#if (!GDB_MULTI_ARCH) && !defined (COERCE_FLOAT_TO_DOUBLE) -#define COERCE_FLOAT_TO_DOUBLE(formal, actual) (default_coerce_float_to_double (formal, actual)) -#endif - -typedef int (gdbarch_coerce_float_to_double_ftype) (struct type *formal, struct type *actual); -extern int gdbarch_coerce_float_to_double (struct gdbarch *gdbarch, struct type *formal, struct type *actual); -extern void set_gdbarch_coerce_float_to_double (struct gdbarch *gdbarch, gdbarch_coerce_float_to_double_ftype *coerce_float_to_double); -#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (COERCE_FLOAT_TO_DOUBLE) -#error "Non multi-arch definition of COERCE_FLOAT_TO_DOUBLE" -#endif -#if GDB_MULTI_ARCH -#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) || !defined (COERCE_FLOAT_TO_DOUBLE) -#define COERCE_FLOAT_TO_DOUBLE(formal, actual) (gdbarch_coerce_float_to_double (current_gdbarch, formal, actual)) #endif #endif Index: gdbarch.sh =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.sh,v retrieving revision 1.185 diff -u -p -r1.185 gdbarch.sh --- gdbarch.sh 11 Dec 2002 20:19:39 -0000 1.185 +++ gdbarch.sh 23 Dec 2002 17:54:01 -0000 @@ -518,7 +518,6 @@ F::DEPRECATED_INIT_FRAME_PC:CORE_ADDR:de # v:2:BELIEVE_PCC_PROMOTION:int:believe_pcc_promotion::::::: v:2:BELIEVE_PCC_PROMOTION_TYPE:int:believe_pcc_promotion_type::::::: -f:2:COERCE_FLOAT_TO_DOUBLE:int:coerce_float_to_double:struct type *formal, struct type *actual:formal, actual:::default_coerce_float_to_double::0 F:2:GET_SAVED_REGISTER:void:get_saved_register:char *raw_buffer, int *optimized, CORE_ADDR *addrp, struct frame_info *frame, int regnum, enum lval_type *lval:raw_buffer, optimized, addrp, frame, regnum, lval # f:2:REGISTER_CONVERTIBLE:int:register_convertible:int nr:nr:::generic_register_convertible_not::0 @@ -779,7 +778,6 @@ cat < la_language == language_c); } static struct gdbarch * Index: hpread.c =================================================================== RCS file: /cvs/src/src/gdb/hpread.c,v retrieving revision 1.27 diff -u -p -r1.27 hpread.c --- hpread.c 17 Dec 2002 00:39:07 -0000 1.27 +++ hpread.c 23 Dec 2002 17:54:03 -0000 @@ -5242,6 +5242,11 @@ hpread_process_one_debug_symbol (union d SYMBOL_CLASS (sym) = LOC_BLOCK; SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile, 1); + /* All functions in C++ have prototypes. For C we don't have enough + information in the debug info. */ + if (SYMBOL_LANGUAGE (s) == language_cplus) + TYPE_FLAGS (SYMBOL_TYPE (s)) |= TYPE_FLAG_PROTOTYPED; + /* The "SYMBOL_NAME" field is expected to be the mangled name * (if any), which we get from the "alias" field of the SOM record * if that exists. Index: i386-sol2-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/i386-sol2-tdep.c,v retrieving revision 1.8 diff -u -p -r1.8 i386-sol2-tdep.c --- i386-sol2-tdep.c 21 Dec 2002 19:58:07 -0000 1.8 +++ i386-sol2-tdep.c 23 Dec 2002 17:54:03 -0000 @@ -47,10 +47,6 @@ i386_sol2_init_abi (struct gdbarch_info tdep->sigcontext_addr = i386bsd_sigcontext_addr; tdep->sc_pc_offset = 36 + 14 * 4; tdep->sc_sp_offset = 36 + 17 * 4; - - /* Assume that the prototype flag can be trusted. */ - set_gdbarch_coerce_float_to_double (gdbarch, - standard_coerce_float_to_double); } Index: mdebugread.c =================================================================== RCS file: /cvs/src/src/gdb/mdebugread.c,v retrieving revision 1.32 diff -u -p -r1.32 mdebugread.c --- mdebugread.c 17 Dec 2002 00:39:07 -0000 1.32 +++ mdebugread.c 23 Dec 2002 17:54:04 -0000 @@ -795,6 +795,11 @@ parse_symbol (SYMR *sh, union aux_ext *a /* Make a type for the procedure itself */ SYMBOL_TYPE (s) = lookup_function_type (t); + /* All functions in C++ have prototypes. For C we don't have enough + information in the debug info. */ + if (SYMBOL_LANGUAGE (s) == language_cplus) + TYPE_FLAGS (SYMBOL_TYPE (s)) |= TYPE_FLAG_PROTOTYPED; + /* Create and enter a new lexical context */ b = new_block (top_stack->maxsyms); SYMBOL_BLOCK_VALUE (s) = b; Index: mips-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/mips-tdep.c,v retrieving revision 1.148 diff -u -p -r1.148 mips-tdep.c --- mips-tdep.c 21 Dec 2002 06:36:02 -0000 1.148 +++ mips-tdep.c 23 Dec 2002 17:54:06 -0000 @@ -5453,24 +5453,6 @@ mips_call_dummy_address (void) } -/* If the current gcc for this target does not produce correct debugging - information for float parameters, both prototyped and unprototyped, then - define this macro. This forces gdb to always assume that floats are - passed as doubles and then converted in the callee. - - For the mips chip, it appears that the debug info marks the parameters as - floats regardless of whether the function is prototyped, but the actual - values are passed as doubles for the non-prototyped case and floats for - the prototyped case. Thus we choose to make the non-prototyped case work - for C and break the prototyped case, since the non-prototyped case is - probably much more common. (FIXME). */ - -static int -mips_coerce_float_to_double (struct type *formal, struct type *actual) -{ - return current_language->la_language == language_c; -} - /* When debugging a 64 MIPS target running a 32 bit ABI, the size of the register stored on the stack (32) is different to its real raw size (64). The below ensures that registers are fetched from the @@ -6012,8 +5994,6 @@ mips_gdbarch_init (struct gdbarch_info i mips_register_convert_to_virtual); set_gdbarch_register_convert_to_raw (gdbarch, mips_register_convert_to_raw); - - set_gdbarch_coerce_float_to_double (gdbarch, mips_coerce_float_to_double); set_gdbarch_frame_chain (gdbarch, mips_frame_chain); set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid); Index: rs6000-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v retrieving revision 1.100 diff -u -p -r1.100 rs6000-tdep.c --- rs6000-tdep.c 18 Dec 2002 15:23:22 -0000 1.100 +++ rs6000-tdep.c 23 Dec 2002 17:54:06 -0000 @@ -1855,17 +1855,6 @@ rs6000_register_virtual_type (int n) } } -/* For the PowerPC, it appears that the debug info marks float parameters as - floats regardless of whether the function is prototyped, but the actual - values are always passed in as doubles. Tell gdb to always assume that - floats are passed as doubles and then converted in the callee. */ - -static int -rs6000_coerce_float_to_double (struct type *formal, struct type *actual) -{ - return 1; -} - /* Return whether register N requires conversion when moving from raw format to virtual format. @@ -2906,7 +2895,6 @@ rs6000_gdbarch_init (struct gdbarch_info set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos); set_gdbarch_push_return_address (gdbarch, ppc_push_return_address); set_gdbarch_believe_pcc_promotion (gdbarch, 1); - set_gdbarch_coerce_float_to_double (gdbarch, rs6000_coerce_float_to_double); set_gdbarch_register_convertible (gdbarch, rs6000_register_convertible); set_gdbarch_register_convert_to_virtual (gdbarch, rs6000_register_convert_to_virtual); Index: s390-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/s390-tdep.c,v retrieving revision 1.62 diff -u -p -r1.62 s390-tdep.c --- s390-tdep.c 11 Dec 2002 02:26:36 -0000 1.62 +++ s390-tdep.c 23 Dec 2002 17:54:07 -0000 @@ -1840,8 +1840,6 @@ s390_gdbarch_init (struct gdbarch_info i set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (s390_call_dummy_words)); set_gdbarch_call_dummy_words (gdbarch, s390_call_dummy_words); - set_gdbarch_coerce_float_to_double (gdbarch, - standard_coerce_float_to_double); switch (info.bfd_arch_info->mach) { Index: sh-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/sh-tdep.c,v retrieving revision 1.82 diff -u -p -r1.82 sh-tdep.c --- sh-tdep.c 11 Dec 2002 02:26:36 -0000 1.82 +++ sh-tdep.c 23 Dec 2002 17:54:07 -0000 @@ -2319,12 +2319,6 @@ sh_fix_call_dummy (char *dummy, CORE_ADD } #endif -static int -sh_coerce_float_to_double (struct type *formal, struct type *actual) -{ - return 1; -} - /* Find a function's return value in the appropriate registers (in regbuf), and copy it into valbuf. Extract from an array REGBUF containing the (raw) register state a function return value of type @@ -4575,8 +4569,6 @@ sh_gdbarch_init (struct gdbarch_info inf set_gdbarch_call_dummy_p (gdbarch, 1); set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0); set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy); - set_gdbarch_coerce_float_to_double (gdbarch, - sh_coerce_float_to_double); set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame); set_gdbarch_push_return_address (gdbarch, sh_push_return_address); Index: sparc-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/sparc-tdep.c,v retrieving revision 1.53 diff -u -p -r1.53 sparc-tdep.c --- sparc-tdep.c 11 Dec 2002 20:35:43 -0000 1.53 +++ sparc-tdep.c 23 Dec 2002 17:54:08 -0000 @@ -3007,14 +3007,6 @@ sparc_gdbarch_fix_call_dummy (char *dumm sparc_fix_call_dummy (dummy, pc, fun, type, gcc_p); } -/* Coerce float to double: a no-op. */ - -static int -sparc_coerce_float_to_double (struct type *formal, struct type *actual) -{ - return 1; -} - /* CALL_DUMMY_ADDRESS: fetch the breakpoint address for a call dummy. */ static CORE_ADDR @@ -3138,8 +3130,6 @@ sparc_gdbarch_init (struct gdbarch_info /* First set settings that are common for all sparc architectures. */ set_gdbarch_believe_pcc_promotion (gdbarch, 1); set_gdbarch_breakpoint_from_pc (gdbarch, memory_breakpoint_from_pc); - set_gdbarch_coerce_float_to_double (gdbarch, - sparc_coerce_float_to_double); set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1); set_gdbarch_call_dummy_p (gdbarch, 1); set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 1); Index: stabsread.c =================================================================== RCS file: /cvs/src/src/gdb/stabsread.c,v retrieving revision 1.46 diff -u -p -r1.46 stabsread.c --- stabsread.c 17 Dec 2002 00:39:08 -0000 1.46 +++ stabsread.c 23 Dec 2002 17:54:09 -0000 @@ -1569,9 +1569,13 @@ define_symbol (CORE_ADDR valu, char *str if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC) SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym)); - /* All functions in C++ have prototypes. */ - if (SYMBOL_LANGUAGE (sym) == language_cplus) - TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED; + /* All functions in C++ have prototypes. Stabs does not offer an + explicit way to identify prototyped or unprototyped functions, + but both GCC and Sun CC emit stabs for the "call-as" type rather + than the "declared-as" type for unprototyped functions, so + we treat all functions as if they were prototyped. This is used + primarily for promotion when calling the function from GDB. */ + TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED; /* fall into process_prototype_types */ Index: v850-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/v850-tdep.c,v retrieving revision 1.30 diff -u -p -r1.30 v850-tdep.c --- v850-tdep.c 11 Dec 2002 02:26:36 -0000 1.30 +++ v850-tdep.c 23 Dec 2002 17:54:09 -0000 @@ -1256,8 +1256,6 @@ v850_gdbarch_init (struct gdbarch_info i set_gdbarch_frame_args_skip (gdbarch, 0); /* OK to default this value to 'unknown'. */ set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown); - /* W/o prototype, coerce float args to double. */ - set_gdbarch_coerce_float_to_double (gdbarch, standard_coerce_float_to_double); /* * Call Dummies Index: valops.c =================================================================== RCS file: /cvs/src/src/gdb/valops.c,v retrieving revision 1.84 diff -u -p -r1.84 valops.c --- valops.c 4 Dec 2002 00:05:53 -0000 1.84 +++ valops.c 23 Dec 2002 17:54:10 -0000 @@ -89,8 +89,30 @@ int overload_resolution = 0; The default is to stop in the frame where the signal was received. */ int unwind_on_signal_p = 0; - +/* How you should pass arguments to a function depends on whether it + was defined in K&R style or prototype style. If you define a + function using the K&R syntax that takes a `float' argument, then + callers must pass that argument as a `double'. If you define the + function using the prototype syntax, then you must pass the + argument as a `float', with no promotion. + + Unfortunately, on certain older platforms, the debug info doesn't + indicate reliably how each function was defined. A function type's + TYPE_FLAG_PROTOTYPED flag may be clear, even if the function was + defined in prototype style. When calling a function whose + TYPE_FLAG_PROTOTYPED flag is clear, GDB consults this flag to decide + what to do. + + For modern targets, it is proper to assume that, if the prototype + flag is clear, that can be trusted: `float' arguments should be + promoted to `double'. For some older targets, if the prototype + flag is clear, that doesn't tell us anything. The default is to + trust the debug information; the user can override this behavior + with "set coerce-float-to-double 0". */ + +static int coerce_float_to_double; + /* Find the address of function name NAME in the inferior. */ @@ -1097,49 +1119,6 @@ default_push_arguments (int nargs, struc return sp; } - -/* Functions to use for the COERCE_FLOAT_TO_DOUBLE gdbarch method. - - How you should pass arguments to a function depends on whether it - was defined in K&R style or prototype style. If you define a - function using the K&R syntax that takes a `float' argument, then - callers must pass that argument as a `double'. If you define the - function using the prototype syntax, then you must pass the - argument as a `float', with no promotion. - - Unfortunately, on certain older platforms, the debug info doesn't - indicate reliably how each function was defined. A function type's - TYPE_FLAG_PROTOTYPED flag may be clear, even if the function was - defined in prototype style. When calling a function whose - TYPE_FLAG_PROTOTYPED flag is clear, GDB consults the - COERCE_FLOAT_TO_DOUBLE gdbarch method to decide what to do. - - For modern targets, it is proper to assume that, if the prototype - flag is clear, that can be trusted: `float' arguments should be - promoted to `double'. You should register the function - `standard_coerce_float_to_double' to get this behavior. - - For some older targets, if the prototype flag is clear, that - doesn't tell us anything. So we guess that, if we don't have a - type for the formal parameter (i.e., the first argument to - COERCE_FLOAT_TO_DOUBLE is null), then we should promote it; - otherwise, we should leave it alone. The function - `default_coerce_float_to_double' provides this behavior; it is the - default value, for compatibility with older configurations. */ -int -default_coerce_float_to_double (struct type *formal, struct type *actual) -{ - return formal == NULL; -} - - -int -standard_coerce_float_to_double (struct type *formal, struct type *actual) -{ - return 1; -} - - /* Perform the standard coercions that are specified for arguments to be passed to C functions. @@ -1182,11 +1161,7 @@ value_arg_coerce (struct value *arg, str type = builtin_type_int; break; case TYPE_CODE_FLT: - /* FIXME: We should always convert floats to doubles in the - non-prototyped case. As many debugging formats include - no information about prototyping, we have to live with - COERCE_FLOAT_TO_DOUBLE for now. */ - if (!is_prototyped && COERCE_FLOAT_TO_DOUBLE (param_type, arg_type)) + if (!is_prototyped && coerce_float_to_double) { if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_double)) type = builtin_type_double; @@ -3554,4 +3529,19 @@ is received while in a function called f unwinds the stack and restore the context to what as it was before the call.\n\ The default is to stop in the frame where the signal was received.", &setlist), &showlist); + + add_show_from_set + (add_set_cmd ("coerce-float-to-double", class_obscure, var_boolean, + (char *) &coerce_float_to_double, + "Set coercion of floats to doubles when calling functions\n" + "Variables of type float should generally be converted to doubles before\n" + "calling an unprototyped function, and left alone when calling a prototyped\n" + "function. However, some older debug info formats do not provide enough\n" + "information to determine that a function is prototyped. If this flag is\n" + "set, GDB will perform the conversion for a function it considers\n" + "unprototyped.\n" + "The default is to perform the conversion.\n", + &setlist), + &showlist); + coerce_float_to_double = 1; } Index: value.h =================================================================== RCS file: /cvs/src/src/gdb/value.h,v retrieving revision 1.37 diff -u -p -r1.37 value.h --- value.h 14 Oct 2002 02:02:42 -0000 1.37 +++ value.h 23 Dec 2002 17:54:10 -0000 @@ -548,10 +548,6 @@ extern struct value *value_slice (struct extern struct value *call_function_by_hand (struct value *, int, struct value **); -extern int default_coerce_float_to_double (struct type *, struct type *); - -extern int standard_coerce_float_to_double (struct type *, struct type *); - extern struct value *value_literal_complex (struct value *, struct value *, struct type *); Index: xstormy16-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/xstormy16-tdep.c,v retrieving revision 1.14 diff -u -p -r1.14 xstormy16-tdep.c --- xstormy16-tdep.c 11 Dec 2002 02:26:36 -0000 1.14 +++ xstormy16-tdep.c 23 Dec 2002 17:54:11 -0000 @@ -1078,10 +1078,6 @@ xstormy16_gdbarch_init (struct gdbarch_i /* OK to default this value to 'unknown'. */ set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown); - /* W/o prototype, coerce float args to double. */ - set_gdbarch_coerce_float_to_double (gdbarch, - standard_coerce_float_to_double); - /* * Call Dummies * Index: config/m32r/tm-m32r.h =================================================================== RCS file: /cvs/src/src/gdb/config/m32r/tm-m32r.h,v retrieving revision 1.13 diff -u -p -r1.13 tm-m32r.h --- config/m32r/tm-m32r.h 11 Dec 2002 02:26:37 -0000 1.13 +++ config/m32r/tm-m32r.h 23 Dec 2002 17:54:11 -0000 @@ -164,8 +164,6 @@ extern CORE_ADDR m32r_skip_prologue (COR /* mvs_no_check FRAME_NUM_ARGS */ #define FRAME_NUM_ARGS(fi) (-1) -#define COERCE_FLOAT_TO_DOUBLE(formal, actual) (1) - extern void m32r_write_sp (CORE_ADDR val); #define TARGET_WRITE_SP m32r_write_sp Index: config/pa/tm-hppa.h =================================================================== RCS file: /cvs/src/src/gdb/config/pa/tm-hppa.h,v retrieving revision 1.26 diff -u -p -r1.26 tm-hppa.h --- config/pa/tm-hppa.h 11 Dec 2002 02:26:37 -0000 1.26 +++ config/pa/tm-hppa.h 23 Dec 2002 17:54:11 -0000 @@ -688,16 +688,6 @@ extern CORE_ADDR target_read_fp (int); extern int hpread_adjust_stack_address (CORE_ADDR); -/* If the current gcc for for this target does not produce correct debugging - information for float parameters, both prototyped and unprototyped, then - define this macro. This forces gdb to always assume that floats are - passed as doubles and then converted in the callee. */ - -extern int hppa_coerce_float_to_double (struct type *formal, - struct type *actual); -#define COERCE_FLOAT_TO_DOUBLE(formal, actual) \ - hppa_coerce_float_to_double (formal, actual) - /* Here's how to step off a permanent breakpoint. */ #define SKIP_PERMANENT_BREAKPOINT (hppa_skip_permanent_breakpoint) extern void hppa_skip_permanent_breakpoint (void); Index: config/sparc/tm-sparc.h =================================================================== RCS file: /cvs/src/src/gdb/config/sparc/tm-sparc.h,v retrieving revision 1.26 diff -u -p -r1.26 tm-sparc.h --- config/sparc/tm-sparc.h 11 Dec 2002 02:26:38 -0000 1.26 +++ config/sparc/tm-sparc.h 23 Dec 2002 17:54:11 -0000 @@ -280,14 +280,6 @@ extern void sparc_store_return_value (st extern CORE_ADDR sparc_extract_struct_value_address (char *); -/* If the current gcc for for this target does not produce correct - debugging information for float parameters, both prototyped and - unprototyped, then define this macro. This forces gdb to always - assume that floats are passed as doubles and then converted in the - callee. */ - -#define COERCE_FLOAT_TO_DOUBLE(FORMAL, ACTUAL) (1) - /* Stack must be aligned on 64-bit boundaries when synthesizing function calls (128-bit for sparc64). */ Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.131 diff -u -p -r1.131 gdb.texinfo --- doc/gdb.texinfo 11 Oct 2002 16:13:15 -0000 1.131 +++ doc/gdb.texinfo 23 Dec 2002 17:54:15 -0000 @@ -12778,6 +12778,7 @@ described here. * History:: Command history * Screen Size:: Screen size * Numbers:: Numbers +* ABI:: Configuring the current ABI * Messages/Warnings:: Optional warnings and messages * Debugging Output:: Optional messages about internal happenings @end menu @@ -13022,6 +13023,39 @@ Display the current default base for num @kindex show output-radix @item show output-radix Display the current default base for numeric display. +@end table + +@node ABI +@section Configuring the current ABI + +@value{GDBN} can determine the ABI (Application Binary Interface) of your +application automatically. However, sometimes you need to override its +conclusions. Use these commands to manage @value{GDBN}'s view of the +current ABI. + +@cindex float promotion +@kindex set coerce-float-to-double + +Generally, the way that an argument of type @code{float} is passed to a +function depends on whether the function is prototyped. For a prototyped +(i.e. ANSI/ISO style) function, @code{float} arguments are passed unchanged, +according to the architecture's convention for @code{float}. For unprototyped +(i.e. K&R style) functions, @code{float} arguments are first promoted to type +@code{double} and then passed. + +Unfortunately, some forms of debug information do not reliably indicate whether +a function is prototyped. If @value{GDBN} calls a function that is not marked +as prototyped, it consults @kbd{set coerce-float-to-double}. + +@table @code +@item set coerce-float-to-double +@itemx set coerce-float-to-double on +Arguments of type @code{float} will be promoted to @code{double} when passed +to an unprototyped function. This is the default setting. + +@item set coerce-float-to-double off +Arguments of type @code{float} will be passed directly to unprototyped +functions. @end table @node Messages/Warnings Index: doc/gdbint.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdbint.texinfo,v retrieving revision 1.110 diff -u -p -r1.110 gdbint.texinfo --- doc/gdbint.texinfo 11 Dec 2002 02:26:38 -0000 1.110 +++ doc/gdbint.texinfo 23 Dec 2002 17:54:17 -0000 @@ -3142,50 +3142,6 @@ and to cancel any deferred stores. Currently only implemented correctly for native Sparc configurations? -@item COERCE_FLOAT_TO_DOUBLE (@var{formal}, @var{actual}) -@findex COERCE_FLOAT_TO_DOUBLE -@cindex promotion to @code{double} -@cindex @code{float} arguments -@cindex prototyped functions, passing arguments to -@cindex passing arguments to prototyped functions -Return non-zero if GDB should promote @code{float} values to -@code{double} when calling a non-prototyped function. The argument -@var{actual} is the type of the value we want to pass to the function. -The argument @var{formal} is the type of this argument, as it appears in -the function's definition. Note that @var{formal} may be zero if we -have no debugging information for the function, or if we're passing more -arguments than are officially declared (for example, varargs). This -macro is never invoked if the function definitely has a prototype. - -How you should pass arguments to a function depends on whether it was -defined in K&R style or prototype style. If you define a function using -the K&R syntax that takes a @code{float} argument, then callers must -pass that argument as a @code{double}. If you define the function using -the prototype syntax, then you must pass the argument as a @code{float}, -with no promotion. - -Unfortunately, on certain older platforms, the debug info doesn't -indicate reliably how each function was defined. A function type's -@code{TYPE_FLAG_PROTOTYPED} flag may be unset, even if the function was -defined in prototype style. When calling a function whose -@code{TYPE_FLAG_PROTOTYPED} flag is unset, GDB consults the -@code{COERCE_FLOAT_TO_DOUBLE} macro to decide what to do. - -@findex standard_coerce_float_to_double -For modern targets, it is proper to assume that, if the prototype flag -is unset, that can be trusted: @code{float} arguments should be promoted -to @code{double}. You should use the function -@code{standard_coerce_float_to_double} to get this behavior. - -@findex default_coerce_float_to_double -For some older targets, if the prototype flag is unset, that doesn't -tell us anything. So we guess that, if we don't have a type for the -formal parameter (@i{i.e.}, the first argument to -@code{COERCE_FLOAT_TO_DOUBLE} is null), then we should promote it; -otherwise, we should leave it alone. The function -@code{default_coerce_float_to_double} provides this behavior; it is the -default value, for compatibility with older configurations. - @item int CONVERT_REGISTER_P(@var{regnum}) @findex CONVERT_REGISTER_P Return non-zero if register @var{regnum} can represent data values in a Index: testsuite/gdb.base/callfuncs.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/callfuncs.exp,v retrieving revision 1.9 diff -u -p -r1.9 callfuncs.exp --- testsuite/gdb.base/callfuncs.exp 6 Jan 2002 14:42:39 -0000 1.9 +++ testsuite/gdb.base/callfuncs.exp 23 Dec 2002 17:54:18 -0000 @@ -143,9 +143,6 @@ proc do_function_calls {} { gdb_test "p t_float_values(float_val1,-2.3765)" " = 1" # Test passing of arguments which might not be widened. - # Under stabs, GCC doesn't tell us whether the function was - # prototyped or not. - if {$gcc_compiled} { setup_xfail_format "stabs" } gdb_test "p t_float_values2(0.0,0.0)" " = 0" # Although PR 5318 mentions SunOS specifically, this seems @@ -157,9 +154,6 @@ proc do_function_calls {} { } } - # Under stabs, GCC doesn't tell us whether the function was - # prototyped or not. - if {$gcc_compiled} { setup_xfail_format "stabs" } gdb_test "p t_float_values2(3.14159,float_val2)" " = 1" gdb_test "p t_small_values(1,2,3,4,5,6,7,8,9,10)" " = 55" Index: testsuite/gdb.base/completion.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/completion.exp,v retrieving revision 1.13 diff -u -p -r1.13 completion.exp --- testsuite/gdb.base/completion.exp 17 May 2002 22:03:34 -0000 1.13 +++ testsuite/gdb.base/completion.exp 23 Dec 2002 17:54:18 -0000 @@ -705,7 +705,7 @@ gdb_expect { -re "marker1.*$gdb_prompt info func marker$"\ { send_gdb "\n" gdb_expect { - -re "All functions matching regular expression \"marker\":.*File.*break.c:\r\nint marker1\\(\\);\r\nint marker2\\(int\\).*marker3\\(char.*char.*\\).*marker4\\(long int\\);.*$gdb_prompt $"\ + -re "All functions matching regular expression \"marker\":.*File.*break.c:\r\nint marker1\\((void|)\\);\r\nint marker2\\(int\\).*marker3\\(char.*char.*\\).*marker4\\(long int\\);.*$gdb_prompt $"\ { pass "complete 'info func mar'"} -re ".*$gdb_prompt $" { fail "complete 'info func mar'"} timeout {fail "(timeout) complete 'info func mar'"} Index: testsuite/gdb.base/whatis.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/whatis.exp,v retrieving revision 1.4 diff -u -p -r1.4 whatis.exp --- testsuite/gdb.base/whatis.exp 4 May 2002 15:18:21 -0000 1.4 +++ testsuite/gdb.base/whatis.exp 23 Dec 2002 17:54:18 -0000 @@ -301,15 +301,13 @@ gdb_test "whatis v_union2" \ "whatis unnamed union" -if { [istarget "hppa*-hp-hpux*"] && $hp_aCC_compiler } { - # HP-UX: HP aCC compiler w/ +objdebug option detects language as - # c++, so we need the 'void' pattern here. - # Without +objdebug compilation option we still need to match ''. - # - guo - set void "(void|)" -} else { - set void "" -} +# HP-UX: HP aCC compiler w/ +objdebug option detects language as +# c++, so we need the 'void' pattern here. +# Without +objdebug compilation option we still need to match ''. +# - guo +# Also, using stabs we will mark these functions as prototyped. This +# is harmless but causes an extra VOID to be printed. +set void "(void|)" # test whatis command with functions return type gdb_test "whatis v_char_func" \ Index: Makefile.in =================================================================== RCS file: /cvs/src/src/gdb/Makefile.in,v retrieving revision 1.297 diff -u -p -r1.297 Makefile.in --- Makefile.in 21 Dec 2002 05:07:36 -0000 1.297 +++ Makefile.in 23 Dec 2002 19:48:21 -0000 @@ -662,7 +662,7 @@ gdb_string_h = gdb_string.h gdb_thread_db_h = gdb_thread_db.h gdb_vfork_h = gdb_vfork.h gdb_wait_h = gdb_wait.h -gdbarch_h = gdbarch.h $(dis_asm_h) $(value_h) $(inferior_h) +gdbarch_h = gdbarch.h $(dis_asm_h) $(inferior_h) gdbcmd_h = gdbcmd.h $(command_h) $(ui_out_h) gdbcore_h = gdbcore.h $(bfd_h) gdbthread_h = gdbthread.h $(breakpoint_h) $(frame_h)