/* Multi-process control for GDB, the GNU debugger.
- Copyright (C) 2008-2020 Free Software Foundation, Inc.
+ Copyright (C) 2008-2021 Free Software Foundation, Inc.
This file is part of GDB.
#include "symfile.h"
#include "gdbsupport/environ.h"
#include "cli/cli-utils.h"
-#include "continuations.h"
#include "arch-utils.h"
#include "target-descriptions.h"
#include "readline/tilde.h"
/* The Current Inferior. This is a strong reference. I.e., whenever
an inferior is the current inferior, its refcount is
incremented. */
-static struct inferior *current_inferior_ = NULL;
+static inferior_ref current_inferior_;
struct inferior*
current_inferior (void)
{
- return current_inferior_;
+ return current_inferior_.get ();
}
void
/* There's always an inferior. */
gdb_assert (inf != NULL);
- inf->incref ();
- current_inferior_->decref ();
- current_inferior_ = inf;
+ current_inferior_ = inferior_ref::new_reference (inf);
}
private_inferior::~private_inferior () = default;
{
inferior *inf = this;
- discard_all_inferior_continuations (inf);
+ m_continuations.clear ();
inferior_free_data (inf);
- xfree (inf->args);
- xfree (inf->terminal);
target_desc_info_free (inf->tdesc_info);
}
m_target_stack.push (get_dummy_target ());
}
+void
+inferior::set_tty (const char *terminal_name)
+{
+ if (terminal_name != nullptr && *terminal_name != '\0')
+ m_terminal = make_unique_xstrdup (terminal_name);
+ else
+ m_terminal = NULL;
+}
+
+const char *
+inferior::tty ()
+{
+ return m_terminal.get ();
+}
+
+void
+inferior::add_continuation (std::function<void ()> &&cont)
+{
+ m_continuations.emplace_front (std::move (cont));
+}
+
+void
+inferior::do_all_continuations ()
+{
+ while (!m_continuations.empty ())
+ {
+ auto iter = m_continuations.begin ();
+ (*iter) ();
+ m_continuations.erase (iter);
+ }
+}
+
struct inferior *
add_inferior_silent (int pid)
{
gdb::observers::inferior_removed.notify (inf);
/* If this program space is rendered useless, remove it. */
- if (program_space_empty_p (inf->pspace))
+ if (inf->pspace->empty ())
delete inf->pspace;
delete inf;
print_selected_inferior (struct ui_out *uiout)
{
struct inferior *inf = current_inferior ();
- const char *filename = inf->pspace->pspace_exec_filename;
+ const char *filename = inf->pspace->exec_filename.get ();
if (filename == NULL)
filename = _("<noexec>");
uiout->field_signed ("number", inf->num);
- /* Because target_pid_to_str uses current_top_target,
+ /* Because target_pid_to_str uses the current inferior,
switch the inferior. */
switch_to_inferior_no_thread (inf);
uiout->field_string ("target-id", inferior_pid_to_str (inf->pid));
std::string conn = uiout_field_connection (inf->process_target ());
- uiout->field_string ("connection-id", conn.c_str ());
+ uiout->field_string ("connection-id", conn);
- if (inf->pspace->pspace_exec_filename != NULL)
- uiout->field_string ("exec", inf->pspace->pspace_exec_filename);
+ if (inf->pspace->exec_filename != nullptr)
+ uiout->field_string ("exec", inf->pspace->exec_filename.get ());
else
uiout->field_skip ("exec");
if (!args || !*args)
error (_("Requires argument (inferior id(s) to detach)"));
+ scoped_restore_current_thread restore_thread;
+
number_or_range_parser parser (args);
while (!parser.finished ())
{
if (!args || !*args)
error (_("Requires argument (inferior id(s) to kill)"));
+ scoped_restore_current_thread restore_thread;
+
number_or_range_parser parser (args);
while (!parser.finished ())
{
struct inferior *inf;
int num;
- num = parse_and_eval_long (args);
-
- inf = find_inferior_id (num);
- if (inf == NULL)
- error (_("Inferior ID %d not known."), num);
-
- if (inf->pid != 0)
+ if (args == nullptr)
{
- if (inf != current_inferior ())
- {
- thread_info *tp = any_thread_of_inferior (inf);
- if (tp == NULL)
- error (_("Inferior has no threads."));
+ inf = current_inferior ();
+ gdb_assert (inf != nullptr);
+ const char *filename = inf->pspace->exec_filename.get ();
- switch_to_thread (tp);
- }
+ if (filename == nullptr)
+ filename = _("<noexec>");
- gdb::observers::user_selected_context_changed.notify
- (USER_SELECTED_INFERIOR
- | USER_SELECTED_THREAD
- | USER_SELECTED_FRAME);
+ printf_filtered (_("[Current inferior is %d [%s] (%s)]\n"),
+ inf->num, inferior_pid_to_str (inf->pid).c_str (),
+ filename);
}
else
{
- switch_to_inferior_no_thread (inf);
+ num = parse_and_eval_long (args);
+
+ inf = find_inferior_id (num);
+ if (inf == NULL)
+ error (_("Inferior ID %d not known."), num);
- gdb::observers::user_selected_context_changed.notify
- (USER_SELECTED_INFERIOR);
+ if (inf->pid != 0)
+ {
+ if (inf != current_inferior ())
+ {
+ thread_info *tp = any_thread_of_inferior (inf);
+ if (tp == NULL)
+ error (_("Inferior has no threads."));
+
+ switch_to_thread (tp);
+ }
+
+ gdb::observers::user_selected_context_changed.notify
+ (USER_SELECTED_INFERIOR
+ | USER_SELECTED_THREAD
+ | USER_SELECTED_FRAME);
+ }
+ else
+ {
+ switch_to_inferior_no_thread (inf);
+
+ gdb::observers::user_selected_context_changed.notify
+ (USER_SELECTED_INFERIOR);
+ }
}
}
/* Reuse the target for new inferior. */
if (!no_connection && proc_target != NULL)
{
- push_target (proc_target);
+ new_inf->push_target (proc_target);
if (proc_target->connection_string () != NULL)
printf_filtered (_("Added inferior %d on connection %d (%s %s)\n"),
new_inf->num,
can only allocate an inferior when all those modules have done
that. Do this after initialize_progspace, due to the
current_program_space reference. */
- current_inferior_ = add_inferior_silent (0);
- current_inferior_->incref ();
+ set_current_inferior (add_inferior_silent (0));
current_inferior_->pspace = current_program_space;
current_inferior_->aspace = current_program_space->aspace;
/* The architecture will be initialized shortly, by
&cmdlist);
add_setshow_boolean_cmd ("inferior-events", no_class,
- &print_inferior_events, _("\
+ &print_inferior_events, _("\
Set printing of inferior events (such as inferior start and exit)."), _("\
Show printing of inferior events (such as inferior start and exit)."), NULL,
- NULL,
- show_print_inferior_events,
- &setprintlist, &showprintlist);
+ NULL,
+ show_print_inferior_events,
+ &setprintlist, &showprintlist);
create_internalvar_type_lazy ("_inferior", &inferior_funcs, NULL);
}