44#include "gdbsupport/scope-exit.h"
53#define infcall_debug_printf(fmt, ...) \
54 debug_prefixed_printf_cond (debug_infcall, "infcall", fmt, ##__VA_ARGS__)
58#define INFCALL_SCOPED_DEBUG_ENTER_EXIT \
59 scoped_debug_enter_exit (debug_infcall, "infcall")
63#define INFCALL_SCOPED_DEBUG_START_END(fmt, ...) \
64 scoped_debug_start_end (debug_infrun, "infcall", fmt, ##__VA_ARGS__)
77#define RAW_FUNCTION_ADDRESS_FORMAT "at 0x%s"
78#define RAW_FUNCTION_ADDRESS_SIZE (sizeof (RAW_FUNCTION_ADDRESS_FORMAT) \
79 + 2 * sizeof (CORE_ADDR))
94 _(
"Permission to call functions in the program is %s.\n"),
124 _(
"Coercion of floats to doubles "
125 "when calling functions is %s.\n"),
142 _(
"Unwinding of stack if a signal is "
143 "received while in a call dummy is %s.\n"),
168 _(
"Unwind stack if a C++ exception is "
169 "unhandled while in a call dummy is %s.\n"),
181 struct type *param_type,
int is_prototyped)
203 case TYPE_CODE_RVALUE_REF:
205 struct value *new_value;
246 case TYPE_CODE_ARRAY:
256 case TYPE_CODE_STRUCT:
257 case TYPE_CODE_UNION:
260 case TYPE_CODE_RANGE:
261 case TYPE_CODE_STRING:
262 case TYPE_CODE_ERROR:
263 case TYPE_CODE_MEMBERPTR:
264 case TYPE_CODE_METHODPTR:
265 case TYPE_CODE_METHOD:
266 case TYPE_CODE_COMPLEX:
278 struct type **retval_type,
279 struct type **function_type)
285 CORE_ADDR funaddr = 0;
291 if (ftype->
code () == TYPE_CODE_FUNC
292 || ftype->
code () == TYPE_CODE_METHOD)
294 else if (ftype->
code () == TYPE_CODE_PTR)
298 if (ftype->
code () == TYPE_CODE_FUNC
299 || ftype->
code () == TYPE_CODE_METHOD)
303 if (ftype->
code () == TYPE_CODE_FUNC
304 || ftype->
code () == TYPE_CODE_METHOD)
308 CORE_ADDR resolver_addr = funaddr;
316 if (retval_type != NULL || function_type != NULL)
322 if (target_ftype == NULL)
324 if (target_ftype != NULL)
327 ftype = target_ftype;
334 else if (ftype->
code () == TYPE_CODE_INT)
338 if (ftype->
length () == 1)
343 int found_descriptor = 0;
354 if (funaddr != nfunaddr)
355 found_descriptor = 1;
357 if (!found_descriptor)
363 error (_(
"Invalid data type for function to be called."));
365 if (retval_type != NULL)
367 if (function_type != NULL)
368 *function_type = ftype;
377 CORE_ADDR sp, CORE_ADDR funaddr,
378 gdb::array_view<value *> args,
380 CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
386 args.data (), args.size (),
396 if (func_name != NULL)
397 error (_(
"'%s' has unknown return type; "
398 "cast the call to its declared return type"),
401 error (_(
"function has unknown return type; "
402 "cast the call to its declared return type"));
431 hex_string (funaddr));
433 gdb_assert (tmp.length () + 1 <= buf_size);
434 return strcpy (buf, tmp.c_str ());
464 struct value *retval = NULL;
472 if (stack_temporaries)
506 gdb_assert (retval != NULL);
530 int struct_return_p, CORE_ADDR struct_addr);
540 struct interp *cmd_interp,
542 struct value *function,
544 int struct_return_p, CORE_ADDR struct_addr)
546 waiting_ui (waiting_ui)
606static struct gdb_exception
608 struct
thread_info *call_thread, CORE_ADDR real_pc)
612 struct gdb_exception caught_error;
613 ptid_t call_thread_ptid = call_thread->ptid;
617 core_addr_to_string (real_pc),
618 call_thread_ptid.to_string ().c_str (),
623 scoped_restore restore_in_infcall
624 = make_scoped_restore (&call_thread->control.in_infcall, 1);
630 call_thread->set_thread_fsm (std::move (sm));
635 call_thread->control.proceed_to_finish = 1;
640 scoped_restore restore_prompt_state
645 scoped_restore restore_ui_async
648 proceed (real_pc, GDB_SIGNAL_0);
659 catch (gdb_exception &e)
662 e.reason, e.what ());
663 caught_error = std::move (e);
706 if (caught_error.reason < 0)
731 sp -= values_type->
length ();
743 sp += values_type->
length ();
769 struct type *default_return_type)
771 for (
auto vals : dtors_to_invoke)
774 gdb::make_array_view (&(vals.self), 1));
782 type *default_return_type,
783 gdb::array_view<value *> args)
809 type *default_return_type,
810 gdb::array_view<value *> args,
812 void *dummy_dtor_data)
817 struct type *target_values_type;
819 CORE_ADDR struct_addr = 0;
825 ptid_t call_thread_ptid;
826 struct gdb_exception e;
830 error (_(
"Cannot call functions in the program: "
831 "may-call-functions is off."));
837 error (_(
"May not call functions while looking at trace frames."));
840 error (_(
"Cannot call functions in reverse mode."));
851 frame.prepare_reinflate ();
855 error (_(
"This target does not support function calls."));
863 error (_(
"Cannot call the function '%s' which does not follow the "
864 "target calling convention."),
869 if (values_type == NULL || values_type->
is_stub ())
870 values_type = default_return_type;
871 if (values_type == NULL)
874 name_buf,
sizeof (name_buf));
875 error (_(
"'%s' has unknown return type; "
876 "cast the call to its declared return type"),
883 error (_(
"Too few arguments in function call."));
967 if (stack_temporaries)
969 struct value *lastval;
978 gdb_assert (sp >= lastval_addr);
983 gdb_assert (sp <= lastval_addr);
1007 target_values_type = values_type;
1022 const gdb_byte *bp_bytes;
1023 CORE_ADDR bp_addr_as_address;
1030 target_values_type, &real_pc, &bp_addr,
1044 bp_addr_as_address = bp_addr;
1047 if (bp_bytes != NULL)
1053 CORE_ADDR dummy_addr;
1063 bp_addr = dummy_addr;
1067 internal_error (_(
"bad switch"));
1074 std::list<destructor_info> dtors_to_invoke;
1076 for (
int i = args.size () - 1; i >= 0; i--)
1079 struct type *param_type;
1083 if (ftype->
code () == TYPE_CODE_METHOD)
1086 && default_return_type != NULL)
1110 value *original_arg = args[i];
1112 param_type, prototyped);
1114 if (param_type == NULL)
1118 if (!info.copy_constructible)
1119 error (_(
"expression cannot be evaluated because the type '%s' "
1120 "is not copy constructible"), param_type->
name ());
1122 if (!info.destructible)
1123 error (_(
"expression cannot be evaluated because the type '%s' "
1124 "is not destructible"), param_type->
name ());
1126 if (info.trivially_copyable)
1139 if (info.trivially_copy_constructible)
1147 value *cctor_args[2] = { clone_ptr, original_arg };
1150 &clone_ptr,
nullptr, ©_ctor,
nullptr,
1153 if (copy_ctor ==
nullptr)
1154 error (_(
"expression cannot be evaluated because a copy "
1155 "constructor for the type '%s' could not be found "
1156 "(maybe inlined?)"), param_type->
name ());
1159 gdb::make_array_view (cctor_args, 2));
1164 if (!info.trivially_destructible)
1171 const char *dtor_name =
nullptr;
1172 for (
int fieldnum = 0;
1185 if (dtor_name ==
nullptr)
1186 error (_(
"expression cannot be evaluated because a destructor "
1187 "for the type '%s' could not be found "
1188 "(maybe inlined?)"), param_type->
name ());
1195 dtors_to_invoke.emplace_front (dtor, clone_ptr);
1198 args[i] = clone_ptr;
1219 std::vector<struct value *> new_args;
1223 new_args.reserve (args.size ());
1226 new_args.insert (new_args.end (), args.begin (), args.end ());
1234 bp_addr, args.size (), args.data (),
1235 sp, return_method, struct_addr);
1298 if (dummy_dtor != NULL)
1300 dummy_dtor, dummy_dtor_data);
1311 std::unique_ptr<thread_fsm> saved_sm = call_thread->release_thread_fsm ();
1316 call_thread_ptid = call_thread->ptid;
1330 std::unique_ptr<call_thread_fsm> sm_up (sm);
1336 e.reason, e.what ());
1345 gdb_assert (call_thread->thread_fsm () == sm);
1347 if (call_thread->thread_fsm ()->finished_p ())
1349 struct value *retval;
1367 std::unique_ptr<thread_fsm> finalizing
1368 = call_thread->release_thread_fsm ();
1369 call_thread->set_thread_fsm (std::move (saved_sm));
1371 finalizing->clean_up (call_thread.get ());
1376 gdb_assert (retval != NULL);
1389 std::unique_ptr<thread_fsm> finalizing
1390 = call_thread->release_thread_fsm ();
1391 call_thread->set_thread_fsm (std::move (saved_sm));
1393 finalizing->clean_up (call_thread.get ());
1403 name_buf,
sizeof (name_buf));
1414 throw_error (e.error, _(
"%s\n\
1415An error occurred while in a function called from GDB.\n\
1416Evaluation of the expression containing the function\n\
1417(%s) will be abandoned.\n\
1418When the function is done executing, GDB will silently stop."),
1422 throw_exception (std::move (e));
1432 name_buf,
sizeof (name_buf));
1442 error (_(
"The program being debugged exited while in a function "
1443 "called from GDB.\n"
1444 "Evaluation of the expression containing the function\n"
1445 "(%s) will be abandoned."),
1452 name_buf,
sizeof (name_buf));
1463The program received a signal in another thread while\n\
1464making a function call from GDB.\n\
1465Evaluation of the expression containing the function\n\
1466(%s) will be abandoned.\n\
1467When the function is done executing, GDB will silently stop."),
1471The program stopped in another thread while making a function call from GDB.\n\
1472Evaluation of the expression containing the function\n\
1473(%s) will be abandoned.\n\
1474When the function is done executing, GDB will silently stop."),
1504The program being debugged was signaled while in a function called from GDB.\n\
1505GDB has restored the context to what it was before the call.\n\
1506To change this behavior use \"set unwindonsignal off\".\n\
1507Evaluation of the expression containing the function\n\
1508(%s) will be abandoned."),
1522The program being debugged was signaled while in a function called from GDB.\n\
1523GDB remains in the frame where the signal was received.\n\
1524To change this behavior use \"set unwindonsignal on\".\n\
1525Evaluation of the expression containing the function\n\
1526(%s) will be abandoned.\n\
1527When the function is done executing, GDB will silently stop."),
1543The program being debugged entered a std::terminate call, most likely\n\
1544caused by an unhandled C++ exception. GDB blocked this call in order\n\
1545to prevent the program from being terminated, and has restored the\n\
1546context to its original state before the call.\n\
1547To change this behaviour use \"set unwind-on-terminating-exception off\".\n\
1548Evaluation of the expression containing the function (%s)\n\
1549will be abandoned."),
1570The program being debugged stopped while in a function called from GDB.\n\
1571Evaluation of the expression containing the function\n\
1572(%s) will be abandoned.\n\
1573When the function is done executing, GDB will silently stop."),
1580 gdb_assert_not_reached (
"... should not be here");
1589Set permission to call functions in the program."), _(
"\
1590Show permission to call functions in the program."), _(
"\
1591When this permission is on, GDB may call functions in the program.\n\
1592Otherwise, any sort of attempt to call a function in the program\n\
1593will result in an error."),
1600Set coercion of floats to doubles when calling functions."), _(
"\
1601Show coercion of floats to doubles when calling functions."), _(
"\
1602Variables of type float should generally be converted to doubles before\n\
1603calling an unprototyped function, and left alone when calling a prototyped\n\
1604function. However, some older debug info formats do not provide enough\n\
1605information to determine that a function is prototyped. If this flag is\n\
1606set, GDB will perform the conversion for a function it considers\n\
1608The default is to perform the conversion."),
1615Set unwinding of stack if a signal is received while in a call dummy."), _(
"\
1616Show unwinding of stack if a signal is received while in a call dummy."), _(
"\
1617The unwindonsignal lets the user determine what gdb should do if a signal\n\
1618is received while in a function called from gdb (call dummy). If set, gdb\n\
1619unwinds the stack and restore the context to what as it was before the call.\n\
1620The default is to stop in the frame where the signal was received."),
1627Set unwinding of stack if std::terminate is called while in call dummy."), _(
"\
1628Show unwinding of stack if std::terminate() is called while in a call dummy."),
1630The unwind on terminating exception flag lets the user determine\n\
1631what gdb should do if a std::terminate() call is made from the\n\
1632default exception handler. If set, gdb unwinds the stack and restores\n\
1633the context to what it was before the call. If unset, gdb allows the\n\
1634std::terminate call to proceed.\n\
1635The default is to unwind the frame."),
1642 _(
"Set inferior call debugging."),
1643 _(
"Show inferior call debugging."),
1644 _(
"When on, inferior function call specific debugging is enabled."),
struct value * ada_convert_actual(struct value *actual, struct type *formal_type0)
struct symbol * find_pc_function(CORE_ADDR pc)
struct type * find_function_type(CORE_ADDR pc)
struct type * find_gnu_ifunc_target_type(CORE_ADDR resolver_funaddr)
void set_std_terminate_breakpoint(void)
void breakpoint_auto_delete(bpstat *bs)
void delete_std_terminate_breakpoint(void)
void enable_watchpoints_after_interactive_call_stop(void)
struct breakpoint * set_longjmp_breakpoint_for_call_dummy(void)
void disable_watchpoints_before_interactive_call_start(void)
breakpoint_up set_momentary_breakpoint(struct gdbarch *gdbarch, struct symtab_and_line sal, struct frame_id frame_id, enum bptype type)
struct cmd_list_element * showlist
struct cmd_list_element * setlist
struct cmd_list_element * showdebuglist
struct cmd_list_element * setdebuglist
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void write_memory(CORE_ADDR memaddr, const bfd_byte *myaddr, ssize_t len)
void register_dummy_frame_dtor(frame_id dummy_id, thread_info *thread, dummy_frame_dtor_ftype *dtor, void *dtor_data)
void dummy_frame_pop(frame_id dummy_id, thread_info *thread)
void dummy_frame_push(struct infcall_suspend_state *caller_state, const frame_id *dummy_id, thread_info *thread)
void() dummy_frame_dtor_ftype(void *data, int registers_valid)
struct type * fortran_preserve_arg_pointer(struct value *arg, struct type *type)
CORE_ADDR get_frame_sp(frame_info_ptr this_frame)
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
frame_info_ptr get_current_frame(void)
enum call_dummy_location_type gdbarch_call_dummy_location(struct gdbarch *gdbarch)
enum return_value_convention gdbarch_return_value(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
const gdb_byte * gdbarch_breakpoint_from_pc(struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
CORE_ADDR gdbarch_push_dummy_call(struct gdbarch *gdbarch, struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, function_call_return_method return_method, CORE_ADDR struct_addr)
CORE_ADDR gdbarch_frame_align(struct gdbarch *gdbarch, CORE_ADDR address)
int gdbarch_return_in_first_hidden_param_p(struct gdbarch *gdbarch, struct type *type)
CORE_ADDR gdbarch_deprecated_function_start_offset(struct gdbarch *gdbarch)
CORE_ADDR gdbarch_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)
bool gdbarch_push_dummy_call_p(struct gdbarch *gdbarch)
int gdbarch_frame_red_zone_size(struct gdbarch *gdbarch)
bool gdbarch_push_dummy_code_p(struct gdbarch *gdbarch)
int gdbarch_inner_than(struct gdbarch *gdbarch, CORE_ADDR lhs, CORE_ADDR rhs)
CORE_ADDR gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
bool gdbarch_frame_align_p(struct gdbarch *gdbarch)
function_call_return_method
@ return_method_hidden_param
const char * thread_state_string(enum thread_state state)
all_non_exited_threads_range all_non_exited_threads(process_stratum_target *proc_target=nullptr, ptid_t filter_ptid=minus_one_ptid)
void finish_thread_state(process_stratum_target *targ, ptid_t ptid)
struct thread_info * inferior_thread(void)
value * get_last_thread_stack_temporary(struct thread_info *tp)
void push_thread_stack_temporary(struct thread_info *tp, struct value *v)
bool thread_stack_temporaries_enabled_p(struct thread_info *tp)
gdb::ref_ptr< struct thread_info, refcounted_object_ref_policy > thread_info_ref
struct type * lookup_pointer_type(struct type *type)
int class_or_union_p(const struct type *t)
bool is_nocall_function(const struct type *type)
struct type * check_typedef(struct type *type)
#define TYPE_FN_FIELD_PHYSNAME(thisfn, n)
#define TYPE_NFN_FIELDS(thistype)
#define TYPE_IS_REFERENCE(t)
#define TYPE_FN_FIELDLIST1(thistype, n)
#define TYPE_FN_FIELDLIST_NAME(thistype, n)
static struct value * get_call_return_value(struct call_return_meta_info *ri)
static void show_may_call_functions_p(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static bool unwind_on_terminating_exception_p
struct value * call_function_by_hand_dummy(struct value *function, type *default_return_type, gdb::array_view< value * > args, dummy_frame_dtor_ftype *dummy_dtor, void *dummy_dtor_data)
CORE_ADDR find_function_addr(struct value *function, struct type **retval_type, struct type **function_type)
static bool coerce_float_to_double_p
#define infcall_debug_printf(fmt,...)
static struct gdb_exception run_inferior_call(std::unique_ptr< call_thread_fsm > sm, struct thread_info *call_thread, CORE_ADDR real_pc)
static void show_unwind_on_terminating_exception_p(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static CORE_ADDR push_dummy_code(struct gdbarch *gdbarch, CORE_ADDR sp, CORE_ADDR funaddr, gdb::array_view< value * > args, struct type *value_type, CORE_ADDR *real_pc, CORE_ADDR *bp_addr, struct regcache *regcache)
void _initialize_infcall()
static bool may_call_functions_p
void error_call_unknown_return_type(const char *func_name)
static bool debug_infcall
#define RAW_FUNCTION_ADDRESS_FORMAT
static struct value * value_arg_coerce(struct gdbarch *gdbarch, struct value *arg, struct type *param_type, int is_prototyped)
static CORE_ADDR reserve_stack_space(const type *values_type, CORE_ADDR &sp)
static void show_unwind_on_signal_p(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static bool unwind_on_signal_p
struct value * call_function_by_hand(struct value *function, type *default_return_type, gdb::array_view< value * > args)
static void show_debug_infcall(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
#define INFCALL_SCOPED_DEBUG_ENTER_EXIT
static void call_destructors(const std::list< destructor_info > &dtors_to_invoke, struct type *default_return_type)
#define RAW_FUNCTION_ADDRESS_SIZE
static void show_coerce_float_to_double_p(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static const char * get_function_name(CORE_ADDR funaddr, char *buf, int buf_size)
int stopped_by_random_signal
enum stop_stack_kind stop_stack_dummy
struct inferior * current_inferior(void)
void restore_infcall_control_state(struct infcall_control_state *)
std::unique_ptr< infcall_control_state, infcall_control_state_deleter > infcall_control_state_up
infcall_suspend_state_up save_infcall_suspend_state()
void discard_infcall_control_state(struct infcall_control_state *)
infcall_control_state_up save_infcall_control_state()
std::unique_ptr< infcall_suspend_state, infcall_suspend_state_deleter > infcall_suspend_state_up
void maybe_remove_breakpoints(void)
void clear_proceed_status(int step)
enum exec_direction_kind execution_direction
void proceed(CORE_ADDR addr, enum gdb_signal siggnal)
ptid_t user_visible_resume_ptid(int step)
static void infrun_debug_show_threads(const char *title, ThreadRange threads)
struct interp * command_interp(void)
const struct language_defn * current_language
struct language_pass_by_ref_info language_pass_by_reference(struct type *type)
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR pc)
observable< ptid_t, CORE_ADDR > inferior_call_pre
observable< ptid_t, CORE_ADDR > inferior_call_post
CORE_ADDR entry_point_address(void)
struct program_space * current_program_space
static gdbpy_ref field_name(struct type *type, int field)
struct regcache * get_current_regcache(void)
struct minimal_symbol * minsym
breakpoint * related_breakpoint
struct type * builtin_double
struct type * builtin_long_double
struct type * builtin_int
struct type * builtin_void
struct value * return_value
bool should_stop(struct thread_info *thread) override
call_thread_fsm(struct ui *waiting_ui, struct interp *cmd_interp, struct gdbarch *gdbarch, struct value *function, struct type *value_type, int struct_return_p, CORE_ADDR struct_addr)
struct call_return_meta_info return_meta_info
bool should_notify_stop() override
destructor_info(struct value *function, struct value *self)
struct type * type() const
const char * print_name() const
enum language la_language
virtual bool c_style_arrays_p() const
struct obj_section * section
struct program_space * pspace
struct type * target_type() const
struct field & field(int idx) const
bool is_gnu_ifunc() const
const char * name() const
bool is_prototyped() const
enum prompt_state prompt_state
void unregister_file_handler()
void register_file_handler()
struct obj_section * find_pc_overlay(CORE_ADDR pc)
#define gnu_ifunc_resolve_addr
bool target_has_execution(inferior *inf)
void wait_sync_command_done(void)
int get_traceframe_number(void)
void gdb_printf(struct ui_file *stream, const char *format,...)
struct value * value_coerce_to_target(struct value *val)
struct value * value_cast_pointers(struct type *type, struct value *arg2, int subclass_check)
struct value * value_addr(struct value *arg1)
struct value * find_function_in_inferior(const char *name, struct objfile **objf_p)
struct value * value_cast(struct type *type, struct value *arg2)
struct value * value_ref(struct value *arg1, enum type_code refcode)
void read_value_memory(struct value *val, LONGEST bit_offset, int stack, CORE_ADDR memaddr, gdb_byte *buffer, size_t length)
int find_overload_match(gdb::array_view< value * > args, const char *name, enum oload_search_type method, struct value **objp, struct symbol *fsym, struct value **valp, struct symbol **symp, int *staticp, const int no_adl, const enum noside noside)
struct type * value_type(const struct value *value)
struct value * allocate_value(struct type *type)
CORE_ADDR value_as_address(struct value *val)
CORE_ADDR value_address(const struct value *value)
gdb::array_view< gdb_byte > value_contents_raw(struct value *value)
gdb::array_view< const gdb_byte > value_contents(struct value *value)
LONGEST value_as_long(struct value *val)
struct value * value_from_pointer(struct type *type, CORE_ADDR addr)
struct value * value_from_contents_and_address(struct type *type, const gdb_byte *valaddr, CORE_ADDR address)
int using_struct_return(struct gdbarch *gdbarch, struct value *function, struct type *value_type)
void value_force_lval(struct value *v, CORE_ADDR addr)