1*5796c8dcSSimon Schubert /* Perform an inferior function call, for GDB, the GNU debugger. 2*5796c8dcSSimon Schubert 3*5796c8dcSSimon Schubert Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 4*5796c8dcSSimon Schubert 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 5*5796c8dcSSimon Schubert 2008, 2009 Free Software Foundation, Inc. 6*5796c8dcSSimon Schubert 7*5796c8dcSSimon Schubert This file is part of GDB. 8*5796c8dcSSimon Schubert 9*5796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 10*5796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 11*5796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 12*5796c8dcSSimon Schubert (at your option) any later version. 13*5796c8dcSSimon Schubert 14*5796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 15*5796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 16*5796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*5796c8dcSSimon Schubert GNU General Public License for more details. 18*5796c8dcSSimon Schubert 19*5796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 20*5796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 21*5796c8dcSSimon Schubert 22*5796c8dcSSimon Schubert #include "defs.h" 23*5796c8dcSSimon Schubert #include "breakpoint.h" 24*5796c8dcSSimon Schubert #include "target.h" 25*5796c8dcSSimon Schubert #include "regcache.h" 26*5796c8dcSSimon Schubert #include "inferior.h" 27*5796c8dcSSimon Schubert #include "gdb_assert.h" 28*5796c8dcSSimon Schubert #include "block.h" 29*5796c8dcSSimon Schubert #include "gdbcore.h" 30*5796c8dcSSimon Schubert #include "language.h" 31*5796c8dcSSimon Schubert #include "objfiles.h" 32*5796c8dcSSimon Schubert #include "gdbcmd.h" 33*5796c8dcSSimon Schubert #include "command.h" 34*5796c8dcSSimon Schubert #include "gdb_string.h" 35*5796c8dcSSimon Schubert #include "infcall.h" 36*5796c8dcSSimon Schubert #include "dummy-frame.h" 37*5796c8dcSSimon Schubert #include "ada-lang.h" 38*5796c8dcSSimon Schubert #include "gdbthread.h" 39*5796c8dcSSimon Schubert #include "exceptions.h" 40*5796c8dcSSimon Schubert 41*5796c8dcSSimon Schubert /* If we can't find a function's name from its address, 42*5796c8dcSSimon Schubert we print this instead. */ 43*5796c8dcSSimon Schubert #define RAW_FUNCTION_ADDRESS_FORMAT "at 0x%s" 44*5796c8dcSSimon Schubert #define RAW_FUNCTION_ADDRESS_SIZE (sizeof (RAW_FUNCTION_ADDRESS_FORMAT) \ 45*5796c8dcSSimon Schubert + 2 * sizeof (CORE_ADDR)) 46*5796c8dcSSimon Schubert 47*5796c8dcSSimon Schubert /* NOTE: cagney/2003-04-16: What's the future of this code? 48*5796c8dcSSimon Schubert 49*5796c8dcSSimon Schubert GDB needs an asynchronous expression evaluator, that means an 50*5796c8dcSSimon Schubert asynchronous inferior function call implementation, and that in 51*5796c8dcSSimon Schubert turn means restructuring the code so that it is event driven. */ 52*5796c8dcSSimon Schubert 53*5796c8dcSSimon Schubert /* How you should pass arguments to a function depends on whether it 54*5796c8dcSSimon Schubert was defined in K&R style or prototype style. If you define a 55*5796c8dcSSimon Schubert function using the K&R syntax that takes a `float' argument, then 56*5796c8dcSSimon Schubert callers must pass that argument as a `double'. If you define the 57*5796c8dcSSimon Schubert function using the prototype syntax, then you must pass the 58*5796c8dcSSimon Schubert argument as a `float', with no promotion. 59*5796c8dcSSimon Schubert 60*5796c8dcSSimon Schubert Unfortunately, on certain older platforms, the debug info doesn't 61*5796c8dcSSimon Schubert indicate reliably how each function was defined. A function type's 62*5796c8dcSSimon Schubert TYPE_FLAG_PROTOTYPED flag may be clear, even if the function was 63*5796c8dcSSimon Schubert defined in prototype style. When calling a function whose 64*5796c8dcSSimon Schubert TYPE_FLAG_PROTOTYPED flag is clear, GDB consults this flag to 65*5796c8dcSSimon Schubert decide what to do. 66*5796c8dcSSimon Schubert 67*5796c8dcSSimon Schubert For modern targets, it is proper to assume that, if the prototype 68*5796c8dcSSimon Schubert flag is clear, that can be trusted: `float' arguments should be 69*5796c8dcSSimon Schubert promoted to `double'. For some older targets, if the prototype 70*5796c8dcSSimon Schubert flag is clear, that doesn't tell us anything. The default is to 71*5796c8dcSSimon Schubert trust the debug information; the user can override this behavior 72*5796c8dcSSimon Schubert with "set coerce-float-to-double 0". */ 73*5796c8dcSSimon Schubert 74*5796c8dcSSimon Schubert static int coerce_float_to_double_p = 1; 75*5796c8dcSSimon Schubert static void 76*5796c8dcSSimon Schubert show_coerce_float_to_double_p (struct ui_file *file, int from_tty, 77*5796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 78*5796c8dcSSimon Schubert { 79*5796c8dcSSimon Schubert fprintf_filtered (file, _("\ 80*5796c8dcSSimon Schubert Coercion of floats to doubles when calling functions is %s.\n"), 81*5796c8dcSSimon Schubert value); 82*5796c8dcSSimon Schubert } 83*5796c8dcSSimon Schubert 84*5796c8dcSSimon Schubert /* This boolean tells what gdb should do if a signal is received while 85*5796c8dcSSimon Schubert in a function called from gdb (call dummy). If set, gdb unwinds 86*5796c8dcSSimon Schubert the stack and restore the context to what as it was before the 87*5796c8dcSSimon Schubert call. 88*5796c8dcSSimon Schubert 89*5796c8dcSSimon Schubert The default is to stop in the frame where the signal was received. */ 90*5796c8dcSSimon Schubert 91*5796c8dcSSimon Schubert int unwind_on_signal_p = 0; 92*5796c8dcSSimon Schubert static void 93*5796c8dcSSimon Schubert show_unwind_on_signal_p (struct ui_file *file, int from_tty, 94*5796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 95*5796c8dcSSimon Schubert { 96*5796c8dcSSimon Schubert fprintf_filtered (file, _("\ 97*5796c8dcSSimon Schubert Unwinding of stack if a signal is received while in a call dummy is %s.\n"), 98*5796c8dcSSimon Schubert value); 99*5796c8dcSSimon Schubert } 100*5796c8dcSSimon Schubert 101*5796c8dcSSimon Schubert /* This boolean tells what gdb should do if a std::terminate call is 102*5796c8dcSSimon Schubert made while in a function called from gdb (call dummy). 103*5796c8dcSSimon Schubert As the confines of a single dummy stack prohibit out-of-frame 104*5796c8dcSSimon Schubert handlers from handling a raised exception, and as out-of-frame 105*5796c8dcSSimon Schubert handlers are common in C++, this can lead to no handler being found 106*5796c8dcSSimon Schubert by the unwinder, and a std::terminate call. This is a false positive. 107*5796c8dcSSimon Schubert If set, gdb unwinds the stack and restores the context to what it 108*5796c8dcSSimon Schubert was before the call. 109*5796c8dcSSimon Schubert 110*5796c8dcSSimon Schubert The default is to unwind the frame if a std::terminate call is 111*5796c8dcSSimon Schubert made. */ 112*5796c8dcSSimon Schubert 113*5796c8dcSSimon Schubert static int unwind_on_terminating_exception_p = 1; 114*5796c8dcSSimon Schubert 115*5796c8dcSSimon Schubert static void 116*5796c8dcSSimon Schubert show_unwind_on_terminating_exception_p (struct ui_file *file, int from_tty, 117*5796c8dcSSimon Schubert struct cmd_list_element *c, 118*5796c8dcSSimon Schubert const char *value) 119*5796c8dcSSimon Schubert 120*5796c8dcSSimon Schubert { 121*5796c8dcSSimon Schubert fprintf_filtered (file, _("\ 122*5796c8dcSSimon Schubert Unwind stack if a C++ exception is unhandled while in a call dummy is %s.\n"), 123*5796c8dcSSimon Schubert value); 124*5796c8dcSSimon Schubert } 125*5796c8dcSSimon Schubert 126*5796c8dcSSimon Schubert /* Perform the standard coercions that are specified 127*5796c8dcSSimon Schubert for arguments to be passed to C or Ada functions. 128*5796c8dcSSimon Schubert 129*5796c8dcSSimon Schubert If PARAM_TYPE is non-NULL, it is the expected parameter type. 130*5796c8dcSSimon Schubert IS_PROTOTYPED is non-zero if the function declaration is prototyped. 131*5796c8dcSSimon Schubert SP is the stack pointer were additional data can be pushed (updating 132*5796c8dcSSimon Schubert its value as needed). */ 133*5796c8dcSSimon Schubert 134*5796c8dcSSimon Schubert static struct value * 135*5796c8dcSSimon Schubert value_arg_coerce (struct gdbarch *gdbarch, struct value *arg, 136*5796c8dcSSimon Schubert struct type *param_type, int is_prototyped, CORE_ADDR *sp) 137*5796c8dcSSimon Schubert { 138*5796c8dcSSimon Schubert const struct builtin_type *builtin = builtin_type (gdbarch); 139*5796c8dcSSimon Schubert struct type *arg_type = check_typedef (value_type (arg)); 140*5796c8dcSSimon Schubert struct type *type 141*5796c8dcSSimon Schubert = param_type ? check_typedef (param_type) : arg_type; 142*5796c8dcSSimon Schubert 143*5796c8dcSSimon Schubert /* Perform any Ada-specific coercion first. */ 144*5796c8dcSSimon Schubert if (current_language->la_language == language_ada) 145*5796c8dcSSimon Schubert arg = ada_convert_actual (arg, type, gdbarch, sp); 146*5796c8dcSSimon Schubert 147*5796c8dcSSimon Schubert /* Force the value to the target if we will need its address. At 148*5796c8dcSSimon Schubert this point, we could allocate arguments on the stack instead of 149*5796c8dcSSimon Schubert calling malloc if we knew that their addresses would not be 150*5796c8dcSSimon Schubert saved by the called function. */ 151*5796c8dcSSimon Schubert arg = value_coerce_to_target (arg); 152*5796c8dcSSimon Schubert 153*5796c8dcSSimon Schubert switch (TYPE_CODE (type)) 154*5796c8dcSSimon Schubert { 155*5796c8dcSSimon Schubert case TYPE_CODE_REF: 156*5796c8dcSSimon Schubert { 157*5796c8dcSSimon Schubert struct value *new_value; 158*5796c8dcSSimon Schubert 159*5796c8dcSSimon Schubert if (TYPE_CODE (arg_type) == TYPE_CODE_REF) 160*5796c8dcSSimon Schubert return value_cast_pointers (type, arg); 161*5796c8dcSSimon Schubert 162*5796c8dcSSimon Schubert /* Cast the value to the reference's target type, and then 163*5796c8dcSSimon Schubert convert it back to a reference. This will issue an error 164*5796c8dcSSimon Schubert if the value was not previously in memory - in some cases 165*5796c8dcSSimon Schubert we should clearly be allowing this, but how? */ 166*5796c8dcSSimon Schubert new_value = value_cast (TYPE_TARGET_TYPE (type), arg); 167*5796c8dcSSimon Schubert new_value = value_ref (new_value); 168*5796c8dcSSimon Schubert return new_value; 169*5796c8dcSSimon Schubert } 170*5796c8dcSSimon Schubert case TYPE_CODE_INT: 171*5796c8dcSSimon Schubert case TYPE_CODE_CHAR: 172*5796c8dcSSimon Schubert case TYPE_CODE_BOOL: 173*5796c8dcSSimon Schubert case TYPE_CODE_ENUM: 174*5796c8dcSSimon Schubert /* If we don't have a prototype, coerce to integer type if necessary. */ 175*5796c8dcSSimon Schubert if (!is_prototyped) 176*5796c8dcSSimon Schubert { 177*5796c8dcSSimon Schubert if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin->builtin_int)) 178*5796c8dcSSimon Schubert type = builtin->builtin_int; 179*5796c8dcSSimon Schubert } 180*5796c8dcSSimon Schubert /* Currently all target ABIs require at least the width of an integer 181*5796c8dcSSimon Schubert type for an argument. We may have to conditionalize the following 182*5796c8dcSSimon Schubert type coercion for future targets. */ 183*5796c8dcSSimon Schubert if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin->builtin_int)) 184*5796c8dcSSimon Schubert type = builtin->builtin_int; 185*5796c8dcSSimon Schubert break; 186*5796c8dcSSimon Schubert case TYPE_CODE_FLT: 187*5796c8dcSSimon Schubert if (!is_prototyped && coerce_float_to_double_p) 188*5796c8dcSSimon Schubert { 189*5796c8dcSSimon Schubert if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin->builtin_double)) 190*5796c8dcSSimon Schubert type = builtin->builtin_double; 191*5796c8dcSSimon Schubert else if (TYPE_LENGTH (type) > TYPE_LENGTH (builtin->builtin_double)) 192*5796c8dcSSimon Schubert type = builtin->builtin_long_double; 193*5796c8dcSSimon Schubert } 194*5796c8dcSSimon Schubert break; 195*5796c8dcSSimon Schubert case TYPE_CODE_FUNC: 196*5796c8dcSSimon Schubert type = lookup_pointer_type (type); 197*5796c8dcSSimon Schubert break; 198*5796c8dcSSimon Schubert case TYPE_CODE_ARRAY: 199*5796c8dcSSimon Schubert /* Arrays are coerced to pointers to their first element, unless 200*5796c8dcSSimon Schubert they are vectors, in which case we want to leave them alone, 201*5796c8dcSSimon Schubert because they are passed by value. */ 202*5796c8dcSSimon Schubert if (current_language->c_style_arrays) 203*5796c8dcSSimon Schubert if (!TYPE_VECTOR (type)) 204*5796c8dcSSimon Schubert type = lookup_pointer_type (TYPE_TARGET_TYPE (type)); 205*5796c8dcSSimon Schubert break; 206*5796c8dcSSimon Schubert case TYPE_CODE_UNDEF: 207*5796c8dcSSimon Schubert case TYPE_CODE_PTR: 208*5796c8dcSSimon Schubert case TYPE_CODE_STRUCT: 209*5796c8dcSSimon Schubert case TYPE_CODE_UNION: 210*5796c8dcSSimon Schubert case TYPE_CODE_VOID: 211*5796c8dcSSimon Schubert case TYPE_CODE_SET: 212*5796c8dcSSimon Schubert case TYPE_CODE_RANGE: 213*5796c8dcSSimon Schubert case TYPE_CODE_STRING: 214*5796c8dcSSimon Schubert case TYPE_CODE_BITSTRING: 215*5796c8dcSSimon Schubert case TYPE_CODE_ERROR: 216*5796c8dcSSimon Schubert case TYPE_CODE_MEMBERPTR: 217*5796c8dcSSimon Schubert case TYPE_CODE_METHODPTR: 218*5796c8dcSSimon Schubert case TYPE_CODE_METHOD: 219*5796c8dcSSimon Schubert case TYPE_CODE_COMPLEX: 220*5796c8dcSSimon Schubert default: 221*5796c8dcSSimon Schubert break; 222*5796c8dcSSimon Schubert } 223*5796c8dcSSimon Schubert 224*5796c8dcSSimon Schubert return value_cast (type, arg); 225*5796c8dcSSimon Schubert } 226*5796c8dcSSimon Schubert 227*5796c8dcSSimon Schubert /* Determine a function's address and its return type from its value. 228*5796c8dcSSimon Schubert Calls error() if the function is not valid for calling. */ 229*5796c8dcSSimon Schubert 230*5796c8dcSSimon Schubert CORE_ADDR 231*5796c8dcSSimon Schubert find_function_addr (struct value *function, struct type **retval_type) 232*5796c8dcSSimon Schubert { 233*5796c8dcSSimon Schubert struct type *ftype = check_typedef (value_type (function)); 234*5796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (ftype); 235*5796c8dcSSimon Schubert enum type_code code = TYPE_CODE (ftype); 236*5796c8dcSSimon Schubert struct type *value_type = NULL; 237*5796c8dcSSimon Schubert CORE_ADDR funaddr; 238*5796c8dcSSimon Schubert 239*5796c8dcSSimon Schubert /* If it's a member function, just look at the function 240*5796c8dcSSimon Schubert part of it. */ 241*5796c8dcSSimon Schubert 242*5796c8dcSSimon Schubert /* Determine address to call. */ 243*5796c8dcSSimon Schubert if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD) 244*5796c8dcSSimon Schubert { 245*5796c8dcSSimon Schubert funaddr = value_address (function); 246*5796c8dcSSimon Schubert value_type = TYPE_TARGET_TYPE (ftype); 247*5796c8dcSSimon Schubert } 248*5796c8dcSSimon Schubert else if (code == TYPE_CODE_PTR) 249*5796c8dcSSimon Schubert { 250*5796c8dcSSimon Schubert funaddr = value_as_address (function); 251*5796c8dcSSimon Schubert ftype = check_typedef (TYPE_TARGET_TYPE (ftype)); 252*5796c8dcSSimon Schubert if (TYPE_CODE (ftype) == TYPE_CODE_FUNC 253*5796c8dcSSimon Schubert || TYPE_CODE (ftype) == TYPE_CODE_METHOD) 254*5796c8dcSSimon Schubert { 255*5796c8dcSSimon Schubert funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr, 256*5796c8dcSSimon Schubert ¤t_target); 257*5796c8dcSSimon Schubert value_type = TYPE_TARGET_TYPE (ftype); 258*5796c8dcSSimon Schubert } 259*5796c8dcSSimon Schubert } 260*5796c8dcSSimon Schubert else if (code == TYPE_CODE_INT) 261*5796c8dcSSimon Schubert { 262*5796c8dcSSimon Schubert /* Handle the case of functions lacking debugging info. 263*5796c8dcSSimon Schubert Their values are characters since their addresses are char */ 264*5796c8dcSSimon Schubert if (TYPE_LENGTH (ftype) == 1) 265*5796c8dcSSimon Schubert funaddr = value_as_address (value_addr (function)); 266*5796c8dcSSimon Schubert else 267*5796c8dcSSimon Schubert { 268*5796c8dcSSimon Schubert /* Handle function descriptors lacking debug info. */ 269*5796c8dcSSimon Schubert int found_descriptor = 0; 270*5796c8dcSSimon Schubert funaddr = 0; /* pacify "gcc -Werror" */ 271*5796c8dcSSimon Schubert if (VALUE_LVAL (function) == lval_memory) 272*5796c8dcSSimon Schubert { 273*5796c8dcSSimon Schubert CORE_ADDR nfunaddr; 274*5796c8dcSSimon Schubert funaddr = value_as_address (value_addr (function)); 275*5796c8dcSSimon Schubert nfunaddr = funaddr; 276*5796c8dcSSimon Schubert funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr, 277*5796c8dcSSimon Schubert ¤t_target); 278*5796c8dcSSimon Schubert if (funaddr != nfunaddr) 279*5796c8dcSSimon Schubert found_descriptor = 1; 280*5796c8dcSSimon Schubert } 281*5796c8dcSSimon Schubert if (!found_descriptor) 282*5796c8dcSSimon Schubert /* Handle integer used as address of a function. */ 283*5796c8dcSSimon Schubert funaddr = (CORE_ADDR) value_as_long (function); 284*5796c8dcSSimon Schubert } 285*5796c8dcSSimon Schubert } 286*5796c8dcSSimon Schubert else 287*5796c8dcSSimon Schubert error (_("Invalid data type for function to be called.")); 288*5796c8dcSSimon Schubert 289*5796c8dcSSimon Schubert if (retval_type != NULL) 290*5796c8dcSSimon Schubert *retval_type = value_type; 291*5796c8dcSSimon Schubert return funaddr + gdbarch_deprecated_function_start_offset (gdbarch); 292*5796c8dcSSimon Schubert } 293*5796c8dcSSimon Schubert 294*5796c8dcSSimon Schubert /* For CALL_DUMMY_ON_STACK, push a breakpoint sequence that the called 295*5796c8dcSSimon Schubert function returns to. */ 296*5796c8dcSSimon Schubert 297*5796c8dcSSimon Schubert static CORE_ADDR 298*5796c8dcSSimon Schubert push_dummy_code (struct gdbarch *gdbarch, 299*5796c8dcSSimon Schubert CORE_ADDR sp, CORE_ADDR funaddr, 300*5796c8dcSSimon Schubert struct value **args, int nargs, 301*5796c8dcSSimon Schubert struct type *value_type, 302*5796c8dcSSimon Schubert CORE_ADDR *real_pc, CORE_ADDR *bp_addr, 303*5796c8dcSSimon Schubert struct regcache *regcache) 304*5796c8dcSSimon Schubert { 305*5796c8dcSSimon Schubert gdb_assert (gdbarch_push_dummy_code_p (gdbarch)); 306*5796c8dcSSimon Schubert 307*5796c8dcSSimon Schubert return gdbarch_push_dummy_code (gdbarch, sp, funaddr, 308*5796c8dcSSimon Schubert args, nargs, value_type, real_pc, bp_addr, 309*5796c8dcSSimon Schubert regcache); 310*5796c8dcSSimon Schubert } 311*5796c8dcSSimon Schubert 312*5796c8dcSSimon Schubert /* Fetch the name of the function at FUNADDR. 313*5796c8dcSSimon Schubert This is used in printing an error message for call_function_by_hand. 314*5796c8dcSSimon Schubert BUF is used to print FUNADDR in hex if the function name cannot be 315*5796c8dcSSimon Schubert determined. It must be large enough to hold formatted result of 316*5796c8dcSSimon Schubert RAW_FUNCTION_ADDRESS_FORMAT. */ 317*5796c8dcSSimon Schubert 318*5796c8dcSSimon Schubert static const char * 319*5796c8dcSSimon Schubert get_function_name (CORE_ADDR funaddr, char *buf, int buf_size) 320*5796c8dcSSimon Schubert { 321*5796c8dcSSimon Schubert { 322*5796c8dcSSimon Schubert struct symbol *symbol = find_pc_function (funaddr); 323*5796c8dcSSimon Schubert if (symbol) 324*5796c8dcSSimon Schubert return SYMBOL_PRINT_NAME (symbol); 325*5796c8dcSSimon Schubert } 326*5796c8dcSSimon Schubert 327*5796c8dcSSimon Schubert { 328*5796c8dcSSimon Schubert /* Try the minimal symbols. */ 329*5796c8dcSSimon Schubert struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (funaddr); 330*5796c8dcSSimon Schubert if (msymbol) 331*5796c8dcSSimon Schubert return SYMBOL_PRINT_NAME (msymbol); 332*5796c8dcSSimon Schubert } 333*5796c8dcSSimon Schubert 334*5796c8dcSSimon Schubert { 335*5796c8dcSSimon Schubert char *tmp = xstrprintf (_(RAW_FUNCTION_ADDRESS_FORMAT), 336*5796c8dcSSimon Schubert hex_string (funaddr)); 337*5796c8dcSSimon Schubert gdb_assert (strlen (tmp) + 1 <= buf_size); 338*5796c8dcSSimon Schubert strcpy (buf, tmp); 339*5796c8dcSSimon Schubert xfree (tmp); 340*5796c8dcSSimon Schubert return buf; 341*5796c8dcSSimon Schubert } 342*5796c8dcSSimon Schubert } 343*5796c8dcSSimon Schubert 344*5796c8dcSSimon Schubert /* Subroutine of call_function_by_hand to simplify it. 345*5796c8dcSSimon Schubert Start up the inferior and wait for it to stop. 346*5796c8dcSSimon Schubert Return the exception if there's an error, or an exception with 347*5796c8dcSSimon Schubert reason >= 0 if there's no error. 348*5796c8dcSSimon Schubert 349*5796c8dcSSimon Schubert This is done inside a TRY_CATCH so the caller needn't worry about 350*5796c8dcSSimon Schubert thrown errors. The caller should rethrow if there's an error. */ 351*5796c8dcSSimon Schubert 352*5796c8dcSSimon Schubert static struct gdb_exception 353*5796c8dcSSimon Schubert run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc) 354*5796c8dcSSimon Schubert { 355*5796c8dcSSimon Schubert volatile struct gdb_exception e; 356*5796c8dcSSimon Schubert int saved_async = 0; 357*5796c8dcSSimon Schubert int saved_in_infcall = call_thread->in_infcall; 358*5796c8dcSSimon Schubert ptid_t call_thread_ptid = call_thread->ptid; 359*5796c8dcSSimon Schubert char *saved_target_shortname = xstrdup (target_shortname); 360*5796c8dcSSimon Schubert 361*5796c8dcSSimon Schubert call_thread->in_infcall = 1; 362*5796c8dcSSimon Schubert 363*5796c8dcSSimon Schubert clear_proceed_status (); 364*5796c8dcSSimon Schubert 365*5796c8dcSSimon Schubert disable_watchpoints_before_interactive_call_start (); 366*5796c8dcSSimon Schubert call_thread->proceed_to_finish = 1; /* We want stop_registers, please... */ 367*5796c8dcSSimon Schubert 368*5796c8dcSSimon Schubert if (target_can_async_p ()) 369*5796c8dcSSimon Schubert saved_async = target_async_mask (0); 370*5796c8dcSSimon Schubert 371*5796c8dcSSimon Schubert TRY_CATCH (e, RETURN_MASK_ALL) 372*5796c8dcSSimon Schubert proceed (real_pc, TARGET_SIGNAL_0, 0); 373*5796c8dcSSimon Schubert 374*5796c8dcSSimon Schubert /* At this point the current thread may have changed. Refresh 375*5796c8dcSSimon Schubert CALL_THREAD as it could be invalid if its thread has exited. */ 376*5796c8dcSSimon Schubert call_thread = find_thread_ptid (call_thread_ptid); 377*5796c8dcSSimon Schubert 378*5796c8dcSSimon Schubert /* Don't restore the async mask if the target has changed, 379*5796c8dcSSimon Schubert saved_async is for the original target. */ 380*5796c8dcSSimon Schubert if (saved_async 381*5796c8dcSSimon Schubert && strcmp (saved_target_shortname, target_shortname) == 0) 382*5796c8dcSSimon Schubert target_async_mask (saved_async); 383*5796c8dcSSimon Schubert 384*5796c8dcSSimon Schubert enable_watchpoints_after_interactive_call_stop (); 385*5796c8dcSSimon Schubert 386*5796c8dcSSimon Schubert /* Call breakpoint_auto_delete on the current contents of the bpstat 387*5796c8dcSSimon Schubert of inferior call thread. 388*5796c8dcSSimon Schubert If all error()s out of proceed ended up calling normal_stop 389*5796c8dcSSimon Schubert (and perhaps they should; it already does in the special case 390*5796c8dcSSimon Schubert of error out of resume()), then we wouldn't need this. */ 391*5796c8dcSSimon Schubert if (e.reason < 0) 392*5796c8dcSSimon Schubert { 393*5796c8dcSSimon Schubert if (call_thread != NULL) 394*5796c8dcSSimon Schubert breakpoint_auto_delete (call_thread->stop_bpstat); 395*5796c8dcSSimon Schubert } 396*5796c8dcSSimon Schubert 397*5796c8dcSSimon Schubert if (call_thread != NULL) 398*5796c8dcSSimon Schubert call_thread->in_infcall = saved_in_infcall; 399*5796c8dcSSimon Schubert 400*5796c8dcSSimon Schubert xfree (saved_target_shortname); 401*5796c8dcSSimon Schubert 402*5796c8dcSSimon Schubert return e; 403*5796c8dcSSimon Schubert } 404*5796c8dcSSimon Schubert 405*5796c8dcSSimon Schubert /* All this stuff with a dummy frame may seem unnecessarily complicated 406*5796c8dcSSimon Schubert (why not just save registers in GDB?). The purpose of pushing a dummy 407*5796c8dcSSimon Schubert frame which looks just like a real frame is so that if you call a 408*5796c8dcSSimon Schubert function and then hit a breakpoint (get a signal, etc), "backtrace" 409*5796c8dcSSimon Schubert will look right. Whether the backtrace needs to actually show the 410*5796c8dcSSimon Schubert stack at the time the inferior function was called is debatable, but 411*5796c8dcSSimon Schubert it certainly needs to not display garbage. So if you are contemplating 412*5796c8dcSSimon Schubert making dummy frames be different from normal frames, consider that. */ 413*5796c8dcSSimon Schubert 414*5796c8dcSSimon Schubert /* Perform a function call in the inferior. 415*5796c8dcSSimon Schubert ARGS is a vector of values of arguments (NARGS of them). 416*5796c8dcSSimon Schubert FUNCTION is a value, the function to be called. 417*5796c8dcSSimon Schubert Returns a value representing what the function returned. 418*5796c8dcSSimon Schubert May fail to return, if a breakpoint or signal is hit 419*5796c8dcSSimon Schubert during the execution of the function. 420*5796c8dcSSimon Schubert 421*5796c8dcSSimon Schubert ARGS is modified to contain coerced values. */ 422*5796c8dcSSimon Schubert 423*5796c8dcSSimon Schubert struct value * 424*5796c8dcSSimon Schubert call_function_by_hand (struct value *function, int nargs, struct value **args) 425*5796c8dcSSimon Schubert { 426*5796c8dcSSimon Schubert CORE_ADDR sp; 427*5796c8dcSSimon Schubert struct type *values_type, *target_values_type; 428*5796c8dcSSimon Schubert unsigned char struct_return = 0, lang_struct_return = 0; 429*5796c8dcSSimon Schubert CORE_ADDR struct_addr = 0; 430*5796c8dcSSimon Schubert struct inferior_status *inf_status; 431*5796c8dcSSimon Schubert struct cleanup *inf_status_cleanup; 432*5796c8dcSSimon Schubert struct inferior_thread_state *caller_state; 433*5796c8dcSSimon Schubert struct cleanup *caller_state_cleanup; 434*5796c8dcSSimon Schubert CORE_ADDR funaddr; 435*5796c8dcSSimon Schubert CORE_ADDR real_pc; 436*5796c8dcSSimon Schubert struct type *ftype = check_typedef (value_type (function)); 437*5796c8dcSSimon Schubert CORE_ADDR bp_addr; 438*5796c8dcSSimon Schubert struct frame_id dummy_id; 439*5796c8dcSSimon Schubert struct cleanup *args_cleanup; 440*5796c8dcSSimon Schubert struct frame_info *frame; 441*5796c8dcSSimon Schubert struct gdbarch *gdbarch; 442*5796c8dcSSimon Schubert struct breakpoint *terminate_bp = NULL; 443*5796c8dcSSimon Schubert struct minimal_symbol *tm; 444*5796c8dcSSimon Schubert ptid_t call_thread_ptid; 445*5796c8dcSSimon Schubert struct gdb_exception e; 446*5796c8dcSSimon Schubert const char *name; 447*5796c8dcSSimon Schubert char name_buf[RAW_FUNCTION_ADDRESS_SIZE]; 448*5796c8dcSSimon Schubert 449*5796c8dcSSimon Schubert if (TYPE_CODE (ftype) == TYPE_CODE_PTR) 450*5796c8dcSSimon Schubert ftype = check_typedef (TYPE_TARGET_TYPE (ftype)); 451*5796c8dcSSimon Schubert 452*5796c8dcSSimon Schubert if (!target_has_execution) 453*5796c8dcSSimon Schubert noprocess (); 454*5796c8dcSSimon Schubert 455*5796c8dcSSimon Schubert frame = get_current_frame (); 456*5796c8dcSSimon Schubert gdbarch = get_frame_arch (frame); 457*5796c8dcSSimon Schubert 458*5796c8dcSSimon Schubert if (!gdbarch_push_dummy_call_p (gdbarch)) 459*5796c8dcSSimon Schubert error (_("This target does not support function calls.")); 460*5796c8dcSSimon Schubert 461*5796c8dcSSimon Schubert /* A cleanup for the inferior status. 462*5796c8dcSSimon Schubert This is only needed while we're preparing the inferior function call. */ 463*5796c8dcSSimon Schubert inf_status = save_inferior_status (); 464*5796c8dcSSimon Schubert inf_status_cleanup = make_cleanup_restore_inferior_status (inf_status); 465*5796c8dcSSimon Schubert 466*5796c8dcSSimon Schubert /* Save the caller's registers and other state associated with the 467*5796c8dcSSimon Schubert inferior itself so that they can be restored once the 468*5796c8dcSSimon Schubert callee returns. To allow nested calls the registers are (further 469*5796c8dcSSimon Schubert down) pushed onto a dummy frame stack. Include a cleanup (which 470*5796c8dcSSimon Schubert is tossed once the regcache has been pushed). */ 471*5796c8dcSSimon Schubert caller_state = save_inferior_thread_state (); 472*5796c8dcSSimon Schubert caller_state_cleanup = make_cleanup_restore_inferior_thread_state (caller_state); 473*5796c8dcSSimon Schubert 474*5796c8dcSSimon Schubert /* Ensure that the initial SP is correctly aligned. */ 475*5796c8dcSSimon Schubert { 476*5796c8dcSSimon Schubert CORE_ADDR old_sp = get_frame_sp (frame); 477*5796c8dcSSimon Schubert if (gdbarch_frame_align_p (gdbarch)) 478*5796c8dcSSimon Schubert { 479*5796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, old_sp); 480*5796c8dcSSimon Schubert /* NOTE: cagney/2003-08-13: Skip the "red zone". For some 481*5796c8dcSSimon Schubert ABIs, a function can use memory beyond the inner most stack 482*5796c8dcSSimon Schubert address. AMD64 called that region the "red zone". Skip at 483*5796c8dcSSimon Schubert least the "red zone" size before allocating any space on 484*5796c8dcSSimon Schubert the stack. */ 485*5796c8dcSSimon Schubert if (gdbarch_inner_than (gdbarch, 1, 2)) 486*5796c8dcSSimon Schubert sp -= gdbarch_frame_red_zone_size (gdbarch); 487*5796c8dcSSimon Schubert else 488*5796c8dcSSimon Schubert sp += gdbarch_frame_red_zone_size (gdbarch); 489*5796c8dcSSimon Schubert /* Still aligned? */ 490*5796c8dcSSimon Schubert gdb_assert (sp == gdbarch_frame_align (gdbarch, sp)); 491*5796c8dcSSimon Schubert /* NOTE: cagney/2002-09-18: 492*5796c8dcSSimon Schubert 493*5796c8dcSSimon Schubert On a RISC architecture, a void parameterless generic dummy 494*5796c8dcSSimon Schubert frame (i.e., no parameters, no result) typically does not 495*5796c8dcSSimon Schubert need to push anything the stack and hence can leave SP and 496*5796c8dcSSimon Schubert FP. Similarly, a frameless (possibly leaf) function does 497*5796c8dcSSimon Schubert not push anything on the stack and, hence, that too can 498*5796c8dcSSimon Schubert leave FP and SP unchanged. As a consequence, a sequence of 499*5796c8dcSSimon Schubert void parameterless generic dummy frame calls to frameless 500*5796c8dcSSimon Schubert functions will create a sequence of effectively identical 501*5796c8dcSSimon Schubert frames (SP, FP and TOS and PC the same). This, not 502*5796c8dcSSimon Schubert suprisingly, results in what appears to be a stack in an 503*5796c8dcSSimon Schubert infinite loop --- when GDB tries to find a generic dummy 504*5796c8dcSSimon Schubert frame on the internal dummy frame stack, it will always 505*5796c8dcSSimon Schubert find the first one. 506*5796c8dcSSimon Schubert 507*5796c8dcSSimon Schubert To avoid this problem, the code below always grows the 508*5796c8dcSSimon Schubert stack. That way, two dummy frames can never be identical. 509*5796c8dcSSimon Schubert It does burn a few bytes of stack but that is a small price 510*5796c8dcSSimon Schubert to pay :-). */ 511*5796c8dcSSimon Schubert if (sp == old_sp) 512*5796c8dcSSimon Schubert { 513*5796c8dcSSimon Schubert if (gdbarch_inner_than (gdbarch, 1, 2)) 514*5796c8dcSSimon Schubert /* Stack grows down. */ 515*5796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, old_sp - 1); 516*5796c8dcSSimon Schubert else 517*5796c8dcSSimon Schubert /* Stack grows up. */ 518*5796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, old_sp + 1); 519*5796c8dcSSimon Schubert } 520*5796c8dcSSimon Schubert gdb_assert ((gdbarch_inner_than (gdbarch, 1, 2) 521*5796c8dcSSimon Schubert && sp <= old_sp) 522*5796c8dcSSimon Schubert || (gdbarch_inner_than (gdbarch, 2, 1) 523*5796c8dcSSimon Schubert && sp >= old_sp)); 524*5796c8dcSSimon Schubert } 525*5796c8dcSSimon Schubert else 526*5796c8dcSSimon Schubert /* FIXME: cagney/2002-09-18: Hey, you loose! 527*5796c8dcSSimon Schubert 528*5796c8dcSSimon Schubert Who knows how badly aligned the SP is! 529*5796c8dcSSimon Schubert 530*5796c8dcSSimon Schubert If the generic dummy frame ends up empty (because nothing is 531*5796c8dcSSimon Schubert pushed) GDB won't be able to correctly perform back traces. 532*5796c8dcSSimon Schubert If a target is having trouble with backtraces, first thing to 533*5796c8dcSSimon Schubert do is add FRAME_ALIGN() to the architecture vector. If that 534*5796c8dcSSimon Schubert fails, try dummy_id(). 535*5796c8dcSSimon Schubert 536*5796c8dcSSimon Schubert If the ABI specifies a "Red Zone" (see the doco) the code 537*5796c8dcSSimon Schubert below will quietly trash it. */ 538*5796c8dcSSimon Schubert sp = old_sp; 539*5796c8dcSSimon Schubert } 540*5796c8dcSSimon Schubert 541*5796c8dcSSimon Schubert funaddr = find_function_addr (function, &values_type); 542*5796c8dcSSimon Schubert if (!values_type) 543*5796c8dcSSimon Schubert values_type = builtin_type (gdbarch)->builtin_int; 544*5796c8dcSSimon Schubert 545*5796c8dcSSimon Schubert CHECK_TYPEDEF (values_type); 546*5796c8dcSSimon Schubert 547*5796c8dcSSimon Schubert /* Are we returning a value using a structure return (passing a 548*5796c8dcSSimon Schubert hidden argument pointing to storage) or a normal value return? 549*5796c8dcSSimon Schubert There are two cases: language-mandated structure return and 550*5796c8dcSSimon Schubert target ABI structure return. The variable STRUCT_RETURN only 551*5796c8dcSSimon Schubert describes the latter. The language version is handled by passing 552*5796c8dcSSimon Schubert the return location as the first parameter to the function, 553*5796c8dcSSimon Schubert even preceding "this". This is different from the target 554*5796c8dcSSimon Schubert ABI version, which is target-specific; for instance, on ia64 555*5796c8dcSSimon Schubert the first argument is passed in out0 but the hidden structure 556*5796c8dcSSimon Schubert return pointer would normally be passed in r8. */ 557*5796c8dcSSimon Schubert 558*5796c8dcSSimon Schubert if (language_pass_by_reference (values_type)) 559*5796c8dcSSimon Schubert { 560*5796c8dcSSimon Schubert lang_struct_return = 1; 561*5796c8dcSSimon Schubert 562*5796c8dcSSimon Schubert /* Tell the target specific argument pushing routine not to 563*5796c8dcSSimon Schubert expect a value. */ 564*5796c8dcSSimon Schubert target_values_type = builtin_type (gdbarch)->builtin_void; 565*5796c8dcSSimon Schubert } 566*5796c8dcSSimon Schubert else 567*5796c8dcSSimon Schubert { 568*5796c8dcSSimon Schubert struct_return = using_struct_return (gdbarch, 569*5796c8dcSSimon Schubert value_type (function), values_type); 570*5796c8dcSSimon Schubert target_values_type = values_type; 571*5796c8dcSSimon Schubert } 572*5796c8dcSSimon Schubert 573*5796c8dcSSimon Schubert /* Determine the location of the breakpoint (and possibly other 574*5796c8dcSSimon Schubert stuff) that the called function will return to. The SPARC, for a 575*5796c8dcSSimon Schubert function returning a structure or union, needs to make space for 576*5796c8dcSSimon Schubert not just the breakpoint but also an extra word containing the 577*5796c8dcSSimon Schubert size (?) of the structure being passed. */ 578*5796c8dcSSimon Schubert 579*5796c8dcSSimon Schubert /* The actual breakpoint (at BP_ADDR) is inserted separatly so there 580*5796c8dcSSimon Schubert is no need to write that out. */ 581*5796c8dcSSimon Schubert 582*5796c8dcSSimon Schubert switch (gdbarch_call_dummy_location (gdbarch)) 583*5796c8dcSSimon Schubert { 584*5796c8dcSSimon Schubert case ON_STACK: 585*5796c8dcSSimon Schubert sp = push_dummy_code (gdbarch, sp, funaddr, 586*5796c8dcSSimon Schubert args, nargs, target_values_type, 587*5796c8dcSSimon Schubert &real_pc, &bp_addr, get_current_regcache ()); 588*5796c8dcSSimon Schubert break; 589*5796c8dcSSimon Schubert case AT_ENTRY_POINT: 590*5796c8dcSSimon Schubert { 591*5796c8dcSSimon Schubert CORE_ADDR dummy_addr; 592*5796c8dcSSimon Schubert 593*5796c8dcSSimon Schubert real_pc = funaddr; 594*5796c8dcSSimon Schubert dummy_addr = entry_point_address (); 595*5796c8dcSSimon Schubert /* A call dummy always consists of just a single breakpoint, so 596*5796c8dcSSimon Schubert its address is the same as the address of the dummy. */ 597*5796c8dcSSimon Schubert bp_addr = dummy_addr; 598*5796c8dcSSimon Schubert break; 599*5796c8dcSSimon Schubert } 600*5796c8dcSSimon Schubert case AT_SYMBOL: 601*5796c8dcSSimon Schubert /* Some executables define a symbol __CALL_DUMMY_ADDRESS whose 602*5796c8dcSSimon Schubert address is the location where the breakpoint should be 603*5796c8dcSSimon Schubert placed. Once all targets are using the overhauled frame code 604*5796c8dcSSimon Schubert this can be deleted - ON_STACK is a better option. */ 605*5796c8dcSSimon Schubert { 606*5796c8dcSSimon Schubert struct minimal_symbol *sym; 607*5796c8dcSSimon Schubert CORE_ADDR dummy_addr; 608*5796c8dcSSimon Schubert 609*5796c8dcSSimon Schubert sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL); 610*5796c8dcSSimon Schubert real_pc = funaddr; 611*5796c8dcSSimon Schubert if (sym) 612*5796c8dcSSimon Schubert { 613*5796c8dcSSimon Schubert dummy_addr = SYMBOL_VALUE_ADDRESS (sym); 614*5796c8dcSSimon Schubert /* Make certain that the address points at real code, and not 615*5796c8dcSSimon Schubert a function descriptor. */ 616*5796c8dcSSimon Schubert dummy_addr = gdbarch_convert_from_func_ptr_addr (gdbarch, 617*5796c8dcSSimon Schubert dummy_addr, 618*5796c8dcSSimon Schubert ¤t_target); 619*5796c8dcSSimon Schubert } 620*5796c8dcSSimon Schubert else 621*5796c8dcSSimon Schubert dummy_addr = entry_point_address (); 622*5796c8dcSSimon Schubert /* A call dummy always consists of just a single breakpoint, 623*5796c8dcSSimon Schubert so it's address is the same as the address of the dummy. */ 624*5796c8dcSSimon Schubert bp_addr = dummy_addr; 625*5796c8dcSSimon Schubert break; 626*5796c8dcSSimon Schubert } 627*5796c8dcSSimon Schubert default: 628*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("bad switch")); 629*5796c8dcSSimon Schubert } 630*5796c8dcSSimon Schubert 631*5796c8dcSSimon Schubert if (nargs < TYPE_NFIELDS (ftype)) 632*5796c8dcSSimon Schubert error (_("Too few arguments in function call.")); 633*5796c8dcSSimon Schubert 634*5796c8dcSSimon Schubert { 635*5796c8dcSSimon Schubert int i; 636*5796c8dcSSimon Schubert for (i = nargs - 1; i >= 0; i--) 637*5796c8dcSSimon Schubert { 638*5796c8dcSSimon Schubert int prototyped; 639*5796c8dcSSimon Schubert struct type *param_type; 640*5796c8dcSSimon Schubert 641*5796c8dcSSimon Schubert /* FIXME drow/2002-05-31: Should just always mark methods as 642*5796c8dcSSimon Schubert prototyped. Can we respect TYPE_VARARGS? Probably not. */ 643*5796c8dcSSimon Schubert if (TYPE_CODE (ftype) == TYPE_CODE_METHOD) 644*5796c8dcSSimon Schubert prototyped = 1; 645*5796c8dcSSimon Schubert else if (i < TYPE_NFIELDS (ftype)) 646*5796c8dcSSimon Schubert prototyped = TYPE_PROTOTYPED (ftype); 647*5796c8dcSSimon Schubert else 648*5796c8dcSSimon Schubert prototyped = 0; 649*5796c8dcSSimon Schubert 650*5796c8dcSSimon Schubert if (i < TYPE_NFIELDS (ftype)) 651*5796c8dcSSimon Schubert param_type = TYPE_FIELD_TYPE (ftype, i); 652*5796c8dcSSimon Schubert else 653*5796c8dcSSimon Schubert param_type = NULL; 654*5796c8dcSSimon Schubert 655*5796c8dcSSimon Schubert args[i] = value_arg_coerce (gdbarch, args[i], 656*5796c8dcSSimon Schubert param_type, prototyped, &sp); 657*5796c8dcSSimon Schubert 658*5796c8dcSSimon Schubert if (param_type != NULL && language_pass_by_reference (param_type)) 659*5796c8dcSSimon Schubert args[i] = value_addr (args[i]); 660*5796c8dcSSimon Schubert } 661*5796c8dcSSimon Schubert } 662*5796c8dcSSimon Schubert 663*5796c8dcSSimon Schubert /* Reserve space for the return structure to be written on the 664*5796c8dcSSimon Schubert stack, if necessary. Make certain that the value is correctly 665*5796c8dcSSimon Schubert aligned. */ 666*5796c8dcSSimon Schubert 667*5796c8dcSSimon Schubert if (struct_return || lang_struct_return) 668*5796c8dcSSimon Schubert { 669*5796c8dcSSimon Schubert int len = TYPE_LENGTH (values_type); 670*5796c8dcSSimon Schubert if (gdbarch_inner_than (gdbarch, 1, 2)) 671*5796c8dcSSimon Schubert { 672*5796c8dcSSimon Schubert /* Stack grows downward. Align STRUCT_ADDR and SP after 673*5796c8dcSSimon Schubert making space for the return value. */ 674*5796c8dcSSimon Schubert sp -= len; 675*5796c8dcSSimon Schubert if (gdbarch_frame_align_p (gdbarch)) 676*5796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, sp); 677*5796c8dcSSimon Schubert struct_addr = sp; 678*5796c8dcSSimon Schubert } 679*5796c8dcSSimon Schubert else 680*5796c8dcSSimon Schubert { 681*5796c8dcSSimon Schubert /* Stack grows upward. Align the frame, allocate space, and 682*5796c8dcSSimon Schubert then again, re-align the frame??? */ 683*5796c8dcSSimon Schubert if (gdbarch_frame_align_p (gdbarch)) 684*5796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, sp); 685*5796c8dcSSimon Schubert struct_addr = sp; 686*5796c8dcSSimon Schubert sp += len; 687*5796c8dcSSimon Schubert if (gdbarch_frame_align_p (gdbarch)) 688*5796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, sp); 689*5796c8dcSSimon Schubert } 690*5796c8dcSSimon Schubert } 691*5796c8dcSSimon Schubert 692*5796c8dcSSimon Schubert if (lang_struct_return) 693*5796c8dcSSimon Schubert { 694*5796c8dcSSimon Schubert struct value **new_args; 695*5796c8dcSSimon Schubert 696*5796c8dcSSimon Schubert /* Add the new argument to the front of the argument list. */ 697*5796c8dcSSimon Schubert new_args = xmalloc (sizeof (struct value *) * (nargs + 1)); 698*5796c8dcSSimon Schubert new_args[0] = value_from_pointer (lookup_pointer_type (values_type), 699*5796c8dcSSimon Schubert struct_addr); 700*5796c8dcSSimon Schubert memcpy (&new_args[1], &args[0], sizeof (struct value *) * nargs); 701*5796c8dcSSimon Schubert args = new_args; 702*5796c8dcSSimon Schubert nargs++; 703*5796c8dcSSimon Schubert args_cleanup = make_cleanup (xfree, args); 704*5796c8dcSSimon Schubert } 705*5796c8dcSSimon Schubert else 706*5796c8dcSSimon Schubert args_cleanup = make_cleanup (null_cleanup, NULL); 707*5796c8dcSSimon Schubert 708*5796c8dcSSimon Schubert /* Create the dummy stack frame. Pass in the call dummy address as, 709*5796c8dcSSimon Schubert presumably, the ABI code knows where, in the call dummy, the 710*5796c8dcSSimon Schubert return address should be pointed. */ 711*5796c8dcSSimon Schubert sp = gdbarch_push_dummy_call (gdbarch, function, get_current_regcache (), 712*5796c8dcSSimon Schubert bp_addr, nargs, args, 713*5796c8dcSSimon Schubert sp, struct_return, struct_addr); 714*5796c8dcSSimon Schubert 715*5796c8dcSSimon Schubert do_cleanups (args_cleanup); 716*5796c8dcSSimon Schubert 717*5796c8dcSSimon Schubert /* Set up a frame ID for the dummy frame so we can pass it to 718*5796c8dcSSimon Schubert set_momentary_breakpoint. We need to give the breakpoint a frame 719*5796c8dcSSimon Schubert ID so that the breakpoint code can correctly re-identify the 720*5796c8dcSSimon Schubert dummy breakpoint. */ 721*5796c8dcSSimon Schubert /* Sanity. The exact same SP value is returned by PUSH_DUMMY_CALL, 722*5796c8dcSSimon Schubert saved as the dummy-frame TOS, and used by dummy_id to form 723*5796c8dcSSimon Schubert the frame ID's stack address. */ 724*5796c8dcSSimon Schubert dummy_id = frame_id_build (sp, bp_addr); 725*5796c8dcSSimon Schubert 726*5796c8dcSSimon Schubert /* Create a momentary breakpoint at the return address of the 727*5796c8dcSSimon Schubert inferior. That way it breaks when it returns. */ 728*5796c8dcSSimon Schubert 729*5796c8dcSSimon Schubert { 730*5796c8dcSSimon Schubert struct breakpoint *bpt; 731*5796c8dcSSimon Schubert struct symtab_and_line sal; 732*5796c8dcSSimon Schubert init_sal (&sal); /* initialize to zeroes */ 733*5796c8dcSSimon Schubert sal.pc = bp_addr; 734*5796c8dcSSimon Schubert sal.section = find_pc_overlay (sal.pc); 735*5796c8dcSSimon Schubert /* Sanity. The exact same SP value is returned by 736*5796c8dcSSimon Schubert PUSH_DUMMY_CALL, saved as the dummy-frame TOS, and used by 737*5796c8dcSSimon Schubert dummy_id to form the frame ID's stack address. */ 738*5796c8dcSSimon Schubert bpt = set_momentary_breakpoint (gdbarch, sal, dummy_id, bp_call_dummy); 739*5796c8dcSSimon Schubert bpt->disposition = disp_del; 740*5796c8dcSSimon Schubert } 741*5796c8dcSSimon Schubert 742*5796c8dcSSimon Schubert /* Create a breakpoint in std::terminate. 743*5796c8dcSSimon Schubert If a C++ exception is raised in the dummy-frame, and the 744*5796c8dcSSimon Schubert exception handler is (normally, and expected to be) out-of-frame, 745*5796c8dcSSimon Schubert the default C++ handler will (wrongly) be called in an inferior 746*5796c8dcSSimon Schubert function call. This is wrong, as an exception can be normally 747*5796c8dcSSimon Schubert and legally handled out-of-frame. The confines of the dummy frame 748*5796c8dcSSimon Schubert prevent the unwinder from finding the correct handler (or any 749*5796c8dcSSimon Schubert handler, unless it is in-frame). The default handler calls 750*5796c8dcSSimon Schubert std::terminate. This will kill the inferior. Assert that 751*5796c8dcSSimon Schubert terminate should never be called in an inferior function 752*5796c8dcSSimon Schubert call. Place a momentary breakpoint in the std::terminate function 753*5796c8dcSSimon Schubert and if triggered in the call, rewind. */ 754*5796c8dcSSimon Schubert if (unwind_on_terminating_exception_p) 755*5796c8dcSSimon Schubert { 756*5796c8dcSSimon Schubert struct minimal_symbol *tm = lookup_minimal_symbol ("std::terminate()", 757*5796c8dcSSimon Schubert NULL, NULL); 758*5796c8dcSSimon Schubert if (tm != NULL) 759*5796c8dcSSimon Schubert terminate_bp = set_momentary_breakpoint_at_pc 760*5796c8dcSSimon Schubert (gdbarch, SYMBOL_VALUE_ADDRESS (tm), bp_breakpoint); 761*5796c8dcSSimon Schubert } 762*5796c8dcSSimon Schubert 763*5796c8dcSSimon Schubert /* Everything's ready, push all the info needed to restore the 764*5796c8dcSSimon Schubert caller (and identify the dummy-frame) onto the dummy-frame 765*5796c8dcSSimon Schubert stack. */ 766*5796c8dcSSimon Schubert dummy_frame_push (caller_state, &dummy_id); 767*5796c8dcSSimon Schubert 768*5796c8dcSSimon Schubert /* Discard both inf_status and caller_state cleanups. 769*5796c8dcSSimon Schubert From this point on we explicitly restore the associated state 770*5796c8dcSSimon Schubert or discard it. */ 771*5796c8dcSSimon Schubert discard_cleanups (inf_status_cleanup); 772*5796c8dcSSimon Schubert 773*5796c8dcSSimon Schubert /* Register a clean-up for unwind_on_terminating_exception_breakpoint. */ 774*5796c8dcSSimon Schubert if (terminate_bp) 775*5796c8dcSSimon Schubert make_cleanup_delete_breakpoint (terminate_bp); 776*5796c8dcSSimon Schubert 777*5796c8dcSSimon Schubert /* - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - 778*5796c8dcSSimon Schubert If you're looking to implement asynchronous dummy-frames, then 779*5796c8dcSSimon Schubert just below is the place to chop this function in two.. */ 780*5796c8dcSSimon Schubert 781*5796c8dcSSimon Schubert /* TP is invalid after run_inferior_call returns, so enclose this 782*5796c8dcSSimon Schubert in a block so that it's only in scope during the time it's valid. */ 783*5796c8dcSSimon Schubert { 784*5796c8dcSSimon Schubert struct thread_info *tp = inferior_thread (); 785*5796c8dcSSimon Schubert 786*5796c8dcSSimon Schubert /* Save this thread's ptid, we need it later but the thread 787*5796c8dcSSimon Schubert may have exited. */ 788*5796c8dcSSimon Schubert call_thread_ptid = tp->ptid; 789*5796c8dcSSimon Schubert 790*5796c8dcSSimon Schubert /* Run the inferior until it stops. */ 791*5796c8dcSSimon Schubert 792*5796c8dcSSimon Schubert e = run_inferior_call (tp, real_pc); 793*5796c8dcSSimon Schubert } 794*5796c8dcSSimon Schubert 795*5796c8dcSSimon Schubert /* Rethrow an error if we got one trying to run the inferior. */ 796*5796c8dcSSimon Schubert 797*5796c8dcSSimon Schubert if (e.reason < 0) 798*5796c8dcSSimon Schubert { 799*5796c8dcSSimon Schubert const char *name = get_function_name (funaddr, 800*5796c8dcSSimon Schubert name_buf, sizeof (name_buf)); 801*5796c8dcSSimon Schubert 802*5796c8dcSSimon Schubert discard_inferior_status (inf_status); 803*5796c8dcSSimon Schubert 804*5796c8dcSSimon Schubert /* We could discard the dummy frame here if the program exited, 805*5796c8dcSSimon Schubert but it will get garbage collected the next time the program is 806*5796c8dcSSimon Schubert run anyway. */ 807*5796c8dcSSimon Schubert 808*5796c8dcSSimon Schubert switch (e.reason) 809*5796c8dcSSimon Schubert { 810*5796c8dcSSimon Schubert case RETURN_ERROR: 811*5796c8dcSSimon Schubert throw_error (e.error, _("\ 812*5796c8dcSSimon Schubert %s\n\ 813*5796c8dcSSimon Schubert An error occurred while in a function called from GDB.\n\ 814*5796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 815*5796c8dcSSimon Schubert (%s) will be abandoned.\n\ 816*5796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."), 817*5796c8dcSSimon Schubert e.message, name); 818*5796c8dcSSimon Schubert case RETURN_QUIT: 819*5796c8dcSSimon Schubert default: 820*5796c8dcSSimon Schubert throw_exception (e); 821*5796c8dcSSimon Schubert } 822*5796c8dcSSimon Schubert } 823*5796c8dcSSimon Schubert 824*5796c8dcSSimon Schubert /* If the program has exited, or we stopped at a different thread, 825*5796c8dcSSimon Schubert exit and inform the user. */ 826*5796c8dcSSimon Schubert 827*5796c8dcSSimon Schubert if (! target_has_execution) 828*5796c8dcSSimon Schubert { 829*5796c8dcSSimon Schubert const char *name = get_function_name (funaddr, 830*5796c8dcSSimon Schubert name_buf, sizeof (name_buf)); 831*5796c8dcSSimon Schubert 832*5796c8dcSSimon Schubert /* If we try to restore the inferior status, 833*5796c8dcSSimon Schubert we'll crash as the inferior is no longer running. */ 834*5796c8dcSSimon Schubert discard_inferior_status (inf_status); 835*5796c8dcSSimon Schubert 836*5796c8dcSSimon Schubert /* We could discard the dummy frame here given that the program exited, 837*5796c8dcSSimon Schubert but it will get garbage collected the next time the program is 838*5796c8dcSSimon Schubert run anyway. */ 839*5796c8dcSSimon Schubert 840*5796c8dcSSimon Schubert error (_("\ 841*5796c8dcSSimon Schubert The program being debugged exited while in a function called from GDB.\n\ 842*5796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 843*5796c8dcSSimon Schubert (%s) will be abandoned."), 844*5796c8dcSSimon Schubert name); 845*5796c8dcSSimon Schubert } 846*5796c8dcSSimon Schubert 847*5796c8dcSSimon Schubert if (! ptid_equal (call_thread_ptid, inferior_ptid)) 848*5796c8dcSSimon Schubert { 849*5796c8dcSSimon Schubert const char *name = get_function_name (funaddr, 850*5796c8dcSSimon Schubert name_buf, sizeof (name_buf)); 851*5796c8dcSSimon Schubert 852*5796c8dcSSimon Schubert /* We've switched threads. This can happen if another thread gets a 853*5796c8dcSSimon Schubert signal or breakpoint while our thread was running. 854*5796c8dcSSimon Schubert There's no point in restoring the inferior status, 855*5796c8dcSSimon Schubert we're in a different thread. */ 856*5796c8dcSSimon Schubert discard_inferior_status (inf_status); 857*5796c8dcSSimon Schubert /* Keep the dummy frame record, if the user switches back to the 858*5796c8dcSSimon Schubert thread with the hand-call, we'll need it. */ 859*5796c8dcSSimon Schubert if (stopped_by_random_signal) 860*5796c8dcSSimon Schubert error (_("\ 861*5796c8dcSSimon Schubert The program received a signal in another thread while\n\ 862*5796c8dcSSimon Schubert making a function call from GDB.\n\ 863*5796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 864*5796c8dcSSimon Schubert (%s) will be abandoned.\n\ 865*5796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."), 866*5796c8dcSSimon Schubert name); 867*5796c8dcSSimon Schubert else 868*5796c8dcSSimon Schubert error (_("\ 869*5796c8dcSSimon Schubert The program stopped in another thread while making a function call from GDB.\n\ 870*5796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 871*5796c8dcSSimon Schubert (%s) will be abandoned.\n\ 872*5796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."), 873*5796c8dcSSimon Schubert name); 874*5796c8dcSSimon Schubert } 875*5796c8dcSSimon Schubert 876*5796c8dcSSimon Schubert if (stopped_by_random_signal || !stop_stack_dummy) 877*5796c8dcSSimon Schubert { 878*5796c8dcSSimon Schubert const char *name = get_function_name (funaddr, 879*5796c8dcSSimon Schubert name_buf, sizeof (name_buf)); 880*5796c8dcSSimon Schubert 881*5796c8dcSSimon Schubert if (stopped_by_random_signal) 882*5796c8dcSSimon Schubert { 883*5796c8dcSSimon Schubert /* We stopped inside the FUNCTION because of a random 884*5796c8dcSSimon Schubert signal. Further execution of the FUNCTION is not 885*5796c8dcSSimon Schubert allowed. */ 886*5796c8dcSSimon Schubert 887*5796c8dcSSimon Schubert if (unwind_on_signal_p) 888*5796c8dcSSimon Schubert { 889*5796c8dcSSimon Schubert /* The user wants the context restored. */ 890*5796c8dcSSimon Schubert 891*5796c8dcSSimon Schubert /* We must get back to the frame we were before the 892*5796c8dcSSimon Schubert dummy call. */ 893*5796c8dcSSimon Schubert dummy_frame_pop (dummy_id); 894*5796c8dcSSimon Schubert 895*5796c8dcSSimon Schubert /* We also need to restore inferior status to that before the 896*5796c8dcSSimon Schubert dummy call. */ 897*5796c8dcSSimon Schubert restore_inferior_status (inf_status); 898*5796c8dcSSimon Schubert 899*5796c8dcSSimon Schubert /* FIXME: Insert a bunch of wrap_here; name can be very 900*5796c8dcSSimon Schubert long if it's a C++ name with arguments and stuff. */ 901*5796c8dcSSimon Schubert error (_("\ 902*5796c8dcSSimon Schubert The program being debugged was signaled while in a function called from GDB.\n\ 903*5796c8dcSSimon Schubert GDB has restored the context to what it was before the call.\n\ 904*5796c8dcSSimon Schubert To change this behavior use \"set unwindonsignal off\".\n\ 905*5796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 906*5796c8dcSSimon Schubert (%s) will be abandoned."), 907*5796c8dcSSimon Schubert name); 908*5796c8dcSSimon Schubert } 909*5796c8dcSSimon Schubert else 910*5796c8dcSSimon Schubert { 911*5796c8dcSSimon Schubert /* The user wants to stay in the frame where we stopped 912*5796c8dcSSimon Schubert (default). 913*5796c8dcSSimon Schubert Discard inferior status, we're not at the same point 914*5796c8dcSSimon Schubert we started at. */ 915*5796c8dcSSimon Schubert discard_inferior_status (inf_status); 916*5796c8dcSSimon Schubert 917*5796c8dcSSimon Schubert /* FIXME: Insert a bunch of wrap_here; name can be very 918*5796c8dcSSimon Schubert long if it's a C++ name with arguments and stuff. */ 919*5796c8dcSSimon Schubert error (_("\ 920*5796c8dcSSimon Schubert The program being debugged was signaled while in a function called from GDB.\n\ 921*5796c8dcSSimon Schubert GDB remains in the frame where the signal was received.\n\ 922*5796c8dcSSimon Schubert To change this behavior use \"set unwindonsignal on\".\n\ 923*5796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 924*5796c8dcSSimon Schubert (%s) will be abandoned.\n\ 925*5796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."), 926*5796c8dcSSimon Schubert name); 927*5796c8dcSSimon Schubert } 928*5796c8dcSSimon Schubert } 929*5796c8dcSSimon Schubert 930*5796c8dcSSimon Schubert if (!stop_stack_dummy) 931*5796c8dcSSimon Schubert { 932*5796c8dcSSimon Schubert 933*5796c8dcSSimon Schubert /* Check if unwind on terminating exception behaviour is on. */ 934*5796c8dcSSimon Schubert if (unwind_on_terminating_exception_p) 935*5796c8dcSSimon Schubert { 936*5796c8dcSSimon Schubert /* Check that the breakpoint is our special std::terminate 937*5796c8dcSSimon Schubert breakpoint. If it is, we do not want to kill the inferior 938*5796c8dcSSimon Schubert in an inferior function call. Rewind, and warn the 939*5796c8dcSSimon Schubert user. */ 940*5796c8dcSSimon Schubert 941*5796c8dcSSimon Schubert if (terminate_bp != NULL 942*5796c8dcSSimon Schubert && (inferior_thread()->stop_bpstat->breakpoint_at->address 943*5796c8dcSSimon Schubert == terminate_bp->loc->address)) 944*5796c8dcSSimon Schubert { 945*5796c8dcSSimon Schubert /* We must get back to the frame we were before the 946*5796c8dcSSimon Schubert dummy call. */ 947*5796c8dcSSimon Schubert dummy_frame_pop (dummy_id); 948*5796c8dcSSimon Schubert 949*5796c8dcSSimon Schubert /* We also need to restore inferior status to that before the 950*5796c8dcSSimon Schubert dummy call. */ 951*5796c8dcSSimon Schubert restore_inferior_status (inf_status); 952*5796c8dcSSimon Schubert 953*5796c8dcSSimon Schubert error (_("\ 954*5796c8dcSSimon Schubert The program being debugged entered a std::terminate call, most likely\n\ 955*5796c8dcSSimon Schubert caused by an unhandled C++ exception. GDB blocked this call in order\n\ 956*5796c8dcSSimon Schubert to prevent the program from being terminated, and has restored the\n\ 957*5796c8dcSSimon Schubert context to its original state before the call.\n\ 958*5796c8dcSSimon Schubert To change this behaviour use \"set unwind-on-terminating-exception off\".\n\ 959*5796c8dcSSimon Schubert Evaluation of the expression containing the function (%s)\n\ 960*5796c8dcSSimon Schubert will be abandoned."), 961*5796c8dcSSimon Schubert name); 962*5796c8dcSSimon Schubert } 963*5796c8dcSSimon Schubert } 964*5796c8dcSSimon Schubert /* We hit a breakpoint inside the FUNCTION. 965*5796c8dcSSimon Schubert Keep the dummy frame, the user may want to examine its state. 966*5796c8dcSSimon Schubert Discard inferior status, we're not at the same point 967*5796c8dcSSimon Schubert we started at. */ 968*5796c8dcSSimon Schubert discard_inferior_status (inf_status); 969*5796c8dcSSimon Schubert 970*5796c8dcSSimon Schubert /* The following error message used to say "The expression 971*5796c8dcSSimon Schubert which contained the function call has been discarded." 972*5796c8dcSSimon Schubert It is a hard concept to explain in a few words. Ideally, 973*5796c8dcSSimon Schubert GDB would be able to resume evaluation of the expression 974*5796c8dcSSimon Schubert when the function finally is done executing. Perhaps 975*5796c8dcSSimon Schubert someday this will be implemented (it would not be easy). */ 976*5796c8dcSSimon Schubert /* FIXME: Insert a bunch of wrap_here; name can be very long if it's 977*5796c8dcSSimon Schubert a C++ name with arguments and stuff. */ 978*5796c8dcSSimon Schubert error (_("\ 979*5796c8dcSSimon Schubert The program being debugged stopped while in a function called from GDB.\n\ 980*5796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 981*5796c8dcSSimon Schubert (%s) will be abandoned.\n\ 982*5796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."), 983*5796c8dcSSimon Schubert name); 984*5796c8dcSSimon Schubert } 985*5796c8dcSSimon Schubert 986*5796c8dcSSimon Schubert /* The above code errors out, so ... */ 987*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("... should not be here")); 988*5796c8dcSSimon Schubert } 989*5796c8dcSSimon Schubert 990*5796c8dcSSimon Schubert /* If we get here the called FUNCTION ran to completion, 991*5796c8dcSSimon Schubert and the dummy frame has already been popped. */ 992*5796c8dcSSimon Schubert 993*5796c8dcSSimon Schubert { 994*5796c8dcSSimon Schubert struct regcache *retbuf = regcache_xmalloc (gdbarch); 995*5796c8dcSSimon Schubert struct cleanup *retbuf_cleanup = make_cleanup_regcache_xfree (retbuf); 996*5796c8dcSSimon Schubert struct value *retval = NULL; 997*5796c8dcSSimon Schubert 998*5796c8dcSSimon Schubert regcache_cpy_no_passthrough (retbuf, stop_registers); 999*5796c8dcSSimon Schubert 1000*5796c8dcSSimon Schubert /* Inferior call is successful. Restore the inferior status. 1001*5796c8dcSSimon Schubert At this stage, leave the RETBUF alone. */ 1002*5796c8dcSSimon Schubert restore_inferior_status (inf_status); 1003*5796c8dcSSimon Schubert 1004*5796c8dcSSimon Schubert /* Figure out the value returned by the function. */ 1005*5796c8dcSSimon Schubert 1006*5796c8dcSSimon Schubert if (lang_struct_return) 1007*5796c8dcSSimon Schubert retval = value_at (values_type, struct_addr); 1008*5796c8dcSSimon Schubert else if (TYPE_CODE (target_values_type) == TYPE_CODE_VOID) 1009*5796c8dcSSimon Schubert { 1010*5796c8dcSSimon Schubert /* If the function returns void, don't bother fetching the 1011*5796c8dcSSimon Schubert return value. */ 1012*5796c8dcSSimon Schubert retval = allocate_value (values_type); 1013*5796c8dcSSimon Schubert } 1014*5796c8dcSSimon Schubert else 1015*5796c8dcSSimon Schubert { 1016*5796c8dcSSimon Schubert switch (gdbarch_return_value (gdbarch, value_type (function), 1017*5796c8dcSSimon Schubert target_values_type, NULL, NULL, NULL)) 1018*5796c8dcSSimon Schubert { 1019*5796c8dcSSimon Schubert case RETURN_VALUE_REGISTER_CONVENTION: 1020*5796c8dcSSimon Schubert case RETURN_VALUE_ABI_RETURNS_ADDRESS: 1021*5796c8dcSSimon Schubert case RETURN_VALUE_ABI_PRESERVES_ADDRESS: 1022*5796c8dcSSimon Schubert retval = allocate_value (values_type); 1023*5796c8dcSSimon Schubert gdbarch_return_value (gdbarch, value_type (function), values_type, 1024*5796c8dcSSimon Schubert retbuf, value_contents_raw (retval), NULL); 1025*5796c8dcSSimon Schubert break; 1026*5796c8dcSSimon Schubert case RETURN_VALUE_STRUCT_CONVENTION: 1027*5796c8dcSSimon Schubert retval = value_at (values_type, struct_addr); 1028*5796c8dcSSimon Schubert break; 1029*5796c8dcSSimon Schubert } 1030*5796c8dcSSimon Schubert } 1031*5796c8dcSSimon Schubert 1032*5796c8dcSSimon Schubert do_cleanups (retbuf_cleanup); 1033*5796c8dcSSimon Schubert 1034*5796c8dcSSimon Schubert gdb_assert (retval); 1035*5796c8dcSSimon Schubert return retval; 1036*5796c8dcSSimon Schubert } 1037*5796c8dcSSimon Schubert } 1038*5796c8dcSSimon Schubert 1039*5796c8dcSSimon Schubert 1040*5796c8dcSSimon Schubert /* Provide a prototype to silence -Wmissing-prototypes. */ 1041*5796c8dcSSimon Schubert void _initialize_infcall (void); 1042*5796c8dcSSimon Schubert 1043*5796c8dcSSimon Schubert void 1044*5796c8dcSSimon Schubert _initialize_infcall (void) 1045*5796c8dcSSimon Schubert { 1046*5796c8dcSSimon Schubert add_setshow_boolean_cmd ("coerce-float-to-double", class_obscure, 1047*5796c8dcSSimon Schubert &coerce_float_to_double_p, _("\ 1048*5796c8dcSSimon Schubert Set coercion of floats to doubles when calling functions."), _("\ 1049*5796c8dcSSimon Schubert Show coercion of floats to doubles when calling functions"), _("\ 1050*5796c8dcSSimon Schubert Variables of type float should generally be converted to doubles before\n\ 1051*5796c8dcSSimon Schubert calling an unprototyped function, and left alone when calling a prototyped\n\ 1052*5796c8dcSSimon Schubert function. However, some older debug info formats do not provide enough\n\ 1053*5796c8dcSSimon Schubert information to determine that a function is prototyped. If this flag is\n\ 1054*5796c8dcSSimon Schubert set, GDB will perform the conversion for a function it considers\n\ 1055*5796c8dcSSimon Schubert unprototyped.\n\ 1056*5796c8dcSSimon Schubert The default is to perform the conversion.\n"), 1057*5796c8dcSSimon Schubert NULL, 1058*5796c8dcSSimon Schubert show_coerce_float_to_double_p, 1059*5796c8dcSSimon Schubert &setlist, &showlist); 1060*5796c8dcSSimon Schubert 1061*5796c8dcSSimon Schubert add_setshow_boolean_cmd ("unwindonsignal", no_class, 1062*5796c8dcSSimon Schubert &unwind_on_signal_p, _("\ 1063*5796c8dcSSimon Schubert Set unwinding of stack if a signal is received while in a call dummy."), _("\ 1064*5796c8dcSSimon Schubert Show unwinding of stack if a signal is received while in a call dummy."), _("\ 1065*5796c8dcSSimon Schubert The unwindonsignal lets the user determine what gdb should do if a signal\n\ 1066*5796c8dcSSimon Schubert is received while in a function called from gdb (call dummy). If set, gdb\n\ 1067*5796c8dcSSimon Schubert unwinds the stack and restore the context to what as it was before the call.\n\ 1068*5796c8dcSSimon Schubert The default is to stop in the frame where the signal was received."), 1069*5796c8dcSSimon Schubert NULL, 1070*5796c8dcSSimon Schubert show_unwind_on_signal_p, 1071*5796c8dcSSimon Schubert &setlist, &showlist); 1072*5796c8dcSSimon Schubert 1073*5796c8dcSSimon Schubert add_setshow_boolean_cmd ("unwind-on-terminating-exception", no_class, 1074*5796c8dcSSimon Schubert &unwind_on_terminating_exception_p, _("\ 1075*5796c8dcSSimon Schubert Set unwinding of stack if std::terminate is called while in call dummy."), _("\ 1076*5796c8dcSSimon Schubert Show unwinding of stack if std::terminate() is called while in a call dummy."), _("\ 1077*5796c8dcSSimon Schubert The unwind on terminating exception flag lets the user determine\n\ 1078*5796c8dcSSimon Schubert what gdb should do if a std::terminate() call is made from the\n\ 1079*5796c8dcSSimon Schubert default exception handler. If set, gdb unwinds the stack and restores\n\ 1080*5796c8dcSSimon Schubert the context to what it was before the call. If unset, gdb allows the\n\ 1081*5796c8dcSSimon Schubert std::terminate call to proceed.\n\ 1082*5796c8dcSSimon Schubert The default is to unwind the frame."), 1083*5796c8dcSSimon Schubert NULL, 1084*5796c8dcSSimon Schubert show_unwind_on_terminating_exception_p, 1085*5796c8dcSSimon Schubert &setlist, &showlist); 1086*5796c8dcSSimon Schubert 1087*5796c8dcSSimon Schubert } 1088