15796c8dcSSimon Schubert /* Perform an inferior function call, for GDB, the GNU debugger.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert This file is part of GDB.
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert (at your option) any later version.
115796c8dcSSimon Schubert
125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155796c8dcSSimon Schubert GNU General Public License for more details.
165796c8dcSSimon Schubert
175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
195796c8dcSSimon Schubert
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "breakpoint.h"
22cf7f2e2dSJohn Marino #include "tracepoint.h"
235796c8dcSSimon Schubert #include "target.h"
245796c8dcSSimon Schubert #include "regcache.h"
255796c8dcSSimon Schubert #include "inferior.h"
265796c8dcSSimon Schubert #include "gdb_assert.h"
275796c8dcSSimon Schubert #include "block.h"
285796c8dcSSimon Schubert #include "gdbcore.h"
295796c8dcSSimon Schubert #include "language.h"
305796c8dcSSimon Schubert #include "objfiles.h"
315796c8dcSSimon Schubert #include "gdbcmd.h"
325796c8dcSSimon Schubert #include "command.h"
335796c8dcSSimon Schubert #include "gdb_string.h"
345796c8dcSSimon Schubert #include "infcall.h"
355796c8dcSSimon Schubert #include "dummy-frame.h"
365796c8dcSSimon Schubert #include "ada-lang.h"
375796c8dcSSimon Schubert #include "gdbthread.h"
385796c8dcSSimon Schubert #include "exceptions.h"
395796c8dcSSimon Schubert
405796c8dcSSimon Schubert /* If we can't find a function's name from its address,
415796c8dcSSimon Schubert we print this instead. */
425796c8dcSSimon Schubert #define RAW_FUNCTION_ADDRESS_FORMAT "at 0x%s"
435796c8dcSSimon Schubert #define RAW_FUNCTION_ADDRESS_SIZE (sizeof (RAW_FUNCTION_ADDRESS_FORMAT) \
445796c8dcSSimon Schubert + 2 * sizeof (CORE_ADDR))
455796c8dcSSimon Schubert
465796c8dcSSimon Schubert /* NOTE: cagney/2003-04-16: What's the future of this code?
475796c8dcSSimon Schubert
485796c8dcSSimon Schubert GDB needs an asynchronous expression evaluator, that means an
495796c8dcSSimon Schubert asynchronous inferior function call implementation, and that in
505796c8dcSSimon Schubert turn means restructuring the code so that it is event driven. */
515796c8dcSSimon Schubert
525796c8dcSSimon Schubert /* How you should pass arguments to a function depends on whether it
535796c8dcSSimon Schubert was defined in K&R style or prototype style. If you define a
545796c8dcSSimon Schubert function using the K&R syntax that takes a `float' argument, then
555796c8dcSSimon Schubert callers must pass that argument as a `double'. If you define the
565796c8dcSSimon Schubert function using the prototype syntax, then you must pass the
575796c8dcSSimon Schubert argument as a `float', with no promotion.
585796c8dcSSimon Schubert
595796c8dcSSimon Schubert Unfortunately, on certain older platforms, the debug info doesn't
605796c8dcSSimon Schubert indicate reliably how each function was defined. A function type's
615796c8dcSSimon Schubert TYPE_FLAG_PROTOTYPED flag may be clear, even if the function was
625796c8dcSSimon Schubert defined in prototype style. When calling a function whose
635796c8dcSSimon Schubert TYPE_FLAG_PROTOTYPED flag is clear, GDB consults this flag to
645796c8dcSSimon Schubert decide what to do.
655796c8dcSSimon Schubert
665796c8dcSSimon Schubert For modern targets, it is proper to assume that, if the prototype
675796c8dcSSimon Schubert flag is clear, that can be trusted: `float' arguments should be
685796c8dcSSimon Schubert promoted to `double'. For some older targets, if the prototype
695796c8dcSSimon Schubert flag is clear, that doesn't tell us anything. The default is to
705796c8dcSSimon Schubert trust the debug information; the user can override this behavior
715796c8dcSSimon Schubert with "set coerce-float-to-double 0". */
725796c8dcSSimon Schubert
735796c8dcSSimon Schubert static int coerce_float_to_double_p = 1;
745796c8dcSSimon Schubert static void
show_coerce_float_to_double_p(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)755796c8dcSSimon Schubert show_coerce_float_to_double_p (struct ui_file *file, int from_tty,
765796c8dcSSimon Schubert struct cmd_list_element *c, const char *value)
775796c8dcSSimon Schubert {
78c50c785cSJohn Marino fprintf_filtered (file,
79c50c785cSJohn Marino _("Coercion of floats to doubles "
80c50c785cSJohn Marino "when calling functions is %s.\n"),
815796c8dcSSimon Schubert value);
825796c8dcSSimon Schubert }
835796c8dcSSimon Schubert
845796c8dcSSimon Schubert /* This boolean tells what gdb should do if a signal is received while
855796c8dcSSimon Schubert in a function called from gdb (call dummy). If set, gdb unwinds
865796c8dcSSimon Schubert the stack and restore the context to what as it was before the
875796c8dcSSimon Schubert call.
885796c8dcSSimon Schubert
895796c8dcSSimon Schubert The default is to stop in the frame where the signal was received. */
905796c8dcSSimon Schubert
91*ef5ccd6cSJohn Marino static int unwind_on_signal_p = 0;
925796c8dcSSimon Schubert static void
show_unwind_on_signal_p(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)935796c8dcSSimon Schubert show_unwind_on_signal_p (struct ui_file *file, int from_tty,
945796c8dcSSimon Schubert struct cmd_list_element *c, const char *value)
955796c8dcSSimon Schubert {
96c50c785cSJohn Marino fprintf_filtered (file,
97c50c785cSJohn Marino _("Unwinding of stack if a signal is "
98c50c785cSJohn Marino "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
show_unwind_on_terminating_exception_p(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)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 {
122c50c785cSJohn Marino fprintf_filtered (file,
123c50c785cSJohn Marino _("Unwind stack if a C++ exception is "
124c50c785cSJohn Marino "unhandled while in a call dummy is %s.\n"),
1255796c8dcSSimon Schubert value);
1265796c8dcSSimon Schubert }
1275796c8dcSSimon Schubert
1285796c8dcSSimon Schubert /* Perform the standard coercions that are specified
1295796c8dcSSimon Schubert for arguments to be passed to C or Ada functions.
1305796c8dcSSimon Schubert
1315796c8dcSSimon Schubert If PARAM_TYPE is non-NULL, it is the expected parameter type.
1325796c8dcSSimon Schubert IS_PROTOTYPED is non-zero if the function declaration is prototyped.
1335796c8dcSSimon Schubert SP is the stack pointer were additional data can be pushed (updating
1345796c8dcSSimon Schubert its value as needed). */
1355796c8dcSSimon Schubert
1365796c8dcSSimon Schubert static struct value *
value_arg_coerce(struct gdbarch * gdbarch,struct value * arg,struct type * param_type,int is_prototyped,CORE_ADDR * sp)1375796c8dcSSimon Schubert value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
1385796c8dcSSimon Schubert struct type *param_type, int is_prototyped, CORE_ADDR *sp)
1395796c8dcSSimon Schubert {
1405796c8dcSSimon Schubert const struct builtin_type *builtin = builtin_type (gdbarch);
1415796c8dcSSimon Schubert struct type *arg_type = check_typedef (value_type (arg));
1425796c8dcSSimon Schubert struct type *type
1435796c8dcSSimon Schubert = param_type ? check_typedef (param_type) : arg_type;
1445796c8dcSSimon Schubert
1455796c8dcSSimon Schubert /* Perform any Ada-specific coercion first. */
1465796c8dcSSimon Schubert if (current_language->la_language == language_ada)
147c50c785cSJohn Marino arg = ada_convert_actual (arg, type);
1485796c8dcSSimon Schubert
1495796c8dcSSimon Schubert /* Force the value to the target if we will need its address. At
1505796c8dcSSimon Schubert this point, we could allocate arguments on the stack instead of
1515796c8dcSSimon Schubert calling malloc if we knew that their addresses would not be
1525796c8dcSSimon Schubert saved by the called function. */
1535796c8dcSSimon Schubert arg = value_coerce_to_target (arg);
1545796c8dcSSimon Schubert
1555796c8dcSSimon Schubert switch (TYPE_CODE (type))
1565796c8dcSSimon Schubert {
1575796c8dcSSimon Schubert case TYPE_CODE_REF:
1585796c8dcSSimon Schubert {
1595796c8dcSSimon Schubert struct value *new_value;
1605796c8dcSSimon Schubert
1615796c8dcSSimon Schubert if (TYPE_CODE (arg_type) == TYPE_CODE_REF)
162*ef5ccd6cSJohn Marino return value_cast_pointers (type, arg, 0);
1635796c8dcSSimon Schubert
1645796c8dcSSimon Schubert /* Cast the value to the reference's target type, and then
1655796c8dcSSimon Schubert convert it back to a reference. This will issue an error
1665796c8dcSSimon Schubert if the value was not previously in memory - in some cases
1675796c8dcSSimon Schubert we should clearly be allowing this, but how? */
1685796c8dcSSimon Schubert new_value = value_cast (TYPE_TARGET_TYPE (type), arg);
1695796c8dcSSimon Schubert new_value = value_ref (new_value);
1705796c8dcSSimon Schubert return new_value;
1715796c8dcSSimon Schubert }
1725796c8dcSSimon Schubert case TYPE_CODE_INT:
1735796c8dcSSimon Schubert case TYPE_CODE_CHAR:
1745796c8dcSSimon Schubert case TYPE_CODE_BOOL:
1755796c8dcSSimon Schubert case TYPE_CODE_ENUM:
1765796c8dcSSimon Schubert /* If we don't have a prototype, coerce to integer type if necessary. */
1775796c8dcSSimon Schubert if (!is_prototyped)
1785796c8dcSSimon Schubert {
1795796c8dcSSimon Schubert if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin->builtin_int))
1805796c8dcSSimon Schubert type = builtin->builtin_int;
1815796c8dcSSimon Schubert }
1825796c8dcSSimon Schubert /* Currently all target ABIs require at least the width of an integer
1835796c8dcSSimon Schubert type for an argument. We may have to conditionalize the following
1845796c8dcSSimon Schubert type coercion for future targets. */
1855796c8dcSSimon Schubert if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin->builtin_int))
1865796c8dcSSimon Schubert type = builtin->builtin_int;
1875796c8dcSSimon Schubert break;
1885796c8dcSSimon Schubert case TYPE_CODE_FLT:
1895796c8dcSSimon Schubert if (!is_prototyped && coerce_float_to_double_p)
1905796c8dcSSimon Schubert {
1915796c8dcSSimon Schubert if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin->builtin_double))
1925796c8dcSSimon Schubert type = builtin->builtin_double;
1935796c8dcSSimon Schubert else if (TYPE_LENGTH (type) > TYPE_LENGTH (builtin->builtin_double))
1945796c8dcSSimon Schubert type = builtin->builtin_long_double;
1955796c8dcSSimon Schubert }
1965796c8dcSSimon Schubert break;
1975796c8dcSSimon Schubert case TYPE_CODE_FUNC:
1985796c8dcSSimon Schubert type = lookup_pointer_type (type);
1995796c8dcSSimon Schubert break;
2005796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
2015796c8dcSSimon Schubert /* Arrays are coerced to pointers to their first element, unless
2025796c8dcSSimon Schubert they are vectors, in which case we want to leave them alone,
2035796c8dcSSimon Schubert because they are passed by value. */
2045796c8dcSSimon Schubert if (current_language->c_style_arrays)
2055796c8dcSSimon Schubert if (!TYPE_VECTOR (type))
2065796c8dcSSimon Schubert type = lookup_pointer_type (TYPE_TARGET_TYPE (type));
2075796c8dcSSimon Schubert break;
2085796c8dcSSimon Schubert case TYPE_CODE_UNDEF:
2095796c8dcSSimon Schubert case TYPE_CODE_PTR:
2105796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
2115796c8dcSSimon Schubert case TYPE_CODE_UNION:
2125796c8dcSSimon Schubert case TYPE_CODE_VOID:
2135796c8dcSSimon Schubert case TYPE_CODE_SET:
2145796c8dcSSimon Schubert case TYPE_CODE_RANGE:
2155796c8dcSSimon Schubert case TYPE_CODE_STRING:
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
228c50c785cSJohn Marino /* Return the return type of a function with its first instruction exactly at
229c50c785cSJohn Marino the PC address. Return NULL otherwise. */
230c50c785cSJohn Marino
231c50c785cSJohn Marino static struct type *
find_function_return_type(CORE_ADDR pc)232c50c785cSJohn Marino find_function_return_type (CORE_ADDR pc)
233c50c785cSJohn Marino {
234c50c785cSJohn Marino struct symbol *sym = find_pc_function (pc);
235c50c785cSJohn Marino
236c50c785cSJohn Marino if (sym != NULL && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) == pc
237c50c785cSJohn Marino && SYMBOL_TYPE (sym) != NULL)
238c50c785cSJohn Marino return TYPE_TARGET_TYPE (SYMBOL_TYPE (sym));
239c50c785cSJohn Marino
240c50c785cSJohn Marino return NULL;
241c50c785cSJohn Marino }
242c50c785cSJohn Marino
2435796c8dcSSimon Schubert /* Determine a function's address and its return type from its value.
2445796c8dcSSimon Schubert Calls error() if the function is not valid for calling. */
2455796c8dcSSimon Schubert
2465796c8dcSSimon Schubert CORE_ADDR
find_function_addr(struct value * function,struct type ** retval_type)2475796c8dcSSimon Schubert find_function_addr (struct value *function, struct type **retval_type)
2485796c8dcSSimon Schubert {
2495796c8dcSSimon Schubert struct type *ftype = check_typedef (value_type (function));
2505796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (ftype);
2515796c8dcSSimon Schubert struct type *value_type = NULL;
252c50c785cSJohn Marino /* Initialize it just to avoid a GCC false warning. */
253c50c785cSJohn Marino CORE_ADDR funaddr = 0;
2545796c8dcSSimon Schubert
2555796c8dcSSimon Schubert /* If it's a member function, just look at the function
2565796c8dcSSimon Schubert part of it. */
2575796c8dcSSimon Schubert
2585796c8dcSSimon Schubert /* Determine address to call. */
259c50c785cSJohn Marino if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
260c50c785cSJohn Marino || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
2615796c8dcSSimon Schubert funaddr = value_address (function);
262c50c785cSJohn Marino else if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
2635796c8dcSSimon Schubert {
2645796c8dcSSimon Schubert funaddr = value_as_address (function);
2655796c8dcSSimon Schubert ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
2665796c8dcSSimon Schubert if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
2675796c8dcSSimon Schubert || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
2685796c8dcSSimon Schubert funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
2695796c8dcSSimon Schubert ¤t_target);
270c50c785cSJohn Marino }
271c50c785cSJohn Marino if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
272c50c785cSJohn Marino || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
273c50c785cSJohn Marino {
2745796c8dcSSimon Schubert value_type = TYPE_TARGET_TYPE (ftype);
275c50c785cSJohn Marino
276c50c785cSJohn Marino if (TYPE_GNU_IFUNC (ftype))
277c50c785cSJohn Marino {
278c50c785cSJohn Marino funaddr = gnu_ifunc_resolve_addr (gdbarch, funaddr);
279c50c785cSJohn Marino
280c50c785cSJohn Marino /* Skip querying the function symbol if no RETVAL_TYPE has been
281c50c785cSJohn Marino asked for. */
282c50c785cSJohn Marino if (retval_type)
283c50c785cSJohn Marino value_type = find_function_return_type (funaddr);
2845796c8dcSSimon Schubert }
2855796c8dcSSimon Schubert }
286c50c785cSJohn Marino else if (TYPE_CODE (ftype) == TYPE_CODE_INT)
2875796c8dcSSimon Schubert {
2885796c8dcSSimon Schubert /* Handle the case of functions lacking debugging info.
289c50c785cSJohn Marino Their values are characters since their addresses are char. */
2905796c8dcSSimon Schubert if (TYPE_LENGTH (ftype) == 1)
2915796c8dcSSimon Schubert funaddr = value_as_address (value_addr (function));
2925796c8dcSSimon Schubert else
2935796c8dcSSimon Schubert {
2945796c8dcSSimon Schubert /* Handle function descriptors lacking debug info. */
2955796c8dcSSimon Schubert int found_descriptor = 0;
296cf7f2e2dSJohn Marino
2975796c8dcSSimon Schubert funaddr = 0; /* pacify "gcc -Werror" */
2985796c8dcSSimon Schubert if (VALUE_LVAL (function) == lval_memory)
2995796c8dcSSimon Schubert {
3005796c8dcSSimon Schubert CORE_ADDR nfunaddr;
301cf7f2e2dSJohn Marino
3025796c8dcSSimon Schubert funaddr = value_as_address (value_addr (function));
3035796c8dcSSimon Schubert nfunaddr = funaddr;
3045796c8dcSSimon Schubert funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
3055796c8dcSSimon Schubert ¤t_target);
3065796c8dcSSimon Schubert if (funaddr != nfunaddr)
3075796c8dcSSimon Schubert found_descriptor = 1;
3085796c8dcSSimon Schubert }
3095796c8dcSSimon Schubert if (!found_descriptor)
3105796c8dcSSimon Schubert /* Handle integer used as address of a function. */
3115796c8dcSSimon Schubert funaddr = (CORE_ADDR) value_as_long (function);
3125796c8dcSSimon Schubert }
3135796c8dcSSimon Schubert }
3145796c8dcSSimon Schubert else
3155796c8dcSSimon Schubert error (_("Invalid data type for function to be called."));
3165796c8dcSSimon Schubert
3175796c8dcSSimon Schubert if (retval_type != NULL)
3185796c8dcSSimon Schubert *retval_type = value_type;
3195796c8dcSSimon Schubert return funaddr + gdbarch_deprecated_function_start_offset (gdbarch);
3205796c8dcSSimon Schubert }
3215796c8dcSSimon Schubert
3225796c8dcSSimon Schubert /* For CALL_DUMMY_ON_STACK, push a breakpoint sequence that the called
3235796c8dcSSimon Schubert function returns to. */
3245796c8dcSSimon Schubert
3255796c8dcSSimon Schubert static CORE_ADDR
push_dummy_code(struct gdbarch * gdbarch,CORE_ADDR sp,CORE_ADDR funaddr,struct value ** args,int nargs,struct type * value_type,CORE_ADDR * real_pc,CORE_ADDR * bp_addr,struct regcache * regcache)3265796c8dcSSimon Schubert push_dummy_code (struct gdbarch *gdbarch,
3275796c8dcSSimon Schubert CORE_ADDR sp, CORE_ADDR funaddr,
3285796c8dcSSimon Schubert struct value **args, int nargs,
3295796c8dcSSimon Schubert struct type *value_type,
3305796c8dcSSimon Schubert CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
3315796c8dcSSimon Schubert struct regcache *regcache)
3325796c8dcSSimon Schubert {
3335796c8dcSSimon Schubert gdb_assert (gdbarch_push_dummy_code_p (gdbarch));
3345796c8dcSSimon Schubert
3355796c8dcSSimon Schubert return gdbarch_push_dummy_code (gdbarch, sp, funaddr,
3365796c8dcSSimon Schubert args, nargs, value_type, real_pc, bp_addr,
3375796c8dcSSimon Schubert regcache);
3385796c8dcSSimon Schubert }
3395796c8dcSSimon Schubert
3405796c8dcSSimon Schubert /* Fetch the name of the function at FUNADDR.
3415796c8dcSSimon Schubert This is used in printing an error message for call_function_by_hand.
3425796c8dcSSimon Schubert BUF is used to print FUNADDR in hex if the function name cannot be
3435796c8dcSSimon Schubert determined. It must be large enough to hold formatted result of
3445796c8dcSSimon Schubert RAW_FUNCTION_ADDRESS_FORMAT. */
3455796c8dcSSimon Schubert
3465796c8dcSSimon Schubert static const char *
get_function_name(CORE_ADDR funaddr,char * buf,int buf_size)3475796c8dcSSimon Schubert get_function_name (CORE_ADDR funaddr, char *buf, int buf_size)
3485796c8dcSSimon Schubert {
3495796c8dcSSimon Schubert {
3505796c8dcSSimon Schubert struct symbol *symbol = find_pc_function (funaddr);
351cf7f2e2dSJohn Marino
3525796c8dcSSimon Schubert if (symbol)
3535796c8dcSSimon Schubert return SYMBOL_PRINT_NAME (symbol);
3545796c8dcSSimon Schubert }
3555796c8dcSSimon Schubert
3565796c8dcSSimon Schubert {
3575796c8dcSSimon Schubert /* Try the minimal symbols. */
3585796c8dcSSimon Schubert struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (funaddr);
359cf7f2e2dSJohn Marino
3605796c8dcSSimon Schubert if (msymbol)
3615796c8dcSSimon Schubert return SYMBOL_PRINT_NAME (msymbol);
3625796c8dcSSimon Schubert }
3635796c8dcSSimon Schubert
3645796c8dcSSimon Schubert {
3655796c8dcSSimon Schubert char *tmp = xstrprintf (_(RAW_FUNCTION_ADDRESS_FORMAT),
3665796c8dcSSimon Schubert hex_string (funaddr));
367cf7f2e2dSJohn Marino
3685796c8dcSSimon Schubert gdb_assert (strlen (tmp) + 1 <= buf_size);
3695796c8dcSSimon Schubert strcpy (buf, tmp);
3705796c8dcSSimon Schubert xfree (tmp);
3715796c8dcSSimon Schubert return buf;
3725796c8dcSSimon Schubert }
3735796c8dcSSimon Schubert }
3745796c8dcSSimon Schubert
3755796c8dcSSimon Schubert /* Subroutine of call_function_by_hand to simplify it.
3765796c8dcSSimon Schubert Start up the inferior and wait for it to stop.
3775796c8dcSSimon Schubert Return the exception if there's an error, or an exception with
3785796c8dcSSimon Schubert reason >= 0 if there's no error.
3795796c8dcSSimon Schubert
3805796c8dcSSimon Schubert This is done inside a TRY_CATCH so the caller needn't worry about
3815796c8dcSSimon Schubert thrown errors. The caller should rethrow if there's an error. */
3825796c8dcSSimon Schubert
3835796c8dcSSimon Schubert static struct gdb_exception
run_inferior_call(struct thread_info * call_thread,CORE_ADDR real_pc)3845796c8dcSSimon Schubert run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc)
3855796c8dcSSimon Schubert {
3865796c8dcSSimon Schubert volatile struct gdb_exception e;
387c50c785cSJohn Marino int saved_in_infcall = call_thread->control.in_infcall;
3885796c8dcSSimon Schubert ptid_t call_thread_ptid = call_thread->ptid;
3895796c8dcSSimon Schubert
390c50c785cSJohn Marino call_thread->control.in_infcall = 1;
3915796c8dcSSimon Schubert
3925796c8dcSSimon Schubert clear_proceed_status ();
3935796c8dcSSimon Schubert
3945796c8dcSSimon Schubert disable_watchpoints_before_interactive_call_start ();
395c50c785cSJohn Marino
396c50c785cSJohn Marino /* We want stop_registers, please... */
397c50c785cSJohn Marino call_thread->control.proceed_to_finish = 1;
3985796c8dcSSimon Schubert
3995796c8dcSSimon Schubert TRY_CATCH (e, RETURN_MASK_ALL)
400a45ae5f8SJohn Marino {
401*ef5ccd6cSJohn Marino proceed (real_pc, GDB_SIGNAL_0, 0);
4025796c8dcSSimon Schubert
403a45ae5f8SJohn Marino /* Inferior function calls are always synchronous, even if the
404a45ae5f8SJohn Marino target supports asynchronous execution. Do here what
405a45ae5f8SJohn Marino `proceed' itself does in sync mode. */
406a45ae5f8SJohn Marino if (target_can_async_p () && is_running (inferior_ptid))
407a45ae5f8SJohn Marino {
408a45ae5f8SJohn Marino wait_for_inferior ();
409a45ae5f8SJohn Marino normal_stop ();
410a45ae5f8SJohn Marino }
411a45ae5f8SJohn Marino }
412a45ae5f8SJohn Marino
4135796c8dcSSimon Schubert /* At this point the current thread may have changed. Refresh
4145796c8dcSSimon Schubert CALL_THREAD as it could be invalid if its thread has exited. */
4155796c8dcSSimon Schubert call_thread = find_thread_ptid (call_thread_ptid);
4165796c8dcSSimon Schubert
4175796c8dcSSimon Schubert enable_watchpoints_after_interactive_call_stop ();
4185796c8dcSSimon Schubert
4195796c8dcSSimon Schubert /* Call breakpoint_auto_delete on the current contents of the bpstat
4205796c8dcSSimon Schubert of inferior call thread.
4215796c8dcSSimon Schubert If all error()s out of proceed ended up calling normal_stop
4225796c8dcSSimon Schubert (and perhaps they should; it already does in the special case
4235796c8dcSSimon Schubert of error out of resume()), then we wouldn't need this. */
4245796c8dcSSimon Schubert if (e.reason < 0)
4255796c8dcSSimon Schubert {
4265796c8dcSSimon Schubert if (call_thread != NULL)
427c50c785cSJohn Marino breakpoint_auto_delete (call_thread->control.stop_bpstat);
4285796c8dcSSimon Schubert }
4295796c8dcSSimon Schubert
4305796c8dcSSimon Schubert if (call_thread != NULL)
431c50c785cSJohn Marino call_thread->control.in_infcall = saved_in_infcall;
4325796c8dcSSimon Schubert
4335796c8dcSSimon Schubert return e;
4345796c8dcSSimon Schubert }
4355796c8dcSSimon Schubert
436cf7f2e2dSJohn Marino /* A cleanup function that calls delete_std_terminate_breakpoint. */
437cf7f2e2dSJohn Marino static void
cleanup_delete_std_terminate_breakpoint(void * ignore)438cf7f2e2dSJohn Marino cleanup_delete_std_terminate_breakpoint (void *ignore)
439cf7f2e2dSJohn Marino {
440cf7f2e2dSJohn Marino delete_std_terminate_breakpoint ();
441cf7f2e2dSJohn Marino }
442cf7f2e2dSJohn Marino
4435796c8dcSSimon Schubert /* All this stuff with a dummy frame may seem unnecessarily complicated
4445796c8dcSSimon Schubert (why not just save registers in GDB?). The purpose of pushing a dummy
4455796c8dcSSimon Schubert frame which looks just like a real frame is so that if you call a
4465796c8dcSSimon Schubert function and then hit a breakpoint (get a signal, etc), "backtrace"
4475796c8dcSSimon Schubert will look right. Whether the backtrace needs to actually show the
4485796c8dcSSimon Schubert stack at the time the inferior function was called is debatable, but
4495796c8dcSSimon Schubert it certainly needs to not display garbage. So if you are contemplating
4505796c8dcSSimon Schubert making dummy frames be different from normal frames, consider that. */
4515796c8dcSSimon Schubert
4525796c8dcSSimon Schubert /* Perform a function call in the inferior.
4535796c8dcSSimon Schubert ARGS is a vector of values of arguments (NARGS of them).
4545796c8dcSSimon Schubert FUNCTION is a value, the function to be called.
4555796c8dcSSimon Schubert Returns a value representing what the function returned.
4565796c8dcSSimon Schubert May fail to return, if a breakpoint or signal is hit
4575796c8dcSSimon Schubert during the execution of the function.
4585796c8dcSSimon Schubert
4595796c8dcSSimon Schubert ARGS is modified to contain coerced values. */
4605796c8dcSSimon Schubert
4615796c8dcSSimon Schubert struct value *
call_function_by_hand(struct value * function,int nargs,struct value ** args)4625796c8dcSSimon Schubert call_function_by_hand (struct value *function, int nargs, struct value **args)
4635796c8dcSSimon Schubert {
4645796c8dcSSimon Schubert CORE_ADDR sp;
4655796c8dcSSimon Schubert struct type *values_type, *target_values_type;
466*ef5ccd6cSJohn Marino unsigned char struct_return = 0, hidden_first_param_p = 0;
4675796c8dcSSimon Schubert CORE_ADDR struct_addr = 0;
468c50c785cSJohn Marino struct infcall_control_state *inf_status;
4695796c8dcSSimon Schubert struct cleanup *inf_status_cleanup;
470c50c785cSJohn Marino struct infcall_suspend_state *caller_state;
4715796c8dcSSimon Schubert CORE_ADDR funaddr;
4725796c8dcSSimon Schubert CORE_ADDR real_pc;
4735796c8dcSSimon Schubert struct type *ftype = check_typedef (value_type (function));
4745796c8dcSSimon Schubert CORE_ADDR bp_addr;
4755796c8dcSSimon Schubert struct frame_id dummy_id;
4765796c8dcSSimon Schubert struct cleanup *args_cleanup;
4775796c8dcSSimon Schubert struct frame_info *frame;
4785796c8dcSSimon Schubert struct gdbarch *gdbarch;
479cf7f2e2dSJohn Marino struct cleanup *terminate_bp_cleanup;
4805796c8dcSSimon Schubert ptid_t call_thread_ptid;
4815796c8dcSSimon Schubert struct gdb_exception e;
4825796c8dcSSimon Schubert char name_buf[RAW_FUNCTION_ADDRESS_SIZE];
4835796c8dcSSimon Schubert
4845796c8dcSSimon Schubert if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
4855796c8dcSSimon Schubert ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
4865796c8dcSSimon Schubert
4875796c8dcSSimon Schubert if (!target_has_execution)
4885796c8dcSSimon Schubert noprocess ();
4895796c8dcSSimon Schubert
490cf7f2e2dSJohn Marino if (get_traceframe_number () >= 0)
491cf7f2e2dSJohn Marino error (_("May not call functions while looking at trace frames."));
492cf7f2e2dSJohn Marino
493a45ae5f8SJohn Marino if (execution_direction == EXEC_REVERSE)
494a45ae5f8SJohn Marino error (_("Cannot call functions in reverse mode."));
495a45ae5f8SJohn Marino
4965796c8dcSSimon Schubert frame = get_current_frame ();
4975796c8dcSSimon Schubert gdbarch = get_frame_arch (frame);
4985796c8dcSSimon Schubert
4995796c8dcSSimon Schubert if (!gdbarch_push_dummy_call_p (gdbarch))
5005796c8dcSSimon Schubert error (_("This target does not support function calls."));
5015796c8dcSSimon Schubert
5025796c8dcSSimon Schubert /* A cleanup for the inferior status.
5035796c8dcSSimon Schubert This is only needed while we're preparing the inferior function call. */
504c50c785cSJohn Marino inf_status = save_infcall_control_state ();
505c50c785cSJohn Marino inf_status_cleanup
506c50c785cSJohn Marino = make_cleanup_restore_infcall_control_state (inf_status);
5075796c8dcSSimon Schubert
5085796c8dcSSimon Schubert /* Save the caller's registers and other state associated with the
5095796c8dcSSimon Schubert inferior itself so that they can be restored once the
5105796c8dcSSimon Schubert callee returns. To allow nested calls the registers are (further
5115796c8dcSSimon Schubert down) pushed onto a dummy frame stack. Include a cleanup (which
5125796c8dcSSimon Schubert is tossed once the regcache has been pushed). */
513c50c785cSJohn Marino caller_state = save_infcall_suspend_state ();
514c50c785cSJohn Marino make_cleanup_restore_infcall_suspend_state (caller_state);
5155796c8dcSSimon Schubert
5165796c8dcSSimon Schubert /* Ensure that the initial SP is correctly aligned. */
5175796c8dcSSimon Schubert {
5185796c8dcSSimon Schubert CORE_ADDR old_sp = get_frame_sp (frame);
519cf7f2e2dSJohn Marino
5205796c8dcSSimon Schubert if (gdbarch_frame_align_p (gdbarch))
5215796c8dcSSimon Schubert {
5225796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, old_sp);
5235796c8dcSSimon Schubert /* NOTE: cagney/2003-08-13: Skip the "red zone". For some
5245796c8dcSSimon Schubert ABIs, a function can use memory beyond the inner most stack
5255796c8dcSSimon Schubert address. AMD64 called that region the "red zone". Skip at
5265796c8dcSSimon Schubert least the "red zone" size before allocating any space on
5275796c8dcSSimon Schubert the stack. */
5285796c8dcSSimon Schubert if (gdbarch_inner_than (gdbarch, 1, 2))
5295796c8dcSSimon Schubert sp -= gdbarch_frame_red_zone_size (gdbarch);
5305796c8dcSSimon Schubert else
5315796c8dcSSimon Schubert sp += gdbarch_frame_red_zone_size (gdbarch);
5325796c8dcSSimon Schubert /* Still aligned? */
5335796c8dcSSimon Schubert gdb_assert (sp == gdbarch_frame_align (gdbarch, sp));
5345796c8dcSSimon Schubert /* NOTE: cagney/2002-09-18:
5355796c8dcSSimon Schubert
5365796c8dcSSimon Schubert On a RISC architecture, a void parameterless generic dummy
5375796c8dcSSimon Schubert frame (i.e., no parameters, no result) typically does not
5385796c8dcSSimon Schubert need to push anything the stack and hence can leave SP and
5395796c8dcSSimon Schubert FP. Similarly, a frameless (possibly leaf) function does
5405796c8dcSSimon Schubert not push anything on the stack and, hence, that too can
5415796c8dcSSimon Schubert leave FP and SP unchanged. As a consequence, a sequence of
5425796c8dcSSimon Schubert void parameterless generic dummy frame calls to frameless
5435796c8dcSSimon Schubert functions will create a sequence of effectively identical
5445796c8dcSSimon Schubert frames (SP, FP and TOS and PC the same). This, not
5455796c8dcSSimon Schubert suprisingly, results in what appears to be a stack in an
5465796c8dcSSimon Schubert infinite loop --- when GDB tries to find a generic dummy
5475796c8dcSSimon Schubert frame on the internal dummy frame stack, it will always
5485796c8dcSSimon Schubert find the first one.
5495796c8dcSSimon Schubert
5505796c8dcSSimon Schubert To avoid this problem, the code below always grows the
5515796c8dcSSimon Schubert stack. That way, two dummy frames can never be identical.
5525796c8dcSSimon Schubert It does burn a few bytes of stack but that is a small price
5535796c8dcSSimon Schubert to pay :-). */
5545796c8dcSSimon Schubert if (sp == old_sp)
5555796c8dcSSimon Schubert {
5565796c8dcSSimon Schubert if (gdbarch_inner_than (gdbarch, 1, 2))
5575796c8dcSSimon Schubert /* Stack grows down. */
5585796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, old_sp - 1);
5595796c8dcSSimon Schubert else
5605796c8dcSSimon Schubert /* Stack grows up. */
5615796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, old_sp + 1);
5625796c8dcSSimon Schubert }
563cf7f2e2dSJohn Marino /* SP may have underflown address zero here from OLD_SP. Memory access
564cf7f2e2dSJohn Marino functions will probably fail in such case but that is a target's
565cf7f2e2dSJohn Marino problem. */
5665796c8dcSSimon Schubert }
5675796c8dcSSimon Schubert else
5685796c8dcSSimon Schubert /* FIXME: cagney/2002-09-18: Hey, you loose!
5695796c8dcSSimon Schubert
5705796c8dcSSimon Schubert Who knows how badly aligned the SP is!
5715796c8dcSSimon Schubert
5725796c8dcSSimon Schubert If the generic dummy frame ends up empty (because nothing is
5735796c8dcSSimon Schubert pushed) GDB won't be able to correctly perform back traces.
5745796c8dcSSimon Schubert If a target is having trouble with backtraces, first thing to
5755796c8dcSSimon Schubert do is add FRAME_ALIGN() to the architecture vector. If that
5765796c8dcSSimon Schubert fails, try dummy_id().
5775796c8dcSSimon Schubert
5785796c8dcSSimon Schubert If the ABI specifies a "Red Zone" (see the doco) the code
5795796c8dcSSimon Schubert below will quietly trash it. */
5805796c8dcSSimon Schubert sp = old_sp;
5815796c8dcSSimon Schubert }
5825796c8dcSSimon Schubert
5835796c8dcSSimon Schubert funaddr = find_function_addr (function, &values_type);
5845796c8dcSSimon Schubert if (!values_type)
5855796c8dcSSimon Schubert values_type = builtin_type (gdbarch)->builtin_int;
5865796c8dcSSimon Schubert
5875796c8dcSSimon Schubert CHECK_TYPEDEF (values_type);
5885796c8dcSSimon Schubert
5895796c8dcSSimon Schubert /* Are we returning a value using a structure return (passing a
5905796c8dcSSimon Schubert hidden argument pointing to storage) or a normal value return?
5915796c8dcSSimon Schubert There are two cases: language-mandated structure return and
5925796c8dcSSimon Schubert target ABI structure return. The variable STRUCT_RETURN only
5935796c8dcSSimon Schubert describes the latter. The language version is handled by passing
5945796c8dcSSimon Schubert the return location as the first parameter to the function,
5955796c8dcSSimon Schubert even preceding "this". This is different from the target
5965796c8dcSSimon Schubert ABI version, which is target-specific; for instance, on ia64
5975796c8dcSSimon Schubert the first argument is passed in out0 but the hidden structure
5985796c8dcSSimon Schubert return pointer would normally be passed in r8. */
5995796c8dcSSimon Schubert
600*ef5ccd6cSJohn Marino if (gdbarch_return_in_first_hidden_param_p (gdbarch, values_type))
6015796c8dcSSimon Schubert {
602*ef5ccd6cSJohn Marino hidden_first_param_p = 1;
6035796c8dcSSimon Schubert
6045796c8dcSSimon Schubert /* Tell the target specific argument pushing routine not to
6055796c8dcSSimon Schubert expect a value. */
6065796c8dcSSimon Schubert target_values_type = builtin_type (gdbarch)->builtin_void;
6075796c8dcSSimon Schubert }
6085796c8dcSSimon Schubert else
6095796c8dcSSimon Schubert {
610*ef5ccd6cSJohn Marino struct_return = using_struct_return (gdbarch, function, values_type);
6115796c8dcSSimon Schubert target_values_type = values_type;
6125796c8dcSSimon Schubert }
6135796c8dcSSimon Schubert
6145796c8dcSSimon Schubert /* Determine the location of the breakpoint (and possibly other
6155796c8dcSSimon Schubert stuff) that the called function will return to. The SPARC, for a
6165796c8dcSSimon Schubert function returning a structure or union, needs to make space for
6175796c8dcSSimon Schubert not just the breakpoint but also an extra word containing the
6185796c8dcSSimon Schubert size (?) of the structure being passed. */
6195796c8dcSSimon Schubert
6205796c8dcSSimon Schubert switch (gdbarch_call_dummy_location (gdbarch))
6215796c8dcSSimon Schubert {
6225796c8dcSSimon Schubert case ON_STACK:
623*ef5ccd6cSJohn Marino {
624*ef5ccd6cSJohn Marino const gdb_byte *bp_bytes;
625*ef5ccd6cSJohn Marino CORE_ADDR bp_addr_as_address;
626*ef5ccd6cSJohn Marino int bp_size;
627*ef5ccd6cSJohn Marino
628*ef5ccd6cSJohn Marino /* Be careful BP_ADDR is in inferior PC encoding while
629*ef5ccd6cSJohn Marino BP_ADDR_AS_ADDRESS is a plain memory address. */
630*ef5ccd6cSJohn Marino
631*ef5ccd6cSJohn Marino sp = push_dummy_code (gdbarch, sp, funaddr, args, nargs,
632*ef5ccd6cSJohn Marino target_values_type, &real_pc, &bp_addr,
633*ef5ccd6cSJohn Marino get_current_regcache ());
634*ef5ccd6cSJohn Marino
635*ef5ccd6cSJohn Marino /* Write a legitimate instruction at the point where the infcall
636*ef5ccd6cSJohn Marino breakpoint is going to be inserted. While this instruction
637*ef5ccd6cSJohn Marino is never going to be executed, a user investigating the
638*ef5ccd6cSJohn Marino memory from GDB would see this instruction instead of random
639*ef5ccd6cSJohn Marino uninitialized bytes. We chose the breakpoint instruction
640*ef5ccd6cSJohn Marino as it may look as the most logical one to the user and also
641*ef5ccd6cSJohn Marino valgrind 3.7.0 needs it for proper vgdb inferior calls.
642*ef5ccd6cSJohn Marino
643*ef5ccd6cSJohn Marino If software breakpoints are unsupported for this target we
644*ef5ccd6cSJohn Marino leave the user visible memory content uninitialized. */
645*ef5ccd6cSJohn Marino
646*ef5ccd6cSJohn Marino bp_addr_as_address = bp_addr;
647*ef5ccd6cSJohn Marino bp_bytes = gdbarch_breakpoint_from_pc (gdbarch, &bp_addr_as_address,
648*ef5ccd6cSJohn Marino &bp_size);
649*ef5ccd6cSJohn Marino if (bp_bytes != NULL)
650*ef5ccd6cSJohn Marino write_memory (bp_addr_as_address, bp_bytes, bp_size);
651*ef5ccd6cSJohn Marino }
6525796c8dcSSimon Schubert break;
6535796c8dcSSimon Schubert case AT_ENTRY_POINT:
6545796c8dcSSimon Schubert {
6555796c8dcSSimon Schubert CORE_ADDR dummy_addr;
6565796c8dcSSimon Schubert
6575796c8dcSSimon Schubert real_pc = funaddr;
6585796c8dcSSimon Schubert dummy_addr = entry_point_address ();
6595796c8dcSSimon Schubert
660*ef5ccd6cSJohn Marino /* A call dummy always consists of just a single breakpoint, so
661*ef5ccd6cSJohn Marino its address is the same as the address of the dummy.
662*ef5ccd6cSJohn Marino
663*ef5ccd6cSJohn Marino The actual breakpoint is inserted separatly so there is no need to
664*ef5ccd6cSJohn Marino write that out. */
6655796c8dcSSimon Schubert bp_addr = dummy_addr;
6665796c8dcSSimon Schubert break;
6675796c8dcSSimon Schubert }
6685796c8dcSSimon Schubert default:
6695796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("bad switch"));
6705796c8dcSSimon Schubert }
6715796c8dcSSimon Schubert
6725796c8dcSSimon Schubert if (nargs < TYPE_NFIELDS (ftype))
6735796c8dcSSimon Schubert error (_("Too few arguments in function call."));
6745796c8dcSSimon Schubert
6755796c8dcSSimon Schubert {
6765796c8dcSSimon Schubert int i;
677cf7f2e2dSJohn Marino
6785796c8dcSSimon Schubert for (i = nargs - 1; i >= 0; i--)
6795796c8dcSSimon Schubert {
6805796c8dcSSimon Schubert int prototyped;
6815796c8dcSSimon Schubert struct type *param_type;
6825796c8dcSSimon Schubert
6835796c8dcSSimon Schubert /* FIXME drow/2002-05-31: Should just always mark methods as
6845796c8dcSSimon Schubert prototyped. Can we respect TYPE_VARARGS? Probably not. */
6855796c8dcSSimon Schubert if (TYPE_CODE (ftype) == TYPE_CODE_METHOD)
6865796c8dcSSimon Schubert prototyped = 1;
6875796c8dcSSimon Schubert else if (i < TYPE_NFIELDS (ftype))
6885796c8dcSSimon Schubert prototyped = TYPE_PROTOTYPED (ftype);
6895796c8dcSSimon Schubert else
6905796c8dcSSimon Schubert prototyped = 0;
6915796c8dcSSimon Schubert
6925796c8dcSSimon Schubert if (i < TYPE_NFIELDS (ftype))
6935796c8dcSSimon Schubert param_type = TYPE_FIELD_TYPE (ftype, i);
6945796c8dcSSimon Schubert else
6955796c8dcSSimon Schubert param_type = NULL;
6965796c8dcSSimon Schubert
6975796c8dcSSimon Schubert args[i] = value_arg_coerce (gdbarch, args[i],
6985796c8dcSSimon Schubert param_type, prototyped, &sp);
6995796c8dcSSimon Schubert
7005796c8dcSSimon Schubert if (param_type != NULL && language_pass_by_reference (param_type))
7015796c8dcSSimon Schubert args[i] = value_addr (args[i]);
7025796c8dcSSimon Schubert }
7035796c8dcSSimon Schubert }
7045796c8dcSSimon Schubert
7055796c8dcSSimon Schubert /* Reserve space for the return structure to be written on the
7065796c8dcSSimon Schubert stack, if necessary. Make certain that the value is correctly
7075796c8dcSSimon Schubert aligned. */
7085796c8dcSSimon Schubert
709*ef5ccd6cSJohn Marino if (struct_return || hidden_first_param_p)
7105796c8dcSSimon Schubert {
7115796c8dcSSimon Schubert if (gdbarch_inner_than (gdbarch, 1, 2))
7125796c8dcSSimon Schubert {
7135796c8dcSSimon Schubert /* Stack grows downward. Align STRUCT_ADDR and SP after
7145796c8dcSSimon Schubert making space for the return value. */
715*ef5ccd6cSJohn Marino sp -= TYPE_LENGTH (values_type);
7165796c8dcSSimon Schubert if (gdbarch_frame_align_p (gdbarch))
7175796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, sp);
7185796c8dcSSimon Schubert struct_addr = sp;
7195796c8dcSSimon Schubert }
7205796c8dcSSimon Schubert else
7215796c8dcSSimon Schubert {
7225796c8dcSSimon Schubert /* Stack grows upward. Align the frame, allocate space, and
7235796c8dcSSimon Schubert then again, re-align the frame??? */
7245796c8dcSSimon Schubert if (gdbarch_frame_align_p (gdbarch))
7255796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, sp);
7265796c8dcSSimon Schubert struct_addr = sp;
727*ef5ccd6cSJohn Marino sp += TYPE_LENGTH (values_type);
7285796c8dcSSimon Schubert if (gdbarch_frame_align_p (gdbarch))
7295796c8dcSSimon Schubert sp = gdbarch_frame_align (gdbarch, sp);
7305796c8dcSSimon Schubert }
7315796c8dcSSimon Schubert }
7325796c8dcSSimon Schubert
733*ef5ccd6cSJohn Marino if (hidden_first_param_p)
7345796c8dcSSimon Schubert {
7355796c8dcSSimon Schubert struct value **new_args;
7365796c8dcSSimon Schubert
7375796c8dcSSimon Schubert /* Add the new argument to the front of the argument list. */
7385796c8dcSSimon Schubert new_args = xmalloc (sizeof (struct value *) * (nargs + 1));
7395796c8dcSSimon Schubert new_args[0] = value_from_pointer (lookup_pointer_type (values_type),
7405796c8dcSSimon Schubert struct_addr);
7415796c8dcSSimon Schubert memcpy (&new_args[1], &args[0], sizeof (struct value *) * nargs);
7425796c8dcSSimon Schubert args = new_args;
7435796c8dcSSimon Schubert nargs++;
7445796c8dcSSimon Schubert args_cleanup = make_cleanup (xfree, args);
7455796c8dcSSimon Schubert }
7465796c8dcSSimon Schubert else
7475796c8dcSSimon Schubert args_cleanup = make_cleanup (null_cleanup, NULL);
7485796c8dcSSimon Schubert
7495796c8dcSSimon Schubert /* Create the dummy stack frame. Pass in the call dummy address as,
7505796c8dcSSimon Schubert presumably, the ABI code knows where, in the call dummy, the
7515796c8dcSSimon Schubert return address should be pointed. */
7525796c8dcSSimon Schubert sp = gdbarch_push_dummy_call (gdbarch, function, get_current_regcache (),
7535796c8dcSSimon Schubert bp_addr, nargs, args,
7545796c8dcSSimon Schubert sp, struct_return, struct_addr);
7555796c8dcSSimon Schubert
7565796c8dcSSimon Schubert do_cleanups (args_cleanup);
7575796c8dcSSimon Schubert
7585796c8dcSSimon Schubert /* Set up a frame ID for the dummy frame so we can pass it to
7595796c8dcSSimon Schubert set_momentary_breakpoint. We need to give the breakpoint a frame
7605796c8dcSSimon Schubert ID so that the breakpoint code can correctly re-identify the
7615796c8dcSSimon Schubert dummy breakpoint. */
7625796c8dcSSimon Schubert /* Sanity. The exact same SP value is returned by PUSH_DUMMY_CALL,
7635796c8dcSSimon Schubert saved as the dummy-frame TOS, and used by dummy_id to form
7645796c8dcSSimon Schubert the frame ID's stack address. */
7655796c8dcSSimon Schubert dummy_id = frame_id_build (sp, bp_addr);
7665796c8dcSSimon Schubert
7675796c8dcSSimon Schubert /* Create a momentary breakpoint at the return address of the
7685796c8dcSSimon Schubert inferior. That way it breaks when it returns. */
7695796c8dcSSimon Schubert
7705796c8dcSSimon Schubert {
771*ef5ccd6cSJohn Marino struct breakpoint *bpt, *longjmp_b;
7725796c8dcSSimon Schubert struct symtab_and_line sal;
773cf7f2e2dSJohn Marino
7745796c8dcSSimon Schubert init_sal (&sal); /* initialize to zeroes */
775cf7f2e2dSJohn Marino sal.pspace = current_program_space;
7765796c8dcSSimon Schubert sal.pc = bp_addr;
7775796c8dcSSimon Schubert sal.section = find_pc_overlay (sal.pc);
7785796c8dcSSimon Schubert /* Sanity. The exact same SP value is returned by
7795796c8dcSSimon Schubert PUSH_DUMMY_CALL, saved as the dummy-frame TOS, and used by
7805796c8dcSSimon Schubert dummy_id to form the frame ID's stack address. */
7815796c8dcSSimon Schubert bpt = set_momentary_breakpoint (gdbarch, sal, dummy_id, bp_call_dummy);
782*ef5ccd6cSJohn Marino
783*ef5ccd6cSJohn Marino /* set_momentary_breakpoint invalidates FRAME. */
784*ef5ccd6cSJohn Marino frame = NULL;
785*ef5ccd6cSJohn Marino
7865796c8dcSSimon Schubert bpt->disposition = disp_del;
787*ef5ccd6cSJohn Marino gdb_assert (bpt->related_breakpoint == bpt);
788*ef5ccd6cSJohn Marino
789*ef5ccd6cSJohn Marino longjmp_b = set_longjmp_breakpoint_for_call_dummy ();
790*ef5ccd6cSJohn Marino if (longjmp_b)
791*ef5ccd6cSJohn Marino {
792*ef5ccd6cSJohn Marino /* Link BPT into the chain of LONGJMP_B. */
793*ef5ccd6cSJohn Marino bpt->related_breakpoint = longjmp_b;
794*ef5ccd6cSJohn Marino while (longjmp_b->related_breakpoint != bpt->related_breakpoint)
795*ef5ccd6cSJohn Marino longjmp_b = longjmp_b->related_breakpoint;
796*ef5ccd6cSJohn Marino longjmp_b->related_breakpoint = bpt;
797*ef5ccd6cSJohn Marino }
7985796c8dcSSimon Schubert }
7995796c8dcSSimon Schubert
8005796c8dcSSimon Schubert /* Create a breakpoint in std::terminate.
8015796c8dcSSimon Schubert If a C++ exception is raised in the dummy-frame, and the
8025796c8dcSSimon Schubert exception handler is (normally, and expected to be) out-of-frame,
8035796c8dcSSimon Schubert the default C++ handler will (wrongly) be called in an inferior
8045796c8dcSSimon Schubert function call. This is wrong, as an exception can be normally
8055796c8dcSSimon Schubert and legally handled out-of-frame. The confines of the dummy frame
8065796c8dcSSimon Schubert prevent the unwinder from finding the correct handler (or any
8075796c8dcSSimon Schubert handler, unless it is in-frame). The default handler calls
8085796c8dcSSimon Schubert std::terminate. This will kill the inferior. Assert that
8095796c8dcSSimon Schubert terminate should never be called in an inferior function
8105796c8dcSSimon Schubert call. Place a momentary breakpoint in the std::terminate function
8115796c8dcSSimon Schubert and if triggered in the call, rewind. */
8125796c8dcSSimon Schubert if (unwind_on_terminating_exception_p)
813cf7f2e2dSJohn Marino set_std_terminate_breakpoint ();
8145796c8dcSSimon Schubert
8155796c8dcSSimon Schubert /* Everything's ready, push all the info needed to restore the
8165796c8dcSSimon Schubert caller (and identify the dummy-frame) onto the dummy-frame
8175796c8dcSSimon Schubert stack. */
8185796c8dcSSimon Schubert dummy_frame_push (caller_state, &dummy_id);
8195796c8dcSSimon Schubert
8205796c8dcSSimon Schubert /* Discard both inf_status and caller_state cleanups.
8215796c8dcSSimon Schubert From this point on we explicitly restore the associated state
8225796c8dcSSimon Schubert or discard it. */
8235796c8dcSSimon Schubert discard_cleanups (inf_status_cleanup);
8245796c8dcSSimon Schubert
8255796c8dcSSimon Schubert /* Register a clean-up for unwind_on_terminating_exception_breakpoint. */
826cf7f2e2dSJohn Marino terminate_bp_cleanup = make_cleanup (cleanup_delete_std_terminate_breakpoint,
827cf7f2e2dSJohn Marino NULL);
8285796c8dcSSimon Schubert
8295796c8dcSSimon Schubert /* - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP -
8305796c8dcSSimon Schubert If you're looking to implement asynchronous dummy-frames, then
8315796c8dcSSimon Schubert just below is the place to chop this function in two.. */
8325796c8dcSSimon Schubert
8335796c8dcSSimon Schubert /* TP is invalid after run_inferior_call returns, so enclose this
8345796c8dcSSimon Schubert in a block so that it's only in scope during the time it's valid. */
8355796c8dcSSimon Schubert {
8365796c8dcSSimon Schubert struct thread_info *tp = inferior_thread ();
8375796c8dcSSimon Schubert
8385796c8dcSSimon Schubert /* Save this thread's ptid, we need it later but the thread
8395796c8dcSSimon Schubert may have exited. */
8405796c8dcSSimon Schubert call_thread_ptid = tp->ptid;
8415796c8dcSSimon Schubert
8425796c8dcSSimon Schubert /* Run the inferior until it stops. */
8435796c8dcSSimon Schubert
8445796c8dcSSimon Schubert e = run_inferior_call (tp, real_pc);
8455796c8dcSSimon Schubert }
8465796c8dcSSimon Schubert
8475796c8dcSSimon Schubert /* Rethrow an error if we got one trying to run the inferior. */
8485796c8dcSSimon Schubert
8495796c8dcSSimon Schubert if (e.reason < 0)
8505796c8dcSSimon Schubert {
8515796c8dcSSimon Schubert const char *name = get_function_name (funaddr,
8525796c8dcSSimon Schubert name_buf, sizeof (name_buf));
8535796c8dcSSimon Schubert
854c50c785cSJohn Marino discard_infcall_control_state (inf_status);
8555796c8dcSSimon Schubert
8565796c8dcSSimon Schubert /* We could discard the dummy frame here if the program exited,
8575796c8dcSSimon Schubert but it will get garbage collected the next time the program is
8585796c8dcSSimon Schubert run anyway. */
8595796c8dcSSimon Schubert
8605796c8dcSSimon Schubert switch (e.reason)
8615796c8dcSSimon Schubert {
8625796c8dcSSimon Schubert case RETURN_ERROR:
863c50c785cSJohn Marino throw_error (e.error, _("%s\n\
8645796c8dcSSimon Schubert An error occurred while in a function called from GDB.\n\
8655796c8dcSSimon Schubert Evaluation of the expression containing the function\n\
8665796c8dcSSimon Schubert (%s) will be abandoned.\n\
8675796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."),
8685796c8dcSSimon Schubert e.message, name);
8695796c8dcSSimon Schubert case RETURN_QUIT:
8705796c8dcSSimon Schubert default:
8715796c8dcSSimon Schubert throw_exception (e);
8725796c8dcSSimon Schubert }
8735796c8dcSSimon Schubert }
8745796c8dcSSimon Schubert
8755796c8dcSSimon Schubert /* If the program has exited, or we stopped at a different thread,
8765796c8dcSSimon Schubert exit and inform the user. */
8775796c8dcSSimon Schubert
8785796c8dcSSimon Schubert if (! target_has_execution)
8795796c8dcSSimon Schubert {
8805796c8dcSSimon Schubert const char *name = get_function_name (funaddr,
8815796c8dcSSimon Schubert name_buf, sizeof (name_buf));
8825796c8dcSSimon Schubert
8835796c8dcSSimon Schubert /* If we try to restore the inferior status,
8845796c8dcSSimon Schubert we'll crash as the inferior is no longer running. */
885c50c785cSJohn Marino discard_infcall_control_state (inf_status);
8865796c8dcSSimon Schubert
8875796c8dcSSimon Schubert /* We could discard the dummy frame here given that the program exited,
8885796c8dcSSimon Schubert but it will get garbage collected the next time the program is
8895796c8dcSSimon Schubert run anyway. */
8905796c8dcSSimon Schubert
891c50c785cSJohn Marino error (_("The program being debugged exited while in a function "
892c50c785cSJohn Marino "called from GDB.\n"
893c50c785cSJohn Marino "Evaluation of the expression containing the function\n"
894c50c785cSJohn Marino "(%s) will be abandoned."),
8955796c8dcSSimon Schubert name);
8965796c8dcSSimon Schubert }
8975796c8dcSSimon Schubert
8985796c8dcSSimon Schubert if (! ptid_equal (call_thread_ptid, inferior_ptid))
8995796c8dcSSimon Schubert {
9005796c8dcSSimon Schubert const char *name = get_function_name (funaddr,
9015796c8dcSSimon Schubert name_buf, sizeof (name_buf));
9025796c8dcSSimon Schubert
9035796c8dcSSimon Schubert /* We've switched threads. This can happen if another thread gets a
9045796c8dcSSimon Schubert signal or breakpoint while our thread was running.
9055796c8dcSSimon Schubert There's no point in restoring the inferior status,
9065796c8dcSSimon Schubert we're in a different thread. */
907c50c785cSJohn Marino discard_infcall_control_state (inf_status);
9085796c8dcSSimon Schubert /* Keep the dummy frame record, if the user switches back to the
9095796c8dcSSimon Schubert thread with the hand-call, we'll need it. */
9105796c8dcSSimon Schubert if (stopped_by_random_signal)
9115796c8dcSSimon Schubert error (_("\
9125796c8dcSSimon Schubert The program received a signal in another thread while\n\
9135796c8dcSSimon Schubert making a function call from GDB.\n\
9145796c8dcSSimon Schubert Evaluation of the expression containing the function\n\
9155796c8dcSSimon Schubert (%s) will be abandoned.\n\
9165796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."),
9175796c8dcSSimon Schubert name);
9185796c8dcSSimon Schubert else
9195796c8dcSSimon Schubert error (_("\
9205796c8dcSSimon Schubert The program stopped in another thread while making a function call from GDB.\n\
9215796c8dcSSimon Schubert Evaluation of the expression containing the function\n\
9225796c8dcSSimon Schubert (%s) will be abandoned.\n\
9235796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."),
9245796c8dcSSimon Schubert name);
9255796c8dcSSimon Schubert }
9265796c8dcSSimon Schubert
927cf7f2e2dSJohn Marino if (stopped_by_random_signal || stop_stack_dummy != STOP_STACK_DUMMY)
9285796c8dcSSimon Schubert {
9295796c8dcSSimon Schubert const char *name = get_function_name (funaddr,
9305796c8dcSSimon Schubert name_buf, sizeof (name_buf));
9315796c8dcSSimon Schubert
9325796c8dcSSimon Schubert if (stopped_by_random_signal)
9335796c8dcSSimon Schubert {
9345796c8dcSSimon Schubert /* We stopped inside the FUNCTION because of a random
9355796c8dcSSimon Schubert signal. Further execution of the FUNCTION is not
9365796c8dcSSimon Schubert allowed. */
9375796c8dcSSimon Schubert
9385796c8dcSSimon Schubert if (unwind_on_signal_p)
9395796c8dcSSimon Schubert {
9405796c8dcSSimon Schubert /* The user wants the context restored. */
9415796c8dcSSimon Schubert
9425796c8dcSSimon Schubert /* We must get back to the frame we were before the
9435796c8dcSSimon Schubert dummy call. */
9445796c8dcSSimon Schubert dummy_frame_pop (dummy_id);
9455796c8dcSSimon Schubert
9465796c8dcSSimon Schubert /* We also need to restore inferior status to that before the
9475796c8dcSSimon Schubert dummy call. */
948c50c785cSJohn Marino restore_infcall_control_state (inf_status);
9495796c8dcSSimon Schubert
9505796c8dcSSimon Schubert /* FIXME: Insert a bunch of wrap_here; name can be very
9515796c8dcSSimon Schubert long if it's a C++ name with arguments and stuff. */
9525796c8dcSSimon Schubert error (_("\
9535796c8dcSSimon Schubert The program being debugged was signaled while in a function called from GDB.\n\
9545796c8dcSSimon Schubert GDB has restored the context to what it was before the call.\n\
9555796c8dcSSimon Schubert To change this behavior use \"set unwindonsignal off\".\n\
9565796c8dcSSimon Schubert Evaluation of the expression containing the function\n\
9575796c8dcSSimon Schubert (%s) will be abandoned."),
9585796c8dcSSimon Schubert name);
9595796c8dcSSimon Schubert }
9605796c8dcSSimon Schubert else
9615796c8dcSSimon Schubert {
9625796c8dcSSimon Schubert /* The user wants to stay in the frame where we stopped
9635796c8dcSSimon Schubert (default).
9645796c8dcSSimon Schubert Discard inferior status, we're not at the same point
9655796c8dcSSimon Schubert we started at. */
966c50c785cSJohn Marino discard_infcall_control_state (inf_status);
9675796c8dcSSimon Schubert
9685796c8dcSSimon Schubert /* FIXME: Insert a bunch of wrap_here; name can be very
9695796c8dcSSimon Schubert long if it's a C++ name with arguments and stuff. */
9705796c8dcSSimon Schubert error (_("\
9715796c8dcSSimon Schubert The program being debugged was signaled while in a function called from GDB.\n\
9725796c8dcSSimon Schubert GDB remains in the frame where the signal was received.\n\
9735796c8dcSSimon Schubert To change this behavior use \"set unwindonsignal on\".\n\
9745796c8dcSSimon Schubert Evaluation of the expression containing the function\n\
9755796c8dcSSimon Schubert (%s) will be abandoned.\n\
9765796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."),
9775796c8dcSSimon Schubert name);
9785796c8dcSSimon Schubert }
9795796c8dcSSimon Schubert }
9805796c8dcSSimon Schubert
981cf7f2e2dSJohn Marino if (stop_stack_dummy == STOP_STD_TERMINATE)
9825796c8dcSSimon Schubert {
983cf7f2e2dSJohn Marino /* We must get back to the frame we were before the dummy
984cf7f2e2dSJohn Marino call. */
9855796c8dcSSimon Schubert dummy_frame_pop (dummy_id);
9865796c8dcSSimon Schubert
987cf7f2e2dSJohn Marino /* We also need to restore inferior status to that before
988cf7f2e2dSJohn Marino the dummy call. */
989c50c785cSJohn Marino restore_infcall_control_state (inf_status);
9905796c8dcSSimon Schubert
9915796c8dcSSimon Schubert error (_("\
9925796c8dcSSimon Schubert The program being debugged entered a std::terminate call, most likely\n\
9935796c8dcSSimon Schubert caused by an unhandled C++ exception. GDB blocked this call in order\n\
9945796c8dcSSimon Schubert to prevent the program from being terminated, and has restored the\n\
9955796c8dcSSimon Schubert context to its original state before the call.\n\
9965796c8dcSSimon Schubert To change this behaviour use \"set unwind-on-terminating-exception off\".\n\
9975796c8dcSSimon Schubert Evaluation of the expression containing the function (%s)\n\
9985796c8dcSSimon Schubert will be abandoned."),
9995796c8dcSSimon Schubert name);
10005796c8dcSSimon Schubert }
1001cf7f2e2dSJohn Marino else if (stop_stack_dummy == STOP_NONE)
1002cf7f2e2dSJohn Marino {
1003cf7f2e2dSJohn Marino
10045796c8dcSSimon Schubert /* We hit a breakpoint inside the FUNCTION.
10055796c8dcSSimon Schubert Keep the dummy frame, the user may want to examine its state.
10065796c8dcSSimon Schubert Discard inferior status, we're not at the same point
10075796c8dcSSimon Schubert we started at. */
1008c50c785cSJohn Marino discard_infcall_control_state (inf_status);
10095796c8dcSSimon Schubert
10105796c8dcSSimon Schubert /* The following error message used to say "The expression
10115796c8dcSSimon Schubert which contained the function call has been discarded."
10125796c8dcSSimon Schubert It is a hard concept to explain in a few words. Ideally,
10135796c8dcSSimon Schubert GDB would be able to resume evaluation of the expression
10145796c8dcSSimon Schubert when the function finally is done executing. Perhaps
10155796c8dcSSimon Schubert someday this will be implemented (it would not be easy). */
10165796c8dcSSimon Schubert /* FIXME: Insert a bunch of wrap_here; name can be very long if it's
10175796c8dcSSimon Schubert a C++ name with arguments and stuff. */
10185796c8dcSSimon Schubert error (_("\
10195796c8dcSSimon Schubert The program being debugged stopped while in a function called from GDB.\n\
10205796c8dcSSimon Schubert Evaluation of the expression containing the function\n\
10215796c8dcSSimon Schubert (%s) will be abandoned.\n\
10225796c8dcSSimon Schubert When the function is done executing, GDB will silently stop."),
10235796c8dcSSimon Schubert name);
10245796c8dcSSimon Schubert }
10255796c8dcSSimon Schubert
10265796c8dcSSimon Schubert /* The above code errors out, so ... */
10275796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("... should not be here"));
10285796c8dcSSimon Schubert }
10295796c8dcSSimon Schubert
1030cf7f2e2dSJohn Marino do_cleanups (terminate_bp_cleanup);
1031cf7f2e2dSJohn Marino
10325796c8dcSSimon Schubert /* If we get here the called FUNCTION ran to completion,
10335796c8dcSSimon Schubert and the dummy frame has already been popped. */
10345796c8dcSSimon Schubert
10355796c8dcSSimon Schubert {
1036cf7f2e2dSJohn Marino struct address_space *aspace = get_regcache_aspace (stop_registers);
1037cf7f2e2dSJohn Marino struct regcache *retbuf = regcache_xmalloc (gdbarch, aspace);
10385796c8dcSSimon Schubert struct cleanup *retbuf_cleanup = make_cleanup_regcache_xfree (retbuf);
10395796c8dcSSimon Schubert struct value *retval = NULL;
10405796c8dcSSimon Schubert
10415796c8dcSSimon Schubert regcache_cpy_no_passthrough (retbuf, stop_registers);
10425796c8dcSSimon Schubert
10435796c8dcSSimon Schubert /* Inferior call is successful. Restore the inferior status.
10445796c8dcSSimon Schubert At this stage, leave the RETBUF alone. */
1045c50c785cSJohn Marino restore_infcall_control_state (inf_status);
10465796c8dcSSimon Schubert
10475796c8dcSSimon Schubert /* Figure out the value returned by the function. */
1048c50c785cSJohn Marino retval = allocate_value (values_type);
10495796c8dcSSimon Schubert
1050*ef5ccd6cSJohn Marino if (hidden_first_param_p)
1051c50c785cSJohn Marino read_value_memory (retval, 0, 1, struct_addr,
1052c50c785cSJohn Marino value_contents_raw (retval),
1053c50c785cSJohn Marino TYPE_LENGTH (values_type));
1054c50c785cSJohn Marino else if (TYPE_CODE (target_values_type) != TYPE_CODE_VOID)
10555796c8dcSSimon Schubert {
10565796c8dcSSimon Schubert /* If the function returns void, don't bother fetching the
10575796c8dcSSimon Schubert return value. */
1058*ef5ccd6cSJohn Marino switch (gdbarch_return_value (gdbarch, function, target_values_type,
1059*ef5ccd6cSJohn Marino NULL, NULL, NULL))
10605796c8dcSSimon Schubert {
10615796c8dcSSimon Schubert case RETURN_VALUE_REGISTER_CONVENTION:
10625796c8dcSSimon Schubert case RETURN_VALUE_ABI_RETURNS_ADDRESS:
10635796c8dcSSimon Schubert case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1064*ef5ccd6cSJohn Marino gdbarch_return_value (gdbarch, function, values_type,
10655796c8dcSSimon Schubert retbuf, value_contents_raw (retval), NULL);
10665796c8dcSSimon Schubert break;
10675796c8dcSSimon Schubert case RETURN_VALUE_STRUCT_CONVENTION:
1068c50c785cSJohn Marino read_value_memory (retval, 0, 1, struct_addr,
1069c50c785cSJohn Marino value_contents_raw (retval),
1070c50c785cSJohn Marino TYPE_LENGTH (values_type));
10715796c8dcSSimon Schubert break;
10725796c8dcSSimon Schubert }
10735796c8dcSSimon Schubert }
10745796c8dcSSimon Schubert
10755796c8dcSSimon Schubert do_cleanups (retbuf_cleanup);
10765796c8dcSSimon Schubert
10775796c8dcSSimon Schubert gdb_assert (retval);
10785796c8dcSSimon Schubert return retval;
10795796c8dcSSimon Schubert }
10805796c8dcSSimon Schubert }
10815796c8dcSSimon Schubert
10825796c8dcSSimon Schubert
10835796c8dcSSimon Schubert /* Provide a prototype to silence -Wmissing-prototypes. */
10845796c8dcSSimon Schubert void _initialize_infcall (void);
10855796c8dcSSimon Schubert
10865796c8dcSSimon Schubert void
_initialize_infcall(void)10875796c8dcSSimon Schubert _initialize_infcall (void)
10885796c8dcSSimon Schubert {
10895796c8dcSSimon Schubert add_setshow_boolean_cmd ("coerce-float-to-double", class_obscure,
10905796c8dcSSimon Schubert &coerce_float_to_double_p, _("\
10915796c8dcSSimon Schubert Set coercion of floats to doubles when calling functions."), _("\
10925796c8dcSSimon Schubert Show coercion of floats to doubles when calling functions"), _("\
10935796c8dcSSimon Schubert Variables of type float should generally be converted to doubles before\n\
10945796c8dcSSimon Schubert calling an unprototyped function, and left alone when calling a prototyped\n\
10955796c8dcSSimon Schubert function. However, some older debug info formats do not provide enough\n\
10965796c8dcSSimon Schubert information to determine that a function is prototyped. If this flag is\n\
10975796c8dcSSimon Schubert set, GDB will perform the conversion for a function it considers\n\
10985796c8dcSSimon Schubert unprototyped.\n\
10995796c8dcSSimon Schubert The default is to perform the conversion.\n"),
11005796c8dcSSimon Schubert NULL,
11015796c8dcSSimon Schubert show_coerce_float_to_double_p,
11025796c8dcSSimon Schubert &setlist, &showlist);
11035796c8dcSSimon Schubert
11045796c8dcSSimon Schubert add_setshow_boolean_cmd ("unwindonsignal", no_class,
11055796c8dcSSimon Schubert &unwind_on_signal_p, _("\
11065796c8dcSSimon Schubert Set unwinding of stack if a signal is received while in a call dummy."), _("\
11075796c8dcSSimon Schubert Show unwinding of stack if a signal is received while in a call dummy."), _("\
11085796c8dcSSimon Schubert The unwindonsignal lets the user determine what gdb should do if a signal\n\
11095796c8dcSSimon Schubert is received while in a function called from gdb (call dummy). If set, gdb\n\
11105796c8dcSSimon Schubert unwinds the stack and restore the context to what as it was before the call.\n\
11115796c8dcSSimon Schubert The default is to stop in the frame where the signal was received."),
11125796c8dcSSimon Schubert NULL,
11135796c8dcSSimon Schubert show_unwind_on_signal_p,
11145796c8dcSSimon Schubert &setlist, &showlist);
11155796c8dcSSimon Schubert
11165796c8dcSSimon Schubert add_setshow_boolean_cmd ("unwind-on-terminating-exception", no_class,
11175796c8dcSSimon Schubert &unwind_on_terminating_exception_p, _("\
11185796c8dcSSimon Schubert Set unwinding of stack if std::terminate is called while in call dummy."), _("\
1119c50c785cSJohn Marino Show unwinding of stack if std::terminate() is called while in a call dummy."),
1120c50c785cSJohn Marino _("\
11215796c8dcSSimon Schubert The unwind on terminating exception flag lets the user determine\n\
11225796c8dcSSimon Schubert what gdb should do if a std::terminate() call is made from the\n\
11235796c8dcSSimon Schubert default exception handler. If set, gdb unwinds the stack and restores\n\
11245796c8dcSSimon Schubert the context to what it was before the call. If unset, gdb allows the\n\
11255796c8dcSSimon Schubert std::terminate call to proceed.\n\
11265796c8dcSSimon Schubert The default is to unwind the frame."),
11275796c8dcSSimon Schubert NULL,
11285796c8dcSSimon Schubert show_unwind_on_terminating_exception_p,
11295796c8dcSSimon Schubert &setlist, &showlist);
11305796c8dcSSimon Schubert
11315796c8dcSSimon Schubert }
1132