32#include "gdbsupport/environ.h"
37#include "readline/tilde.h"
39#include "gdbsupport/buildargv.h"
63 gdb_assert (
inf != NULL);
124 internal_error (
"pop_all_targets couldn't find target %s\n",
228 thr->
ptid.to_string ().c_str (), silent);
239 inf->clear_thread_list (
true);
250 inf->pop_all_targets ();
253 if (
inf->pspace->empty ())
265 inf->clear_thread_list (silent);
270 inf->fake_pid_p =
false;
273 if (
inf->vfork_parent != NULL)
275 inf->vfork_parent->vfork_child = NULL;
276 inf->vfork_parent = NULL;
278 if (
inf->vfork_child != NULL)
280 inf->vfork_child->vfork_parent = NULL;
281 inf->vfork_child = NULL;
284 inf->pending_detach =
false;
316 gdb_printf (_(
"[Inferior %d (%s) detached]\n"),
331 inf->has_exit_code =
false;
353 gdb_assert (
pid != 0);
406 if (
inf->has_execution ())
407 for (
thread_info *tp ATTRIBUTE_UNUSED :
inf->non_exited_threads ())
434 if (!
inf->deletable ()
449 return std::distance (rng.begin (), rng.end ());
470 const char *filename =
inf->pspace->exec_filename.get ();
472 if (filename == NULL)
473 filename = _(
"<noexec>");
475 uiout->
message (_(
"[Switching to inferior %d [%s] (%s)]\n"),
485 if (proc_target == NULL)
506 size_t connection_id_len = 20;
515 if (connection_id_len < conn.size ())
516 connection_id_len = conn.size ();
523 uiout->
message (
"No inferiors.\n");
532 "connection-id",
"Connection");
548 if (
inf == current_inf)
564 if (
inf->pspace->exec_filename !=
nullptr)
573 if (
inf->vfork_parent)
575 uiout->
text (_(
"\n\tis vfork child of inferior "));
578 if (
inf->vfork_child)
580 uiout->
text (_(
"\n\tis vfork parent of inferior "));
592 error (_(
"Requires argument (inferior id(s) to detach)"));
604 warning (_(
"Inferior ID %d not known."),
num);
610 warning (_(
"Inferior ID %d is not running."),
num);
617 warning (_(
"Inferior ID %d has no threads."),
num);
631 error (_(
"Requires argument (inferior id(s) to kill)"));
643 warning (_(
"Inferior ID %d not known."),
num);
649 warning (_(
"Inferior ID %d is not running."),
num);
656 warning (_(
"Inferior ID %d has no threads."),
num);
665 bfd_cache_close_all ();
687 gdb_assert (
inf !=
nullptr);
688 const char *filename =
inf->pspace->exec_filename.get ();
690 if (filename ==
nullptr)
691 filename = _(
"<noexec>");
693 gdb_printf (_(
"[Current inferior is %d [%s] (%s)]\n"),
703 error (_(
"Inferior ID %d not known."),
num);
711 error (_(
"Inferior has no threads."));
745 error (_(
"Requires an argument (inferior id(s) to remove)"));
755 warning (_(
"Inferior ID %d not known."),
num);
759 if (!
inf->deletable ())
761 warning (_(
"Can not remove current inferior %d."),
num);
767 warning (_(
"Can not remove active inferior %d."),
num);
797 gdb_assert (
inf->gdbarch != NULL);
806 bool no_connection,
inferior *org_inf)
815 if (!no_connection && proc_target != NULL)
818 gdb_printf (_(
"Added inferior %d on connection %d (%s)\n"),
833 gdb::unique_xmalloc_ptr<char> exec;
834 symfile_add_flags add_flags = 0;
835 bool no_connection =
false;
842 gdb_argv built_argv (
args);
844 for (
char **argv = built_argv.get (); *argv != NULL; argv++)
848 if (strcmp (*argv,
"-copies") == 0)
852 error (_(
"No argument to -copies"));
855 else if (strcmp (*argv,
"-no-connection") == 0)
856 no_connection =
true;
857 else if (strcmp (*argv,
"-exec") == 0)
861 error (_(
"No argument to -exec"));
862 exec.reset (tilde_expand (*argv));
866 error (_(
"Invalid argument"));
874 for (i = 0; i < copies; ++i)
895 bool no_connection =
false;
899 gdb_argv built_argv (
args);
901 char **argv = built_argv.get ();
902 for (; *argv != NULL; argv++)
906 if (strcmp (*argv,
"-copies") == 0)
910 error (_(
"No argument to -copies"));
914 error (_(
"Invalid copies number"));
916 else if (strcmp (*argv,
"-no-connection") == 0)
917 no_connection =
true;
931 error (_(
"Inferior ID %d not known."),
num);
935 error (_(
"Invalid argument"));
947 for (i = 0; i < copies; ++i)
973 inf->set_args (orginf->
args ());
974 inf->set_cwd (orginf->
cwd ());
975 inf->set_tty (orginf->
tty ());
976 for (
const std::string &set_var : orginf->
environment.user_set_env ())
979 const std::string::size_type pos = set_var.find (
'=');
980 gdb_assert (pos != std::string::npos);
981 const std::string varname = set_var.substr (0, pos);
983 (varname.c_str (), orginf->
environment.get (varname.c_str ()));
985 for (
const std::string &unset_var
987 inf->environment.unset (unset_var.c_str ());
1001static struct value *
1038 _(
"Print a list of inferiors being managed.\n\
1039Usage: info inferiors [ID]...\n\
1040If IDs are specified, the list is limited to just those inferiors.\n\
1041By default all inferiors are displayed."));
1044Add a new inferior.\n\
1045Usage: add-inferior [-copies N] [-exec FILENAME] [-no-connection]\n\
1046N is the optional number of inferiors to add, default is 1.\n\
1047FILENAME is the file name of the executable to use\n\
1049By default, the new inferior inherits the current inferior's connection.\n\
1050If -no-connection is specified, the new inferior begins with\n\
1051no target connection yet."));
1055Remove inferior ID (or list of IDs).\n\
1056Usage: remove-inferiors ID..."));
1059Clone inferior ID.\n\
1060Usage: clone-inferior [-copies N] [-no-connection] [ID]\n\
1061Add N copies of inferior ID. The new inferiors have the same\n\
1062executable loaded as the copied inferior. If -copies is not specified,\n\
1063adds 1 copy. If ID is not specified, it is the current inferior\n\
1065By default, the new inferiors inherit the copied inferior's connection.\n\
1066If -no-connection is specified, the new inferiors begin with\n\
1067no target connection yet."));
1070Detach from inferior ID (or list of IDS).\n\
1071Usage; detach inferiors ID..."),
1075Kill inferior ID (or list of IDs).\n\
1076Usage: kill inferiors ID..."),
1080Use this command to switch between inferiors.\n\
1081Usage: inferior ID\n\
1082The new inferior ID must be currently known."),
1087Set printing of inferior events (such as inferior start and exit)."), _(
"\
1088Show printing of inferior events (such as inferior start and exit)."), NULL,
struct gdbarch * gdbarch_find_by_info(struct gdbarch_info info)
ui_file_style style() const
target_ops * top_target()
void pop_all_targets_above(enum strata stratum)
int unpush_target(struct target_ops *t)
void unpush_target_and_assert(struct target_ops *target)
void do_all_continuations()
const std::string & cwd() const
target_stack m_target_stack
void push_target(struct target_ops *t)
struct process_stratum_target * process_target()
const std::string & args() const
void add_continuation(std::function< void()> &&cont)
struct address_space * aspace
std::unordered_map< ptid_t, thread_info *, hash_ptid > ptid_thread_map
void pop_all_targets_at_and_above(enum strata stratum)
const std::string & tty()
inf_non_exited_threads_range non_exited_threads()
void set_tty(std::string terminal_name)
intrusive_list< thread_info > thread_list
std::list< std::function< void()> > m_continuations
void clear_thread_list(bool silent)
struct program_space * pspace
void maybe_remove_resumed_with_pending_wait_status(thread_info *thread)
bool unpush(target_ops *t)
void field_string(const char *fldname, const char *string, const ui_file_style &style=ui_file_style())
void field_signed(const char *fldname, LONGEST value)
void field_skip(const char *fldname)
void text(const char *string)
void table_header(int width, ui_align align, const std::string &col_name, const std::string &col_hdr)
void message(const char *format,...) ATTRIBUTE_PRINTF(2
struct cmd_list_element * showprintlist
struct cmd_list_element * cmdlist
struct cmd_list_element * setprintlist
struct cmd_list_element * detachlist
struct cmd_list_element * killlist
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc)
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)
struct cmd_list_element * add_info(const char *name, cmd_simple_func_ftype *fun, const char *doc)
cli_style_option file_name_style
int number_is_in_list(const char *list, int number)
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
LONGEST parse_and_eval_long(const char *exp)
void exec_file_attach(const char *filename, int from_tty)
void reinit_frame_cache(void)
void set_thread_exited(thread_info *tp, bool silent)
void switch_to_thread(struct thread_info *thr)
struct thread_info * any_thread_of_inferior(inferior *inf)
#define threads_debug_printf(fmt,...)
void switch_to_no_thread()
void delete_exited_threads(void)
void init_thread_list(void)
gdb::ref_ptr< struct inferior, refcounted_object_ref_policy > inferior_ref
static struct inf * cur_inf(void)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
void detach_command(const char *args, int from_tty)
static void add_inferior_command(const char *args, int from_tty)
void inferior_appeared(struct inferior *inf, int pid)
static void remove_inferior_command(const char *args, int from_tty)
struct inferior * add_inferior_silent(int pid)
struct inferior * add_inferior_with_spaces(void)
void initialize_inferiors(void)
void print_selected_inferior(struct ui_out *uiout)
static std::string inferior_pid_to_str(int pid)
void exit_inferior(inferior *inf)
static inferior_ref current_inferior_
struct inferior * find_inferior_ptid(process_stratum_target *targ, ptid_t ptid)
static struct value * inferior_id_make_value(struct gdbarch *gdbarch, struct internalvar *var, void *ignore)
struct inferior * find_inferior_pid(process_stratum_target *targ, int pid)
static std::string uiout_field_connection(process_stratum_target *proc_target)
void set_current_inferior(struct inferior *inf)
int number_of_inferiors(void)
bool print_inferior_events
void delete_inferior(struct inferior *inf)
static void clone_inferior_command(const char *args, int from_tty)
static void exit_inferior_1(struct inferior *inf, int silent)
static void detach_inferior_command(const char *args, int from_tty)
void detach_inferior(inferior *inf)
int have_live_inferiors(void)
void switch_to_inferior_and_push_target(inferior *new_inf, bool no_connection, inferior *org_inf)
static void kill_inferior_command(const char *args, int from_tty)
struct inferior * current_inferior(void)
struct inferior * add_inferior(int pid)
struct inferior * find_inferior_for_program_space(struct program_space *pspace)
static int highest_inferior_num
void switch_to_inferior_no_thread(inferior *inf)
static const struct internalvar_funcs inferior_funcs
static void show_print_inferior_events(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
void prune_inferiors(void)
static void inferior_command(const char *args, int from_tty)
static void print_inferior(struct ui_out *uiout, const char *requested_inferiors)
static void info_inferiors_command(const char *args, int from_tty)
intrusive_list< inferior > inferior_list
int number_of_live_inferiors(process_stratum_target *proc_target)
void exit_inferior_silent(inferior *inf)
struct inferior * find_inferior_id(int num)
all_inferiors_safe_range all_inferiors_safe()
all_inferiors_range all_inferiors(process_stratum_target *proc_target=nullptr)
inferior * current_inferior()
void switch_to_inferior_no_thread(inferior *inf)
all_non_exited_inferiors_range all_non_exited_inferiors(process_stratum_target *proc_target=nullptr)
observable< struct inferior * > inferior_added
observable< struct inferior * > inferior_exit
observable< struct inferior * > inferior_removed
observable< user_selected_what > user_selected_context_changed
observable< struct inferior * > inferior_appeared
static process_stratum_target * as_process_stratum_target(target_ops *target)
struct program_space * current_program_space
void set_current_program_space(struct program_space *pspace)
struct program_space * clone_program_space(struct program_space *dest, struct program_space *src)
struct address_space * maybe_new_address_space(void)
void registers_changed(void)
virtual ~private_inferior()=0
struct address_space * aspace
virtual strata stratum() const =0
const char * shortname() const
void symbol_file_add_main(const char *args, symfile_add_flags add_flags)
std::string make_target_connection_string(process_stratum_target *t)
void copy_inferior_target_desc_info(struct inferior *destinf, struct inferior *srcinf)
void target_desc_info_free(struct target_desc_info *tdesc_info)
int target_desc_info_from_user_p(struct target_desc_info *info)
target_ops * get_dummy_target()
std::string target_pid_to_str(ptid_t ptid)
void gdb_printf(struct ui_file *stream, const char *format,...)
struct internalvar * create_internalvar_type_lazy(const char *name, const struct internalvar_funcs *funcs, void *data)
struct value * value_from_longest(struct type *type, LONGEST num)