15796c8dcSSimon Schubert /* Perform an inferior function call, for GDB, the GNU debugger. 25796c8dcSSimon Schubert 35796c8dcSSimon Schubert Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 45796c8dcSSimon Schubert 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 5*cf7f2e2dSJohn Marino 2008, 2009, 2010 Free Software Foundation, Inc. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This file is part of GDB. 85796c8dcSSimon Schubert 95796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 105796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 115796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 125796c8dcSSimon Schubert (at your option) any later version. 135796c8dcSSimon Schubert 145796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 155796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 165796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 175796c8dcSSimon Schubert GNU General Public License for more details. 185796c8dcSSimon Schubert 195796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 205796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert #include "defs.h" 235796c8dcSSimon Schubert #include "breakpoint.h" 24*cf7f2e2dSJohn Marino #include "tracepoint.h" 255796c8dcSSimon Schubert #include "target.h" 265796c8dcSSimon Schubert #include "regcache.h" 275796c8dcSSimon Schubert #include "inferior.h" 285796c8dcSSimon Schubert #include "gdb_assert.h" 295796c8dcSSimon Schubert #include "block.h" 305796c8dcSSimon Schubert #include "gdbcore.h" 315796c8dcSSimon Schubert #include "language.h" 325796c8dcSSimon Schubert #include "objfiles.h" 335796c8dcSSimon Schubert #include "gdbcmd.h" 345796c8dcSSimon Schubert #include "command.h" 355796c8dcSSimon Schubert #include "gdb_string.h" 365796c8dcSSimon Schubert #include "infcall.h" 375796c8dcSSimon Schubert #include "dummy-frame.h" 385796c8dcSSimon Schubert #include "ada-lang.h" 395796c8dcSSimon Schubert #include "gdbthread.h" 405796c8dcSSimon Schubert #include "exceptions.h" 415796c8dcSSimon Schubert 425796c8dcSSimon Schubert /* If we can't find a function's name from its address, 435796c8dcSSimon Schubert we print this instead. */ 445796c8dcSSimon Schubert #define RAW_FUNCTION_ADDRESS_FORMAT "at 0x%s" 455796c8dcSSimon Schubert #define RAW_FUNCTION_ADDRESS_SIZE (sizeof (RAW_FUNCTION_ADDRESS_FORMAT) \ 465796c8dcSSimon Schubert + 2 * sizeof (CORE_ADDR)) 475796c8dcSSimon Schubert 485796c8dcSSimon Schubert /* NOTE: cagney/2003-04-16: What's the future of this code? 495796c8dcSSimon Schubert 505796c8dcSSimon Schubert GDB needs an asynchronous expression evaluator, that means an 515796c8dcSSimon Schubert asynchronous inferior function call implementation, and that in 525796c8dcSSimon Schubert turn means restructuring the code so that it is event driven. */ 535796c8dcSSimon Schubert 545796c8dcSSimon Schubert /* How you should pass arguments to a function depends on whether it 555796c8dcSSimon Schubert was defined in K&R style or prototype style. If you define a 565796c8dcSSimon Schubert function using the K&R syntax that takes a `float' argument, then 575796c8dcSSimon Schubert callers must pass that argument as a `double'. If you define the 585796c8dcSSimon Schubert function using the prototype syntax, then you must pass the 595796c8dcSSimon Schubert argument as a `float', with no promotion. 605796c8dcSSimon Schubert 615796c8dcSSimon Schubert Unfortunately, on certain older platforms, the debug info doesn't 625796c8dcSSimon Schubert indicate reliably how each function was defined. A function type's 635796c8dcSSimon Schubert TYPE_FLAG_PROTOTYPED flag may be clear, even if the function was 645796c8dcSSimon Schubert defined in prototype style. When calling a function whose 655796c8dcSSimon Schubert TYPE_FLAG_PROTOTYPED flag is clear, GDB consults this flag to 665796c8dcSSimon Schubert decide what to do. 675796c8dcSSimon Schubert 685796c8dcSSimon Schubert For modern targets, it is proper to assume that, if the prototype 695796c8dcSSimon Schubert flag is clear, that can be trusted: `float' arguments should be 705796c8dcSSimon Schubert promoted to `double'. For some older targets, if the prototype 715796c8dcSSimon Schubert flag is clear, that doesn't tell us anything. The default is to 725796c8dcSSimon Schubert trust the debug information; the user can override this behavior 735796c8dcSSimon Schubert with "set coerce-float-to-double 0". */ 745796c8dcSSimon Schubert 755796c8dcSSimon Schubert static int coerce_float_to_double_p = 1; 765796c8dcSSimon Schubert static void 775796c8dcSSimon Schubert show_coerce_float_to_double_p (struct ui_file *file, int from_tty, 785796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 795796c8dcSSimon Schubert { 805796c8dcSSimon Schubert fprintf_filtered (file, _("\ 815796c8dcSSimon Schubert Coercion of floats to doubles when calling functions is %s.\n"), 825796c8dcSSimon Schubert value); 835796c8dcSSimon Schubert } 845796c8dcSSimon Schubert 855796c8dcSSimon Schubert /* This boolean tells what gdb should do if a signal is received while 865796c8dcSSimon Schubert in a function called from gdb (call dummy). If set, gdb unwinds 875796c8dcSSimon Schubert the stack and restore the context to what as it was before the 885796c8dcSSimon Schubert call. 895796c8dcSSimon Schubert 905796c8dcSSimon Schubert The default is to stop in the frame where the signal was received. */ 915796c8dcSSimon Schubert 925796c8dcSSimon Schubert int unwind_on_signal_p = 0; 935796c8dcSSimon Schubert static void 945796c8dcSSimon Schubert show_unwind_on_signal_p (struct ui_file *file, int from_tty, 955796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 965796c8dcSSimon Schubert { 975796c8dcSSimon Schubert fprintf_filtered (file, _("\ 985796c8dcSSimon Schubert Unwinding of stack if a signal is received while in a call dummy is %s.\n"), 995796c8dcSSimon Schubert value); 1005796c8dcSSimon Schubert } 1015796c8dcSSimon Schubert 1025796c8dcSSimon Schubert /* This boolean tells what gdb should do if a std::terminate call is 1035796c8dcSSimon Schubert made while in a function called from gdb (call dummy). 1045796c8dcSSimon Schubert As the confines of a single dummy stack prohibit out-of-frame 1055796c8dcSSimon Schubert handlers from handling a raised exception, and as out-of-frame 1065796c8dcSSimon Schubert handlers are common in C++, this can lead to no handler being found 1075796c8dcSSimon Schubert by the unwinder, and a std::terminate call. This is a false positive. 1085796c8dcSSimon Schubert If set, gdb unwinds the stack and restores the context to what it 1095796c8dcSSimon Schubert was before the call. 1105796c8dcSSimon Schubert 1115796c8dcSSimon Schubert The default is to unwind the frame if a std::terminate call is 1125796c8dcSSimon Schubert made. */ 1135796c8dcSSimon Schubert 1145796c8dcSSimon Schubert static int unwind_on_terminating_exception_p = 1; 1155796c8dcSSimon Schubert 1165796c8dcSSimon Schubert static void 1175796c8dcSSimon Schubert show_unwind_on_terminating_exception_p (struct ui_file *file, int from_tty, 1185796c8dcSSimon Schubert struct cmd_list_element *c, 1195796c8dcSSimon Schubert const char *value) 1205796c8dcSSimon Schubert 1215796c8dcSSimon Schubert { 1225796c8dcSSimon Schubert fprintf_filtered (file, _("\ 1235796c8dcSSimon Schubert Unwind stack if a C++ exception is unhandled while in a call dummy is %s.\n"), 1245796c8dcSSimon Schubert value); 1255796c8dcSSimon Schubert } 1265796c8dcSSimon Schubert 1275796c8dcSSimon Schubert /* Perform the standard coercions that are specified 1285796c8dcSSimon Schubert for arguments to be passed to C or Ada functions. 1295796c8dcSSimon Schubert 1305796c8dcSSimon Schubert If PARAM_TYPE is non-NULL, it is the expected parameter type. 1315796c8dcSSimon Schubert IS_PROTOTYPED is non-zero if the function declaration is prototyped. 1325796c8dcSSimon Schubert SP is the stack pointer were additional data can be pushed (updating 1335796c8dcSSimon Schubert its value as needed). */ 1345796c8dcSSimon Schubert 1355796c8dcSSimon Schubert static struct value * 1365796c8dcSSimon Schubert value_arg_coerce (struct gdbarch *gdbarch, struct value *arg, 1375796c8dcSSimon Schubert struct type *param_type, int is_prototyped, CORE_ADDR *sp) 1385796c8dcSSimon Schubert { 1395796c8dcSSimon Schubert const struct builtin_type *builtin = builtin_type (gdbarch); 1405796c8dcSSimon Schubert struct type *arg_type = check_typedef (value_type (arg)); 1415796c8dcSSimon Schubert struct type *type 1425796c8dcSSimon Schubert = param_type ? check_typedef (param_type) : arg_type; 1435796c8dcSSimon Schubert 1445796c8dcSSimon Schubert /* Perform any Ada-specific coercion first. */ 1455796c8dcSSimon Schubert if (current_language->la_language == language_ada) 1465796c8dcSSimon Schubert arg = ada_convert_actual (arg, type, gdbarch, sp); 1475796c8dcSSimon Schubert 1485796c8dcSSimon Schubert /* Force the value to the target if we will need its address. At 1495796c8dcSSimon Schubert this point, we could allocate arguments on the stack instead of 1505796c8dcSSimon Schubert calling malloc if we knew that their addresses would not be 1515796c8dcSSimon Schubert saved by the called function. */ 1525796c8dcSSimon Schubert arg = value_coerce_to_target (arg); 1535796c8dcSSimon Schubert 1545796c8dcSSimon Schubert switch (TYPE_CODE (type)) 1555796c8dcSSimon Schubert { 1565796c8dcSSimon Schubert case TYPE_CODE_REF: 1575796c8dcSSimon Schubert { 1585796c8dcSSimon Schubert struct value *new_value; 1595796c8dcSSimon Schubert 1605796c8dcSSimon Schubert if (TYPE_CODE (arg_type) == TYPE_CODE_REF) 1615796c8dcSSimon Schubert return value_cast_pointers (type, arg); 1625796c8dcSSimon Schubert 1635796c8dcSSimon Schubert /* Cast the value to the reference's target type, and then 1645796c8dcSSimon Schubert convert it back to a reference. This will issue an error 1655796c8dcSSimon Schubert if the value was not previously in memory - in some cases 1665796c8dcSSimon Schubert we should clearly be allowing this, but how? */ 1675796c8dcSSimon Schubert new_value = value_cast (TYPE_TARGET_TYPE (type), arg); 1685796c8dcSSimon Schubert new_value = value_ref (new_value); 1695796c8dcSSimon Schubert return new_value; 1705796c8dcSSimon Schubert } 1715796c8dcSSimon Schubert case TYPE_CODE_INT: 1725796c8dcSSimon Schubert case TYPE_CODE_CHAR: 1735796c8dcSSimon Schubert case TYPE_CODE_BOOL: 1745796c8dcSSimon Schubert case TYPE_CODE_ENUM: 1755796c8dcSSimon Schubert /* If we don't have a prototype, coerce to integer type if necessary. */ 1765796c8dcSSimon Schubert if (!is_prototyped) 1775796c8dcSSimon Schubert { 1785796c8dcSSimon Schubert if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin->builtin_int)) 1795796c8dcSSimon Schubert type = builtin->builtin_int; 1805796c8dcSSimon Schubert } 1815796c8dcSSimon Schubert /* Currently all target ABIs require at least the width of an integer 1825796c8dcSSimon Schubert type for an argument. We may have to conditionalize the following 1835796c8dcSSimon Schubert type coercion for future targets. */ 1845796c8dcSSimon Schubert if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin->builtin_int)) 1855796c8dcSSimon Schubert type = builtin->builtin_int; 1865796c8dcSSimon Schubert break; 1875796c8dcSSimon Schubert case TYPE_CODE_FLT: 1885796c8dcSSimon Schubert if (!is_prototyped && coerce_float_to_double_p) 1895796c8dcSSimon Schubert { 1905796c8dcSSimon Schubert if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin->builtin_double)) 1915796c8dcSSimon Schubert type = builtin->builtin_double; 1925796c8dcSSimon Schubert else if (TYPE_LENGTH (type) > TYPE_LENGTH (builtin->builtin_double)) 1935796c8dcSSimon Schubert type = builtin->builtin_long_double; 1945796c8dcSSimon Schubert } 1955796c8dcSSimon Schubert break; 1965796c8dcSSimon Schubert case TYPE_CODE_FUNC: 1975796c8dcSSimon Schubert type = lookup_pointer_type (type); 1985796c8dcSSimon Schubert break; 1995796c8dcSSimon Schubert case TYPE_CODE_ARRAY: 2005796c8dcSSimon Schubert /* Arrays are coerced to pointers to their first element, unless 2015796c8dcSSimon Schubert they are vectors, in which case we want to leave them alone, 2025796c8dcSSimon Schubert because they are passed by value. */ 2035796c8dcSSimon Schubert if (current_language->c_style_arrays) 2045796c8dcSSimon Schubert if (!TYPE_VECTOR (type)) 2055796c8dcSSimon Schubert type = lookup_pointer_type (TYPE_TARGET_TYPE (type)); 2065796c8dcSSimon Schubert break; 2075796c8dcSSimon Schubert case TYPE_CODE_UNDEF: 2085796c8dcSSimon Schubert case TYPE_CODE_PTR: 2095796c8dcSSimon Schubert case TYPE_CODE_STRUCT: 2105796c8dcSSimon Schubert case TYPE_CODE_UNION: 2115796c8dcSSimon Schubert case TYPE_CODE_VOID: 2125796c8dcSSimon Schubert case TYPE_CODE_SET: 2135796c8dcSSimon Schubert case TYPE_CODE_RANGE: 2145796c8dcSSimon Schubert case TYPE_CODE_STRING: 2155796c8dcSSimon Schubert case TYPE_CODE_BITSTRING: 2165796c8dcSSimon Schubert case TYPE_CODE_ERROR: 2175796c8dcSSimon Schubert case TYPE_CODE_MEMBERPTR: 2185796c8dcSSimon Schubert case TYPE_CODE_METHODPTR: 2195796c8dcSSimon Schubert case TYPE_CODE_METHOD: 2205796c8dcSSimon Schubert case TYPE_CODE_COMPLEX: 2215796c8dcSSimon Schubert default: 2225796c8dcSSimon Schubert break; 2235796c8dcSSimon Schubert } 2245796c8dcSSimon Schubert 2255796c8dcSSimon Schubert return value_cast (type, arg); 2265796c8dcSSimon Schubert } 2275796c8dcSSimon Schubert 2285796c8dcSSimon Schubert /* Determine a function's address and its return type from its value. 2295796c8dcSSimon Schubert Calls error() if the function is not valid for calling. */ 2305796c8dcSSimon Schubert 2315796c8dcSSimon Schubert CORE_ADDR 2325796c8dcSSimon Schubert find_function_addr (struct value *function, struct type **retval_type) 2335796c8dcSSimon Schubert { 2345796c8dcSSimon Schubert struct type *ftype = check_typedef (value_type (function)); 2355796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (ftype); 2365796c8dcSSimon Schubert enum type_code code = TYPE_CODE (ftype); 2375796c8dcSSimon Schubert struct type *value_type = NULL; 2385796c8dcSSimon Schubert CORE_ADDR funaddr; 2395796c8dcSSimon Schubert 2405796c8dcSSimon Schubert /* If it's a member function, just look at the function 2415796c8dcSSimon Schubert part of it. */ 2425796c8dcSSimon Schubert 2435796c8dcSSimon Schubert /* Determine address to call. */ 2445796c8dcSSimon Schubert if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD) 2455796c8dcSSimon Schubert { 2465796c8dcSSimon Schubert funaddr = value_address (function); 2475796c8dcSSimon Schubert value_type = TYPE_TARGET_TYPE (ftype); 2485796c8dcSSimon Schubert } 2495796c8dcSSimon Schubert else if (code == TYPE_CODE_PTR) 2505796c8dcSSimon Schubert { 2515796c8dcSSimon Schubert funaddr = value_as_address (function); 2525796c8dcSSimon Schubert ftype = check_typedef (TYPE_TARGET_TYPE (ftype)); 2535796c8dcSSimon Schubert if (TYPE_CODE (ftype) == TYPE_CODE_FUNC 2545796c8dcSSimon Schubert || TYPE_CODE (ftype) == TYPE_CODE_METHOD) 2555796c8dcSSimon Schubert { 2565796c8dcSSimon Schubert funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr, 2575796c8dcSSimon Schubert ¤t_target); 2585796c8dcSSimon Schubert value_type = TYPE_TARGET_TYPE (ftype); 2595796c8dcSSimon Schubert } 2605796c8dcSSimon Schubert } 2615796c8dcSSimon Schubert else if (code == TYPE_CODE_INT) 2625796c8dcSSimon Schubert { 2635796c8dcSSimon Schubert /* Handle the case of functions lacking debugging info. 2645796c8dcSSimon Schubert Their values are characters since their addresses are char */ 2655796c8dcSSimon Schubert if (TYPE_LENGTH (ftype) == 1) 2665796c8dcSSimon Schubert funaddr = value_as_address (value_addr (function)); 2675796c8dcSSimon Schubert else 2685796c8dcSSimon Schubert { 2695796c8dcSSimon Schubert /* Handle function descriptors lacking debug info. */ 2705796c8dcSSimon Schubert int found_descriptor = 0; 271*cf7f2e2dSJohn Marino 2725796c8dcSSimon Schubert funaddr = 0; /* pacify "gcc -Werror" */ 2735796c8dcSSimon Schubert if (VALUE_LVAL (function) == lval_memory) 2745796c8dcSSimon Schubert { 2755796c8dcSSimon Schubert CORE_ADDR nfunaddr; 276*cf7f2e2dSJohn Marino 2775796c8dcSSimon Schubert funaddr = value_as_address (value_addr (function)); 2785796c8dcSSimon Schubert nfunaddr = funaddr; 2795796c8dcSSimon Schubert funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr, 2805796c8dcSSimon Schubert ¤t_target); 2815796c8dcSSimon Schubert if (funaddr != nfunaddr) 2825796c8dcSSimon Schubert found_descriptor = 1; 2835796c8dcSSimon Schubert } 2845796c8dcSSimon Schubert if (!found_descriptor) 2855796c8dcSSimon Schubert /* Handle integer used as address of a function. */ 2865796c8dcSSimon Schubert funaddr = (CORE_ADDR) value_as_long (function); 2875796c8dcSSimon Schubert } 2885796c8dcSSimon Schubert } 2895796c8dcSSimon Schubert else 2905796c8dcSSimon Schubert error (_("Invalid data type for function to be called.")); 2915796c8dcSSimon Schubert 2925796c8dcSSimon Schubert if (retval_type != NULL) 2935796c8dcSSimon Schubert *retval_type = value_type; 2945796c8dcSSimon Schubert return funaddr + gdbarch_deprecated_function_start_offset (gdbarch); 2955796c8dcSSimon Schubert } 2965796c8dcSSimon Schubert 2975796c8dcSSimon Schubert /* For CALL_DUMMY_ON_STACK, push a breakpoint sequence that the called 2985796c8dcSSimon Schubert function returns to. */ 2995796c8dcSSimon Schubert 3005796c8dcSSimon Schubert static CORE_ADDR 3015796c8dcSSimon Schubert push_dummy_code (struct gdbarch *gdbarch, 3025796c8dcSSimon Schubert CORE_ADDR sp, CORE_ADDR funaddr, 3035796c8dcSSimon Schubert struct value **args, int nargs, 3045796c8dcSSimon Schubert struct type *value_type, 3055796c8dcSSimon Schubert CORE_ADDR *real_pc, CORE_ADDR *bp_addr, 3065796c8dcSSimon Schubert struct regcache *regcache) 3075796c8dcSSimon Schubert { 3085796c8dcSSimon Schubert gdb_assert (gdbarch_push_dummy_code_p (gdbarch)); 3095796c8dcSSimon Schubert 3105796c8dcSSimon Schubert return gdbarch_push_dummy_code (gdbarch, sp, funaddr, 3115796c8dcSSimon Schubert args, nargs, value_type, real_pc, bp_addr, 3125796c8dcSSimon Schubert regcache); 3135796c8dcSSimon Schubert } 3145796c8dcSSimon Schubert 3155796c8dcSSimon Schubert /* Fetch the name of the function at FUNADDR. 3165796c8dcSSimon Schubert This is used in printing an error message for call_function_by_hand. 3175796c8dcSSimon Schubert BUF is used to print FUNADDR in hex if the function name cannot be 3185796c8dcSSimon Schubert determined. It must be large enough to hold formatted result of 3195796c8dcSSimon Schubert RAW_FUNCTION_ADDRESS_FORMAT. */ 3205796c8dcSSimon Schubert 3215796c8dcSSimon Schubert static const char * 3225796c8dcSSimon Schubert get_function_name (CORE_ADDR funaddr, char *buf, int buf_size) 3235796c8dcSSimon Schubert { 3245796c8dcSSimon Schubert { 3255796c8dcSSimon Schubert struct symbol *symbol = find_pc_function (funaddr); 326*cf7f2e2dSJohn Marino 3275796c8dcSSimon Schubert if (symbol) 3285796c8dcSSimon Schubert return SYMBOL_PRINT_NAME (symbol); 3295796c8dcSSimon Schubert } 3305796c8dcSSimon Schubert 3315796c8dcSSimon Schubert { 3325796c8dcSSimon Schubert /* Try the minimal symbols. */ 3335796c8dcSSimon Schubert struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (funaddr); 334*cf7f2e2dSJohn Marino 3355796c8dcSSimon Schubert if (msymbol) 3365796c8dcSSimon Schubert return SYMBOL_PRINT_NAME (msymbol); 3375796c8dcSSimon Schubert } 3385796c8dcSSimon Schubert 3395796c8dcSSimon Schubert { 3405796c8dcSSimon Schubert char *tmp = xstrprintf (_(RAW_FUNCTION_ADDRESS_FORMAT), 3415796c8dcSSimon Schubert hex_string (funaddr)); 342*cf7f2e2dSJohn Marino 3435796c8dcSSimon Schubert gdb_assert (strlen (tmp) + 1 <= buf_size); 3445796c8dcSSimon Schubert strcpy (buf, tmp); 3455796c8dcSSimon Schubert xfree (tmp); 3465796c8dcSSimon Schubert return buf; 3475796c8dcSSimon Schubert } 3485796c8dcSSimon Schubert } 3495796c8dcSSimon Schubert 3505796c8dcSSimon Schubert /* Subroutine of call_function_by_hand to simplify it. 3515796c8dcSSimon Schubert Start up the inferior and wait for it to stop. 3525796c8dcSSimon Schubert Return the exception if there's an error, or an exception with 3535796c8dcSSimon Schubert reason >= 0 if there's no error. 3545796c8dcSSimon Schubert 3555796c8dcSSimon Schubert This is done inside a TRY_CATCH so the caller needn't worry about 3565796c8dcSSimon Schubert thrown errors. The caller should rethrow if there's an error. */ 3575796c8dcSSimon Schubert 3585796c8dcSSimon Schubert static struct gdb_exception 3595796c8dcSSimon Schubert run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc) 3605796c8dcSSimon Schubert { 3615796c8dcSSimon Schubert volatile struct gdb_exception e; 3625796c8dcSSimon Schubert int saved_async = 0; 3635796c8dcSSimon Schubert int saved_in_infcall = call_thread->in_infcall; 3645796c8dcSSimon Schubert ptid_t call_thread_ptid = call_thread->ptid; 3655796c8dcSSimon Schubert char *saved_target_shortname = xstrdup (target_shortname); 3665796c8dcSSimon Schubert 3675796c8dcSSimon Schubert call_thread->in_infcall = 1; 3685796c8dcSSimon Schubert 3695796c8dcSSimon Schubert clear_proceed_status (); 3705796c8dcSSimon Schubert 3715796c8dcSSimon Schubert disable_watchpoints_before_interactive_call_start (); 3725796c8dcSSimon Schubert call_thread->proceed_to_finish = 1; /* We want stop_registers, please... */ 3735796c8dcSSimon Schubert 3745796c8dcSSimon Schubert if (target_can_async_p ()) 3755796c8dcSSimon Schubert saved_async = target_async_mask (0); 3765796c8dcSSimon Schubert 3775796c8dcSSimon Schubert TRY_CATCH (e, RETURN_MASK_ALL) 3785796c8dcSSimon Schubert proceed (real_pc, TARGET_SIGNAL_0, 0); 3795796c8dcSSimon Schubert 3805796c8dcSSimon Schubert /* At this point the current thread may have changed. Refresh 3815796c8dcSSimon Schubert CALL_THREAD as it could be invalid if its thread has exited. */ 3825796c8dcSSimon Schubert call_thread = find_thread_ptid (call_thread_ptid); 3835796c8dcSSimon Schubert 3845796c8dcSSimon Schubert /* Don't restore the async mask if the target has changed, 3855796c8dcSSimon Schubert saved_async is for the original target. */ 3865796c8dcSSimon Schubert if (saved_async 3875796c8dcSSimon Schubert && strcmp (saved_target_shortname, target_shortname) == 0) 3885796c8dcSSimon Schubert target_async_mask (saved_async); 3895796c8dcSSimon Schubert 3905796c8dcSSimon Schubert enable_watchpoints_after_interactive_call_stop (); 3915796c8dcSSimon Schubert 3925796c8dcSSimon Schubert /* Call breakpoint_auto_delete on the current contents of the bpstat 3935796c8dcSSimon Schubert of inferior call thread. 3945796c8dcSSimon Schubert If all error()s out of proceed ended up calling normal_stop 3955796c8dcSSimon Schubert (and perhaps they should; it already does in the special case 3965796c8dcSSimon Schubert of error out of resume()), then we wouldn't need this. */ 3975796c8dcSSimon Schubert if (e.reason < 0) 3985796c8dcSSimon Schubert { 3995796c8dcSSimon Schubert if (call_thread != NULL) 4005796c8dcSSimon Schubert breakpoint_auto_delete (call_thread->stop_bpstat); 4015796c8dcSSimon Schubert } 4025796c8dcSSimon Schubert 4035796c8dcSSimon Schubert if (call_thread != NULL) 4045796c8dcSSimon Schubert call_thread->in_infcall = saved_in_infcall; 4055796c8dcSSimon Schubert 4065796c8dcSSimon Schubert xfree (saved_target_shortname); 4075796c8dcSSimon Schubert 4085796c8dcSSimon Schubert return e; 4095796c8dcSSimon Schubert } 4105796c8dcSSimon Schubert 411*cf7f2e2dSJohn Marino /* A cleanup function that calls delete_std_terminate_breakpoint. */ 412*cf7f2e2dSJohn Marino static void 413*cf7f2e2dSJohn Marino cleanup_delete_std_terminate_breakpoint (void *ignore) 414*cf7f2e2dSJohn Marino { 415*cf7f2e2dSJohn Marino delete_std_terminate_breakpoint (); 416*cf7f2e2dSJohn Marino } 417*cf7f2e2dSJohn Marino 4185796c8dcSSimon Schubert /* All this stuff with a dummy frame may seem unnecessarily complicated 4195796c8dcSSimon Schubert (why not just save registers in GDB?). The purpose of pushing a dummy 4205796c8dcSSimon Schubert frame which looks just like a real frame is so that if you call a 4215796c8dcSSimon Schubert function and then hit a breakpoint (get a signal, etc), "backtrace" 4225796c8dcSSimon Schubert will look right. Whether the backtrace needs to actually show the 4235796c8dcSSimon Schubert stack at the time the inferior function was called is debatable, but 4245796c8dcSSimon Schubert it certainly needs to not display garbage. So if you are contemplating 4255796c8dcSSimon Schubert making dummy frames be different from normal frames, consider that. */ 4265796c8dcSSimon Schubert 4275796c8dcSSimon Schubert /* Perform a function call in the inferior. 4285796c8dcSSimon Schubert ARGS is a vector of values of arguments (NARGS of them). 4295796c8dcSSimon Schubert FUNCTION is a value, the function to be called. 4305796c8dcSSimon Schubert Returns a value representing what the function returned. 4315796c8dcSSimon Schubert May fail to return, if a breakpoint or signal is hit 4325796c8dcSSimon Schubert during the execution of the function. 4335796c8dcSSimon Schubert 4345796c8dcSSimon Schubert ARGS is modified to contain coerced values. */ 4355796c8dcSSimon Schubert 4365796c8dcSSimon Schubert struct value * 4375796c8dcSSimon Schubert call_function_by_hand (struct value *function, int nargs, struct value **args) 4385796c8dcSSimon Schubert { 4395796c8dcSSimon Schubert CORE_ADDR sp; 4405796c8dcSSimon Schubert struct type *values_type, *target_values_type; 4415796c8dcSSimon Schubert unsigned char struct_return = 0, lang_struct_return = 0; 4425796c8dcSSimon Schubert CORE_ADDR struct_addr = 0; 4435796c8dcSSimon Schubert struct inferior_status *inf_status; 4445796c8dcSSimon Schubert struct cleanup *inf_status_cleanup; 4455796c8dcSSimon Schubert struct inferior_thread_state *caller_state; 4465796c8dcSSimon Schubert struct cleanup *caller_state_cleanup; 4475796c8dcSSimon Schubert CORE_ADDR funaddr; 4485796c8dcSSimon Schubert CORE_ADDR real_pc; 4495796c8dcSSimon Schubert struct type *ftype = check_typedef (value_type (function)); 4505796c8dcSSimon Schubert CORE_ADDR bp_addr; 4515796c8dcSSimon Schubert struct frame_id dummy_id; 4525796c8dcSSimon Schubert struct cleanup *args_cleanup; 4535796c8dcSSimon Schubert struct frame_info *frame; 4545796c8dcSSimon Schubert struct gdbarch *gdbarch; 455*cf7f2e2dSJohn Marino struct cleanup *terminate_bp_cleanup; 4565796c8dcSSimon Schubert ptid_t call_thread_ptid; 4575796c8dcSSimon Schubert struct gdb_exception e; 4585796c8dcSSimon Schubert char name_buf[RAW_FUNCTION_ADDRESS_SIZE]; 4595796c8dcSSimon Schubert 4605796c8dcSSimon Schubert if (TYPE_CODE (ftype) == TYPE_CODE_PTR) 4615796c8dcSSimon Schubert ftype = check_typedef (TYPE_TARGET_TYPE (ftype)); 4625796c8dcSSimon Schubert 4635796c8dcSSimon Schubert if (!target_has_execution) 4645796c8dcSSimon Schubert noprocess (); 4655796c8dcSSimon Schubert 466*cf7f2e2dSJohn Marino if (get_traceframe_number () >= 0) 467*cf7f2e2dSJohn Marino error (_("May not call functions while looking at trace frames.")); 468*cf7f2e2dSJohn Marino 4695796c8dcSSimon Schubert frame = get_current_frame (); 4705796c8dcSSimon Schubert gdbarch = get_frame_arch (frame); 4715796c8dcSSimon Schubert 4725796c8dcSSimon Schubert if (!gdbarch_push_dummy_call_p (gdbarch)) 4735796c8dcSSimon Schubert error (_("This target does not support function calls.")); 4745796c8dcSSimon Schubert 4755796c8dcSSimon Schubert /* A cleanup for the inferior status. 4765796c8dcSSimon Schubert This is only needed while we're preparing the inferior function call. */ 4775796c8dcSSimon Schubert inf_status = save_inferior_status (); 4785796c8dcSSimon Schubert inf_status_cleanup = make_cleanup_restore_inferior_status (inf_status); 4795796c8dcSSimon Schubert 4805796c8dcSSimon Schubert /* Save the caller's registers and other state associated with the 4815796c8dcSSimon Schubert inferior itself so that they can be restored once the 4825796c8dcSSimon Schubert callee returns. To allow nested calls the registers are (further 4835796c8dcSSimon Schubert down) pushed onto a dummy frame stack. Include a cleanup (which 4845796c8dcSSimon Schubert is tossed once the regcache has been pushed). */ 4855796c8dcSSimon Schubert caller_state = save_inferior_thread_state (); 4865796c8dcSSimon Schubert caller_state_cleanup = make_cleanup_restore_inferior_thread_state (caller_state); 4875796c8dcSSimon Schubert 4885796c8dcSSimon Schubert /* Ensure that the initial SP is correctly aligned. */ 4895796c8dcSSimon Schubert { 4905796c8dcSSimon Schubert CORE_ADDR old_sp = get_frame_sp (frame); 491*cf7f2e2dSJohn Marino 4925796c8dcSSimon Schubert if (gdbarch_frame_align_p (gdbarch)) 4935796c8dcSSimon Schubert { 4945796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, old_sp); 4955796c8dcSSimon Schubert /* NOTE: cagney/2003-08-13: Skip the "red zone". For some 4965796c8dcSSimon Schubert ABIs, a function can use memory beyond the inner most stack 4975796c8dcSSimon Schubert address. AMD64 called that region the "red zone". Skip at 4985796c8dcSSimon Schubert least the "red zone" size before allocating any space on 4995796c8dcSSimon Schubert the stack. */ 5005796c8dcSSimon Schubert if (gdbarch_inner_than (gdbarch, 1, 2)) 5015796c8dcSSimon Schubert sp -= gdbarch_frame_red_zone_size (gdbarch); 5025796c8dcSSimon Schubert else 5035796c8dcSSimon Schubert sp += gdbarch_frame_red_zone_size (gdbarch); 5045796c8dcSSimon Schubert /* Still aligned? */ 5055796c8dcSSimon Schubert gdb_assert (sp == gdbarch_frame_align (gdbarch, sp)); 5065796c8dcSSimon Schubert /* NOTE: cagney/2002-09-18: 5075796c8dcSSimon Schubert 5085796c8dcSSimon Schubert On a RISC architecture, a void parameterless generic dummy 5095796c8dcSSimon Schubert frame (i.e., no parameters, no result) typically does not 5105796c8dcSSimon Schubert need to push anything the stack and hence can leave SP and 5115796c8dcSSimon Schubert FP. Similarly, a frameless (possibly leaf) function does 5125796c8dcSSimon Schubert not push anything on the stack and, hence, that too can 5135796c8dcSSimon Schubert leave FP and SP unchanged. As a consequence, a sequence of 5145796c8dcSSimon Schubert void parameterless generic dummy frame calls to frameless 5155796c8dcSSimon Schubert functions will create a sequence of effectively identical 5165796c8dcSSimon Schubert frames (SP, FP and TOS and PC the same). This, not 5175796c8dcSSimon Schubert suprisingly, results in what appears to be a stack in an 5185796c8dcSSimon Schubert infinite loop --- when GDB tries to find a generic dummy 5195796c8dcSSimon Schubert frame on the internal dummy frame stack, it will always 5205796c8dcSSimon Schubert find the first one. 5215796c8dcSSimon Schubert 5225796c8dcSSimon Schubert To avoid this problem, the code below always grows the 5235796c8dcSSimon Schubert stack. That way, two dummy frames can never be identical. 5245796c8dcSSimon Schubert It does burn a few bytes of stack but that is a small price 5255796c8dcSSimon Schubert to pay :-). */ 5265796c8dcSSimon Schubert if (sp == old_sp) 5275796c8dcSSimon Schubert { 5285796c8dcSSimon Schubert if (gdbarch_inner_than (gdbarch, 1, 2)) 5295796c8dcSSimon Schubert /* Stack grows down. */ 5305796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, old_sp - 1); 5315796c8dcSSimon Schubert else 5325796c8dcSSimon Schubert /* Stack grows up. */ 5335796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, old_sp + 1); 5345796c8dcSSimon Schubert } 535*cf7f2e2dSJohn Marino /* SP may have underflown address zero here from OLD_SP. Memory access 536*cf7f2e2dSJohn Marino functions will probably fail in such case but that is a target's 537*cf7f2e2dSJohn Marino problem. */ 5385796c8dcSSimon Schubert } 5395796c8dcSSimon Schubert else 5405796c8dcSSimon Schubert /* FIXME: cagney/2002-09-18: Hey, you loose! 5415796c8dcSSimon Schubert 5425796c8dcSSimon Schubert Who knows how badly aligned the SP is! 5435796c8dcSSimon Schubert 5445796c8dcSSimon Schubert If the generic dummy frame ends up empty (because nothing is 5455796c8dcSSimon Schubert pushed) GDB won't be able to correctly perform back traces. 5465796c8dcSSimon Schubert If a target is having trouble with backtraces, first thing to 5475796c8dcSSimon Schubert do is add FRAME_ALIGN() to the architecture vector. If that 5485796c8dcSSimon Schubert fails, try dummy_id(). 5495796c8dcSSimon Schubert 5505796c8dcSSimon Schubert If the ABI specifies a "Red Zone" (see the doco) the code 5515796c8dcSSimon Schubert below will quietly trash it. */ 5525796c8dcSSimon Schubert sp = old_sp; 5535796c8dcSSimon Schubert } 5545796c8dcSSimon Schubert 5555796c8dcSSimon Schubert funaddr = find_function_addr (function, &values_type); 5565796c8dcSSimon Schubert if (!values_type) 5575796c8dcSSimon Schubert values_type = builtin_type (gdbarch)->builtin_int; 5585796c8dcSSimon Schubert 5595796c8dcSSimon Schubert CHECK_TYPEDEF (values_type); 5605796c8dcSSimon Schubert 5615796c8dcSSimon Schubert /* Are we returning a value using a structure return (passing a 5625796c8dcSSimon Schubert hidden argument pointing to storage) or a normal value return? 5635796c8dcSSimon Schubert There are two cases: language-mandated structure return and 5645796c8dcSSimon Schubert target ABI structure return. The variable STRUCT_RETURN only 5655796c8dcSSimon Schubert describes the latter. The language version is handled by passing 5665796c8dcSSimon Schubert the return location as the first parameter to the function, 5675796c8dcSSimon Schubert even preceding "this". This is different from the target 5685796c8dcSSimon Schubert ABI version, which is target-specific; for instance, on ia64 5695796c8dcSSimon Schubert the first argument is passed in out0 but the hidden structure 5705796c8dcSSimon Schubert return pointer would normally be passed in r8. */ 5715796c8dcSSimon Schubert 5725796c8dcSSimon Schubert if (language_pass_by_reference (values_type)) 5735796c8dcSSimon Schubert { 5745796c8dcSSimon Schubert lang_struct_return = 1; 5755796c8dcSSimon Schubert 5765796c8dcSSimon Schubert /* Tell the target specific argument pushing routine not to 5775796c8dcSSimon Schubert expect a value. */ 5785796c8dcSSimon Schubert target_values_type = builtin_type (gdbarch)->builtin_void; 5795796c8dcSSimon Schubert } 5805796c8dcSSimon Schubert else 5815796c8dcSSimon Schubert { 5825796c8dcSSimon Schubert struct_return = using_struct_return (gdbarch, 5835796c8dcSSimon Schubert value_type (function), values_type); 5845796c8dcSSimon Schubert target_values_type = values_type; 5855796c8dcSSimon Schubert } 5865796c8dcSSimon Schubert 5875796c8dcSSimon Schubert /* Determine the location of the breakpoint (and possibly other 5885796c8dcSSimon Schubert stuff) that the called function will return to. The SPARC, for a 5895796c8dcSSimon Schubert function returning a structure or union, needs to make space for 5905796c8dcSSimon Schubert not just the breakpoint but also an extra word containing the 5915796c8dcSSimon Schubert size (?) of the structure being passed. */ 5925796c8dcSSimon Schubert 5935796c8dcSSimon Schubert /* The actual breakpoint (at BP_ADDR) is inserted separatly so there 5945796c8dcSSimon Schubert is no need to write that out. */ 5955796c8dcSSimon Schubert 5965796c8dcSSimon Schubert switch (gdbarch_call_dummy_location (gdbarch)) 5975796c8dcSSimon Schubert { 5985796c8dcSSimon Schubert case ON_STACK: 5995796c8dcSSimon Schubert sp = push_dummy_code (gdbarch, sp, funaddr, 6005796c8dcSSimon Schubert args, nargs, target_values_type, 6015796c8dcSSimon Schubert &real_pc, &bp_addr, get_current_regcache ()); 6025796c8dcSSimon Schubert break; 6035796c8dcSSimon Schubert case AT_ENTRY_POINT: 6045796c8dcSSimon Schubert { 6055796c8dcSSimon Schubert CORE_ADDR dummy_addr; 6065796c8dcSSimon Schubert 6075796c8dcSSimon Schubert real_pc = funaddr; 6085796c8dcSSimon Schubert dummy_addr = entry_point_address (); 6095796c8dcSSimon Schubert /* A call dummy always consists of just a single breakpoint, so 6105796c8dcSSimon Schubert its address is the same as the address of the dummy. */ 6115796c8dcSSimon Schubert bp_addr = dummy_addr; 6125796c8dcSSimon Schubert break; 6135796c8dcSSimon Schubert } 6145796c8dcSSimon Schubert case AT_SYMBOL: 6155796c8dcSSimon Schubert /* Some executables define a symbol __CALL_DUMMY_ADDRESS whose 6165796c8dcSSimon Schubert address is the location where the breakpoint should be 6175796c8dcSSimon Schubert placed. Once all targets are using the overhauled frame code 6185796c8dcSSimon Schubert this can be deleted - ON_STACK is a better option. */ 6195796c8dcSSimon Schubert { 6205796c8dcSSimon Schubert struct minimal_symbol *sym; 6215796c8dcSSimon Schubert CORE_ADDR dummy_addr; 6225796c8dcSSimon Schubert 6235796c8dcSSimon Schubert sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL); 6245796c8dcSSimon Schubert real_pc = funaddr; 6255796c8dcSSimon Schubert if (sym) 6265796c8dcSSimon Schubert { 6275796c8dcSSimon Schubert dummy_addr = SYMBOL_VALUE_ADDRESS (sym); 6285796c8dcSSimon Schubert /* Make certain that the address points at real code, and not 6295796c8dcSSimon Schubert a function descriptor. */ 6305796c8dcSSimon Schubert dummy_addr = gdbarch_convert_from_func_ptr_addr (gdbarch, 6315796c8dcSSimon Schubert dummy_addr, 6325796c8dcSSimon Schubert ¤t_target); 6335796c8dcSSimon Schubert } 6345796c8dcSSimon Schubert else 6355796c8dcSSimon Schubert dummy_addr = entry_point_address (); 6365796c8dcSSimon Schubert /* A call dummy always consists of just a single breakpoint, 6375796c8dcSSimon Schubert so it's address is the same as the address of the dummy. */ 6385796c8dcSSimon Schubert bp_addr = dummy_addr; 6395796c8dcSSimon Schubert break; 6405796c8dcSSimon Schubert } 6415796c8dcSSimon Schubert default: 6425796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("bad switch")); 6435796c8dcSSimon Schubert } 6445796c8dcSSimon Schubert 6455796c8dcSSimon Schubert if (nargs < TYPE_NFIELDS (ftype)) 6465796c8dcSSimon Schubert error (_("Too few arguments in function call.")); 6475796c8dcSSimon Schubert 6485796c8dcSSimon Schubert { 6495796c8dcSSimon Schubert int i; 650*cf7f2e2dSJohn Marino 6515796c8dcSSimon Schubert for (i = nargs - 1; i >= 0; i--) 6525796c8dcSSimon Schubert { 6535796c8dcSSimon Schubert int prototyped; 6545796c8dcSSimon Schubert struct type *param_type; 6555796c8dcSSimon Schubert 6565796c8dcSSimon Schubert /* FIXME drow/2002-05-31: Should just always mark methods as 6575796c8dcSSimon Schubert prototyped. Can we respect TYPE_VARARGS? Probably not. */ 6585796c8dcSSimon Schubert if (TYPE_CODE (ftype) == TYPE_CODE_METHOD) 6595796c8dcSSimon Schubert prototyped = 1; 6605796c8dcSSimon Schubert else if (i < TYPE_NFIELDS (ftype)) 6615796c8dcSSimon Schubert prototyped = TYPE_PROTOTYPED (ftype); 6625796c8dcSSimon Schubert else 6635796c8dcSSimon Schubert prototyped = 0; 6645796c8dcSSimon Schubert 6655796c8dcSSimon Schubert if (i < TYPE_NFIELDS (ftype)) 6665796c8dcSSimon Schubert param_type = TYPE_FIELD_TYPE (ftype, i); 6675796c8dcSSimon Schubert else 6685796c8dcSSimon Schubert param_type = NULL; 6695796c8dcSSimon Schubert 6705796c8dcSSimon Schubert args[i] = value_arg_coerce (gdbarch, args[i], 6715796c8dcSSimon Schubert param_type, prototyped, &sp); 6725796c8dcSSimon Schubert 6735796c8dcSSimon Schubert if (param_type != NULL && language_pass_by_reference (param_type)) 6745796c8dcSSimon Schubert args[i] = value_addr (args[i]); 6755796c8dcSSimon Schubert } 6765796c8dcSSimon Schubert } 6775796c8dcSSimon Schubert 6785796c8dcSSimon Schubert /* Reserve space for the return structure to be written on the 6795796c8dcSSimon Schubert stack, if necessary. Make certain that the value is correctly 6805796c8dcSSimon Schubert aligned. */ 6815796c8dcSSimon Schubert 6825796c8dcSSimon Schubert if (struct_return || lang_struct_return) 6835796c8dcSSimon Schubert { 6845796c8dcSSimon Schubert int len = TYPE_LENGTH (values_type); 685*cf7f2e2dSJohn Marino 6865796c8dcSSimon Schubert if (gdbarch_inner_than (gdbarch, 1, 2)) 6875796c8dcSSimon Schubert { 6885796c8dcSSimon Schubert /* Stack grows downward. Align STRUCT_ADDR and SP after 6895796c8dcSSimon Schubert making space for the return value. */ 6905796c8dcSSimon Schubert sp -= len; 6915796c8dcSSimon Schubert if (gdbarch_frame_align_p (gdbarch)) 6925796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, sp); 6935796c8dcSSimon Schubert struct_addr = sp; 6945796c8dcSSimon Schubert } 6955796c8dcSSimon Schubert else 6965796c8dcSSimon Schubert { 6975796c8dcSSimon Schubert /* Stack grows upward. Align the frame, allocate space, and 6985796c8dcSSimon Schubert then again, re-align the frame??? */ 6995796c8dcSSimon Schubert if (gdbarch_frame_align_p (gdbarch)) 7005796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, sp); 7015796c8dcSSimon Schubert struct_addr = sp; 7025796c8dcSSimon Schubert sp += len; 7035796c8dcSSimon Schubert if (gdbarch_frame_align_p (gdbarch)) 7045796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, sp); 7055796c8dcSSimon Schubert } 7065796c8dcSSimon Schubert } 7075796c8dcSSimon Schubert 7085796c8dcSSimon Schubert if (lang_struct_return) 7095796c8dcSSimon Schubert { 7105796c8dcSSimon Schubert struct value **new_args; 7115796c8dcSSimon Schubert 7125796c8dcSSimon Schubert /* Add the new argument to the front of the argument list. */ 7135796c8dcSSimon Schubert new_args = xmalloc (sizeof (struct value *) * (nargs + 1)); 7145796c8dcSSimon Schubert new_args[0] = value_from_pointer (lookup_pointer_type (values_type), 7155796c8dcSSimon Schubert struct_addr); 7165796c8dcSSimon Schubert memcpy (&new_args[1], &args[0], sizeof (struct value *) * nargs); 7175796c8dcSSimon Schubert args = new_args; 7185796c8dcSSimon Schubert nargs++; 7195796c8dcSSimon Schubert args_cleanup = make_cleanup (xfree, args); 7205796c8dcSSimon Schubert } 7215796c8dcSSimon Schubert else 7225796c8dcSSimon Schubert args_cleanup = make_cleanup (null_cleanup, NULL); 7235796c8dcSSimon Schubert 7245796c8dcSSimon Schubert /* Create the dummy stack frame. Pass in the call dummy address as, 7255796c8dcSSimon Schubert presumably, the ABI code knows where, in the call dummy, the 7265796c8dcSSimon Schubert return address should be pointed. */ 7275796c8dcSSimon Schubert sp = gdbarch_push_dummy_call (gdbarch, function, get_current_regcache (), 7285796c8dcSSimon Schubert bp_addr, nargs, args, 7295796c8dcSSimon Schubert sp, struct_return, struct_addr); 7305796c8dcSSimon Schubert 7315796c8dcSSimon Schubert do_cleanups (args_cleanup); 7325796c8dcSSimon Schubert 7335796c8dcSSimon Schubert /* Set up a frame ID for the dummy frame so we can pass it to 7345796c8dcSSimon Schubert set_momentary_breakpoint. We need to give the breakpoint a frame 7355796c8dcSSimon Schubert ID so that the breakpoint code can correctly re-identify the 7365796c8dcSSimon Schubert dummy breakpoint. */ 7375796c8dcSSimon Schubert /* Sanity. The exact same SP value is returned by PUSH_DUMMY_CALL, 7385796c8dcSSimon Schubert saved as the dummy-frame TOS, and used by dummy_id to form 7395796c8dcSSimon Schubert the frame ID's stack address. */ 7405796c8dcSSimon Schubert dummy_id = frame_id_build (sp, bp_addr); 7415796c8dcSSimon Schubert 7425796c8dcSSimon Schubert /* Create a momentary breakpoint at the return address of the 7435796c8dcSSimon Schubert inferior. That way it breaks when it returns. */ 7445796c8dcSSimon Schubert 7455796c8dcSSimon Schubert { 7465796c8dcSSimon Schubert struct breakpoint *bpt; 7475796c8dcSSimon Schubert struct symtab_and_line sal; 748*cf7f2e2dSJohn Marino 7495796c8dcSSimon Schubert init_sal (&sal); /* initialize to zeroes */ 750*cf7f2e2dSJohn Marino sal.pspace = current_program_space; 7515796c8dcSSimon Schubert sal.pc = bp_addr; 7525796c8dcSSimon Schubert sal.section = find_pc_overlay (sal.pc); 7535796c8dcSSimon Schubert /* Sanity. The exact same SP value is returned by 7545796c8dcSSimon Schubert PUSH_DUMMY_CALL, saved as the dummy-frame TOS, and used by 7555796c8dcSSimon Schubert dummy_id to form the frame ID's stack address. */ 7565796c8dcSSimon Schubert bpt = set_momentary_breakpoint (gdbarch, sal, dummy_id, bp_call_dummy); 7575796c8dcSSimon Schubert bpt->disposition = disp_del; 7585796c8dcSSimon Schubert } 7595796c8dcSSimon Schubert 7605796c8dcSSimon Schubert /* Create a breakpoint in std::terminate. 7615796c8dcSSimon Schubert If a C++ exception is raised in the dummy-frame, and the 7625796c8dcSSimon Schubert exception handler is (normally, and expected to be) out-of-frame, 7635796c8dcSSimon Schubert the default C++ handler will (wrongly) be called in an inferior 7645796c8dcSSimon Schubert function call. This is wrong, as an exception can be normally 7655796c8dcSSimon Schubert and legally handled out-of-frame. The confines of the dummy frame 7665796c8dcSSimon Schubert prevent the unwinder from finding the correct handler (or any 7675796c8dcSSimon Schubert handler, unless it is in-frame). The default handler calls 7685796c8dcSSimon Schubert std::terminate. This will kill the inferior. Assert that 7695796c8dcSSimon Schubert terminate should never be called in an inferior function 7705796c8dcSSimon Schubert call. Place a momentary breakpoint in the std::terminate function 7715796c8dcSSimon Schubert and if triggered in the call, rewind. */ 7725796c8dcSSimon Schubert if (unwind_on_terminating_exception_p) 773*cf7f2e2dSJohn Marino set_std_terminate_breakpoint (); 7745796c8dcSSimon Schubert 7755796c8dcSSimon Schubert /* Everything's ready, push all the info needed to restore the 7765796c8dcSSimon Schubert caller (and identify the dummy-frame) onto the dummy-frame 7775796c8dcSSimon Schubert stack. */ 7785796c8dcSSimon Schubert dummy_frame_push (caller_state, &dummy_id); 7795796c8dcSSimon Schubert 7805796c8dcSSimon Schubert /* Discard both inf_status and caller_state cleanups. 7815796c8dcSSimon Schubert From this point on we explicitly restore the associated state 7825796c8dcSSimon Schubert or discard it. */ 7835796c8dcSSimon Schubert discard_cleanups (inf_status_cleanup); 7845796c8dcSSimon Schubert 7855796c8dcSSimon Schubert /* Register a clean-up for unwind_on_terminating_exception_breakpoint. */ 786*cf7f2e2dSJohn Marino terminate_bp_cleanup = make_cleanup (cleanup_delete_std_terminate_breakpoint, 787*cf7f2e2dSJohn Marino NULL); 7885796c8dcSSimon Schubert 7895796c8dcSSimon Schubert /* - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - 7905796c8dcSSimon Schubert If you're looking to implement asynchronous dummy-frames, then 7915796c8dcSSimon Schubert just below is the place to chop this function in two.. */ 7925796c8dcSSimon Schubert 7935796c8dcSSimon Schubert /* TP is invalid after run_inferior_call returns, so enclose this 7945796c8dcSSimon Schubert in a block so that it's only in scope during the time it's valid. */ 7955796c8dcSSimon Schubert { 7965796c8dcSSimon Schubert struct thread_info *tp = inferior_thread (); 7975796c8dcSSimon Schubert 7985796c8dcSSimon Schubert /* Save this thread's ptid, we need it later but the thread 7995796c8dcSSimon Schubert may have exited. */ 8005796c8dcSSimon Schubert call_thread_ptid = tp->ptid; 8015796c8dcSSimon Schubert 8025796c8dcSSimon Schubert /* Run the inferior until it stops. */ 8035796c8dcSSimon Schubert 8045796c8dcSSimon Schubert e = run_inferior_call (tp, real_pc); 8055796c8dcSSimon Schubert } 8065796c8dcSSimon Schubert 8075796c8dcSSimon Schubert /* Rethrow an error if we got one trying to run the inferior. */ 8085796c8dcSSimon Schubert 8095796c8dcSSimon Schubert if (e.reason < 0) 8105796c8dcSSimon Schubert { 8115796c8dcSSimon Schubert const char *name = get_function_name (funaddr, 8125796c8dcSSimon Schubert name_buf, sizeof (name_buf)); 8135796c8dcSSimon Schubert 8145796c8dcSSimon Schubert discard_inferior_status (inf_status); 8155796c8dcSSimon Schubert 8165796c8dcSSimon Schubert /* We could discard the dummy frame here if the program exited, 8175796c8dcSSimon Schubert but it will get garbage collected the next time the program is 8185796c8dcSSimon Schubert run anyway. */ 8195796c8dcSSimon Schubert 8205796c8dcSSimon Schubert switch (e.reason) 8215796c8dcSSimon Schubert { 8225796c8dcSSimon Schubert case RETURN_ERROR: 8235796c8dcSSimon Schubert throw_error (e.error, _("\ 8245796c8dcSSimon Schubert %s\n\ 8255796c8dcSSimon Schubert An error occurred while in a function called from GDB.\n\ 8265796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 8275796c8dcSSimon Schubert (%s) will be abandoned.\n\ 8285796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."), 8295796c8dcSSimon Schubert e.message, name); 8305796c8dcSSimon Schubert case RETURN_QUIT: 8315796c8dcSSimon Schubert default: 8325796c8dcSSimon Schubert throw_exception (e); 8335796c8dcSSimon Schubert } 8345796c8dcSSimon Schubert } 8355796c8dcSSimon Schubert 8365796c8dcSSimon Schubert /* If the program has exited, or we stopped at a different thread, 8375796c8dcSSimon Schubert exit and inform the user. */ 8385796c8dcSSimon Schubert 8395796c8dcSSimon Schubert if (! target_has_execution) 8405796c8dcSSimon Schubert { 8415796c8dcSSimon Schubert const char *name = get_function_name (funaddr, 8425796c8dcSSimon Schubert name_buf, sizeof (name_buf)); 8435796c8dcSSimon Schubert 8445796c8dcSSimon Schubert /* If we try to restore the inferior status, 8455796c8dcSSimon Schubert we'll crash as the inferior is no longer running. */ 8465796c8dcSSimon Schubert discard_inferior_status (inf_status); 8475796c8dcSSimon Schubert 8485796c8dcSSimon Schubert /* We could discard the dummy frame here given that the program exited, 8495796c8dcSSimon Schubert but it will get garbage collected the next time the program is 8505796c8dcSSimon Schubert run anyway. */ 8515796c8dcSSimon Schubert 8525796c8dcSSimon Schubert error (_("\ 8535796c8dcSSimon Schubert The program being debugged exited while in a function called from GDB.\n\ 8545796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 8555796c8dcSSimon Schubert (%s) will be abandoned."), 8565796c8dcSSimon Schubert name); 8575796c8dcSSimon Schubert } 8585796c8dcSSimon Schubert 8595796c8dcSSimon Schubert if (! ptid_equal (call_thread_ptid, inferior_ptid)) 8605796c8dcSSimon Schubert { 8615796c8dcSSimon Schubert const char *name = get_function_name (funaddr, 8625796c8dcSSimon Schubert name_buf, sizeof (name_buf)); 8635796c8dcSSimon Schubert 8645796c8dcSSimon Schubert /* We've switched threads. This can happen if another thread gets a 8655796c8dcSSimon Schubert signal or breakpoint while our thread was running. 8665796c8dcSSimon Schubert There's no point in restoring the inferior status, 8675796c8dcSSimon Schubert we're in a different thread. */ 8685796c8dcSSimon Schubert discard_inferior_status (inf_status); 8695796c8dcSSimon Schubert /* Keep the dummy frame record, if the user switches back to the 8705796c8dcSSimon Schubert thread with the hand-call, we'll need it. */ 8715796c8dcSSimon Schubert if (stopped_by_random_signal) 8725796c8dcSSimon Schubert error (_("\ 8735796c8dcSSimon Schubert The program received a signal in another thread while\n\ 8745796c8dcSSimon Schubert making a function call from GDB.\n\ 8755796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 8765796c8dcSSimon Schubert (%s) will be abandoned.\n\ 8775796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."), 8785796c8dcSSimon Schubert name); 8795796c8dcSSimon Schubert else 8805796c8dcSSimon Schubert error (_("\ 8815796c8dcSSimon Schubert The program stopped in another thread while making a function call from GDB.\n\ 8825796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 8835796c8dcSSimon Schubert (%s) will be abandoned.\n\ 8845796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."), 8855796c8dcSSimon Schubert name); 8865796c8dcSSimon Schubert } 8875796c8dcSSimon Schubert 888*cf7f2e2dSJohn Marino if (stopped_by_random_signal || stop_stack_dummy != STOP_STACK_DUMMY) 8895796c8dcSSimon Schubert { 8905796c8dcSSimon Schubert const char *name = get_function_name (funaddr, 8915796c8dcSSimon Schubert name_buf, sizeof (name_buf)); 8925796c8dcSSimon Schubert 8935796c8dcSSimon Schubert if (stopped_by_random_signal) 8945796c8dcSSimon Schubert { 8955796c8dcSSimon Schubert /* We stopped inside the FUNCTION because of a random 8965796c8dcSSimon Schubert signal. Further execution of the FUNCTION is not 8975796c8dcSSimon Schubert allowed. */ 8985796c8dcSSimon Schubert 8995796c8dcSSimon Schubert if (unwind_on_signal_p) 9005796c8dcSSimon Schubert { 9015796c8dcSSimon Schubert /* The user wants the context restored. */ 9025796c8dcSSimon Schubert 9035796c8dcSSimon Schubert /* We must get back to the frame we were before the 9045796c8dcSSimon Schubert dummy call. */ 9055796c8dcSSimon Schubert dummy_frame_pop (dummy_id); 9065796c8dcSSimon Schubert 9075796c8dcSSimon Schubert /* We also need to restore inferior status to that before the 9085796c8dcSSimon Schubert dummy call. */ 9095796c8dcSSimon Schubert restore_inferior_status (inf_status); 9105796c8dcSSimon Schubert 9115796c8dcSSimon Schubert /* FIXME: Insert a bunch of wrap_here; name can be very 9125796c8dcSSimon Schubert long if it's a C++ name with arguments and stuff. */ 9135796c8dcSSimon Schubert error (_("\ 9145796c8dcSSimon Schubert The program being debugged was signaled while in a function called from GDB.\n\ 9155796c8dcSSimon Schubert GDB has restored the context to what it was before the call.\n\ 9165796c8dcSSimon Schubert To change this behavior use \"set unwindonsignal off\".\n\ 9175796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 9185796c8dcSSimon Schubert (%s) will be abandoned."), 9195796c8dcSSimon Schubert name); 9205796c8dcSSimon Schubert } 9215796c8dcSSimon Schubert else 9225796c8dcSSimon Schubert { 9235796c8dcSSimon Schubert /* The user wants to stay in the frame where we stopped 9245796c8dcSSimon Schubert (default). 9255796c8dcSSimon Schubert Discard inferior status, we're not at the same point 9265796c8dcSSimon Schubert we started at. */ 9275796c8dcSSimon Schubert discard_inferior_status (inf_status); 9285796c8dcSSimon Schubert 9295796c8dcSSimon Schubert /* FIXME: Insert a bunch of wrap_here; name can be very 9305796c8dcSSimon Schubert long if it's a C++ name with arguments and stuff. */ 9315796c8dcSSimon Schubert error (_("\ 9325796c8dcSSimon Schubert The program being debugged was signaled while in a function called from GDB.\n\ 9335796c8dcSSimon Schubert GDB remains in the frame where the signal was received.\n\ 9345796c8dcSSimon Schubert To change this behavior use \"set unwindonsignal on\".\n\ 9355796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 9365796c8dcSSimon Schubert (%s) will be abandoned.\n\ 9375796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."), 9385796c8dcSSimon Schubert name); 9395796c8dcSSimon Schubert } 9405796c8dcSSimon Schubert } 9415796c8dcSSimon Schubert 942*cf7f2e2dSJohn Marino if (stop_stack_dummy == STOP_STD_TERMINATE) 9435796c8dcSSimon Schubert { 944*cf7f2e2dSJohn Marino /* We must get back to the frame we were before the dummy 945*cf7f2e2dSJohn Marino call. */ 9465796c8dcSSimon Schubert dummy_frame_pop (dummy_id); 9475796c8dcSSimon Schubert 948*cf7f2e2dSJohn Marino /* We also need to restore inferior status to that before 949*cf7f2e2dSJohn Marino the dummy call. */ 9505796c8dcSSimon Schubert restore_inferior_status (inf_status); 9515796c8dcSSimon Schubert 9525796c8dcSSimon Schubert error (_("\ 9535796c8dcSSimon Schubert The program being debugged entered a std::terminate call, most likely\n\ 9545796c8dcSSimon Schubert caused by an unhandled C++ exception. GDB blocked this call in order\n\ 9555796c8dcSSimon Schubert to prevent the program from being terminated, and has restored the\n\ 9565796c8dcSSimon Schubert context to its original state before the call.\n\ 9575796c8dcSSimon Schubert To change this behaviour use \"set unwind-on-terminating-exception off\".\n\ 9585796c8dcSSimon Schubert Evaluation of the expression containing the function (%s)\n\ 9595796c8dcSSimon Schubert will be abandoned."), 9605796c8dcSSimon Schubert name); 9615796c8dcSSimon Schubert } 962*cf7f2e2dSJohn Marino else if (stop_stack_dummy == STOP_NONE) 963*cf7f2e2dSJohn Marino { 964*cf7f2e2dSJohn Marino 9655796c8dcSSimon Schubert /* We hit a breakpoint inside the FUNCTION. 9665796c8dcSSimon Schubert Keep the dummy frame, the user may want to examine its state. 9675796c8dcSSimon Schubert Discard inferior status, we're not at the same point 9685796c8dcSSimon Schubert we started at. */ 9695796c8dcSSimon Schubert discard_inferior_status (inf_status); 9705796c8dcSSimon Schubert 9715796c8dcSSimon Schubert /* The following error message used to say "The expression 9725796c8dcSSimon Schubert which contained the function call has been discarded." 9735796c8dcSSimon Schubert It is a hard concept to explain in a few words. Ideally, 9745796c8dcSSimon Schubert GDB would be able to resume evaluation of the expression 9755796c8dcSSimon Schubert when the function finally is done executing. Perhaps 9765796c8dcSSimon Schubert someday this will be implemented (it would not be easy). */ 9775796c8dcSSimon Schubert /* FIXME: Insert a bunch of wrap_here; name can be very long if it's 9785796c8dcSSimon Schubert a C++ name with arguments and stuff. */ 9795796c8dcSSimon Schubert error (_("\ 9805796c8dcSSimon Schubert The program being debugged stopped while in a function called from GDB.\n\ 9815796c8dcSSimon Schubert Evaluation of the expression containing the function\n\ 9825796c8dcSSimon Schubert (%s) will be abandoned.\n\ 9835796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."), 9845796c8dcSSimon Schubert name); 9855796c8dcSSimon Schubert } 9865796c8dcSSimon Schubert 9875796c8dcSSimon Schubert /* The above code errors out, so ... */ 9885796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("... should not be here")); 9895796c8dcSSimon Schubert } 9905796c8dcSSimon Schubert 991*cf7f2e2dSJohn Marino do_cleanups (terminate_bp_cleanup); 992*cf7f2e2dSJohn Marino 9935796c8dcSSimon Schubert /* If we get here the called FUNCTION ran to completion, 9945796c8dcSSimon Schubert and the dummy frame has already been popped. */ 9955796c8dcSSimon Schubert 9965796c8dcSSimon Schubert { 997*cf7f2e2dSJohn Marino struct address_space *aspace = get_regcache_aspace (stop_registers); 998*cf7f2e2dSJohn Marino struct regcache *retbuf = regcache_xmalloc (gdbarch, aspace); 9995796c8dcSSimon Schubert struct cleanup *retbuf_cleanup = make_cleanup_regcache_xfree (retbuf); 10005796c8dcSSimon Schubert struct value *retval = NULL; 10015796c8dcSSimon Schubert 10025796c8dcSSimon Schubert regcache_cpy_no_passthrough (retbuf, stop_registers); 10035796c8dcSSimon Schubert 10045796c8dcSSimon Schubert /* Inferior call is successful. Restore the inferior status. 10055796c8dcSSimon Schubert At this stage, leave the RETBUF alone. */ 10065796c8dcSSimon Schubert restore_inferior_status (inf_status); 10075796c8dcSSimon Schubert 10085796c8dcSSimon Schubert /* Figure out the value returned by the function. */ 10095796c8dcSSimon Schubert 10105796c8dcSSimon Schubert if (lang_struct_return) 10115796c8dcSSimon Schubert retval = value_at (values_type, struct_addr); 10125796c8dcSSimon Schubert else if (TYPE_CODE (target_values_type) == TYPE_CODE_VOID) 10135796c8dcSSimon Schubert { 10145796c8dcSSimon Schubert /* If the function returns void, don't bother fetching the 10155796c8dcSSimon Schubert return value. */ 10165796c8dcSSimon Schubert retval = allocate_value (values_type); 10175796c8dcSSimon Schubert } 10185796c8dcSSimon Schubert else 10195796c8dcSSimon Schubert { 10205796c8dcSSimon Schubert switch (gdbarch_return_value (gdbarch, value_type (function), 10215796c8dcSSimon Schubert target_values_type, NULL, NULL, NULL)) 10225796c8dcSSimon Schubert { 10235796c8dcSSimon Schubert case RETURN_VALUE_REGISTER_CONVENTION: 10245796c8dcSSimon Schubert case RETURN_VALUE_ABI_RETURNS_ADDRESS: 10255796c8dcSSimon Schubert case RETURN_VALUE_ABI_PRESERVES_ADDRESS: 10265796c8dcSSimon Schubert retval = allocate_value (values_type); 10275796c8dcSSimon Schubert gdbarch_return_value (gdbarch, value_type (function), values_type, 10285796c8dcSSimon Schubert retbuf, value_contents_raw (retval), NULL); 10295796c8dcSSimon Schubert break; 10305796c8dcSSimon Schubert case RETURN_VALUE_STRUCT_CONVENTION: 10315796c8dcSSimon Schubert retval = value_at (values_type, struct_addr); 10325796c8dcSSimon Schubert break; 10335796c8dcSSimon Schubert } 10345796c8dcSSimon Schubert } 10355796c8dcSSimon Schubert 10365796c8dcSSimon Schubert do_cleanups (retbuf_cleanup); 10375796c8dcSSimon Schubert 10385796c8dcSSimon Schubert gdb_assert (retval); 10395796c8dcSSimon Schubert return retval; 10405796c8dcSSimon Schubert } 10415796c8dcSSimon Schubert } 10425796c8dcSSimon Schubert 10435796c8dcSSimon Schubert 10445796c8dcSSimon Schubert /* Provide a prototype to silence -Wmissing-prototypes. */ 10455796c8dcSSimon Schubert void _initialize_infcall (void); 10465796c8dcSSimon Schubert 10475796c8dcSSimon Schubert void 10485796c8dcSSimon Schubert _initialize_infcall (void) 10495796c8dcSSimon Schubert { 10505796c8dcSSimon Schubert add_setshow_boolean_cmd ("coerce-float-to-double", class_obscure, 10515796c8dcSSimon Schubert &coerce_float_to_double_p, _("\ 10525796c8dcSSimon Schubert Set coercion of floats to doubles when calling functions."), _("\ 10535796c8dcSSimon Schubert Show coercion of floats to doubles when calling functions"), _("\ 10545796c8dcSSimon Schubert Variables of type float should generally be converted to doubles before\n\ 10555796c8dcSSimon Schubert calling an unprototyped function, and left alone when calling a prototyped\n\ 10565796c8dcSSimon Schubert function. However, some older debug info formats do not provide enough\n\ 10575796c8dcSSimon Schubert information to determine that a function is prototyped. If this flag is\n\ 10585796c8dcSSimon Schubert set, GDB will perform the conversion for a function it considers\n\ 10595796c8dcSSimon Schubert unprototyped.\n\ 10605796c8dcSSimon Schubert The default is to perform the conversion.\n"), 10615796c8dcSSimon Schubert NULL, 10625796c8dcSSimon Schubert show_coerce_float_to_double_p, 10635796c8dcSSimon Schubert &setlist, &showlist); 10645796c8dcSSimon Schubert 10655796c8dcSSimon Schubert add_setshow_boolean_cmd ("unwindonsignal", no_class, 10665796c8dcSSimon Schubert &unwind_on_signal_p, _("\ 10675796c8dcSSimon Schubert Set unwinding of stack if a signal is received while in a call dummy."), _("\ 10685796c8dcSSimon Schubert Show unwinding of stack if a signal is received while in a call dummy."), _("\ 10695796c8dcSSimon Schubert The unwindonsignal lets the user determine what gdb should do if a signal\n\ 10705796c8dcSSimon Schubert is received while in a function called from gdb (call dummy). If set, gdb\n\ 10715796c8dcSSimon Schubert unwinds the stack and restore the context to what as it was before the call.\n\ 10725796c8dcSSimon Schubert The default is to stop in the frame where the signal was received."), 10735796c8dcSSimon Schubert NULL, 10745796c8dcSSimon Schubert show_unwind_on_signal_p, 10755796c8dcSSimon Schubert &setlist, &showlist); 10765796c8dcSSimon Schubert 10775796c8dcSSimon Schubert add_setshow_boolean_cmd ("unwind-on-terminating-exception", no_class, 10785796c8dcSSimon Schubert &unwind_on_terminating_exception_p, _("\ 10795796c8dcSSimon Schubert Set unwinding of stack if std::terminate is called while in call dummy."), _("\ 10805796c8dcSSimon Schubert Show unwinding of stack if std::terminate() is called while in a call dummy."), _("\ 10815796c8dcSSimon Schubert The unwind on terminating exception flag lets the user determine\n\ 10825796c8dcSSimon Schubert what gdb should do if a std::terminate() call is made from the\n\ 10835796c8dcSSimon Schubert default exception handler. If set, gdb unwinds the stack and restores\n\ 10845796c8dcSSimon Schubert the context to what it was before the call. If unset, gdb allows the\n\ 10855796c8dcSSimon Schubert std::terminate call to proceed.\n\ 10865796c8dcSSimon Schubert The default is to unwind the frame."), 10875796c8dcSSimon Schubert NULL, 10885796c8dcSSimon Schubert show_unwind_on_terminating_exception_p, 10895796c8dcSSimon Schubert &setlist, &showlist); 10905796c8dcSSimon Schubert 10915796c8dcSSimon Schubert } 1092