#include "arch-utils.h"
#include "target-descriptions.h"
#include "readline/tilde.h"
+#include "progspace-and-thread.h"
void _initialize_inferiors (void);
`set print inferior-events'. */
static int print_inferior_events = 0;
-/* The Current Inferior. */
+/* 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;
struct inferior*
/* There's always an inferior. */
gdb_assert (inf != NULL);
+ inf->incref ();
+ current_inferior_->decref ();
current_inferior_ = inf;
}
-/* A cleanups callback, helper for save_current_program_space
- below. */
-
-static void
-restore_inferior (void *arg)
-{
- struct inferior *saved_inferior = (struct inferior *) arg;
-
- set_current_inferior (saved_inferior);
-}
-
-/* Save the current program space so that it may be restored by a later
- call to do_cleanups. Returns the struct cleanup pointer needed for
- later doing the cleanup. */
-
-struct cleanup *
-save_current_inferior (void)
+inferior::~inferior ()
{
- struct cleanup *old_chain = make_cleanup (restore_inferior,
- current_inferior_);
-
- return old_chain;
-}
+ inferior *inf = this;
-static void
-free_inferior (struct inferior *inf)
-{
discard_all_inferior_continuations (inf);
inferior_free_data (inf);
xfree (inf->args);
free_environ (inf->environment);
target_desc_info_free (inf->tdesc_info);
xfree (inf->priv);
- xfree (inf);
+}
+
+inferior::inferior (int pid_)
+ : num (++highest_inferior_num),
+ pid (pid_),
+ environment (make_environ ()),
+ registry_data ()
+{
+ init_environ (this->environment);
+ inferior_alloc_data (this);
}
struct inferior *
add_inferior_silent (int pid)
{
- struct inferior *inf;
-
- inf = XNEW (struct inferior);
- memset (inf, 0, sizeof (*inf));
- inf->pid = pid;
-
- inf->control.stop_soon = NO_STOP_QUIETLY;
-
- inf->num = ++highest_inferior_num;
+ inferior *inf = new inferior (pid);
if (inferior_list == NULL)
inferior_list = inf;
else
{
- struct inferior *last;
+ inferior *last;
for (last = inferior_list; last->next != NULL; last = last->next)
;
last->next = inf;
}
- inf->environment = make_environ ();
- init_environ (inf->environment);
-
- inferior_alloc_data (inf);
-
observer_notify_inferior_added (inf);
if (pid != 0)
if (program_space_empty_p (inf->pspace))
delete_program_space (inf->pspace);
- free_inferior (inf);
+ delete inf;
}
/* If SILENT then be quiet -- don't announce a inferior exit, or the
prune_inferiors (void)
{
struct inferior *ss, **ss_link;
- struct inferior *current = current_inferior ();
ss = inferior_list;
ss_link = &inferior_list;
while (ss)
{
- if (ss == current
+ if (!ss->deletable ()
|| !ss->removable
|| ss->pid != 0)
{
uiout->table_body ();
for (inf = inferior_list; inf; inf = inf->next)
{
- struct cleanup *chain2;
-
if (!number_is_in_list (requested_inferiors, inf->num))
continue;
- chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout, NULL);
if (inf == current_inferior ())
uiout->field_string ("current", "*");
}
uiout->text ("\n");
- do_cleanups (chain2);
}
do_cleanups (old_chain);
continue;
}
- if (inf == current_inferior ())
+ if (!inf->deletable ())
{
warning (_("Can not remove current inferior %d."), num);
continue;
}
}
- save_current_space_and_thread ();
+ scoped_restore_current_pspace_and_thread restore_pspace_thread;
for (i = 0; i < copies; ++i)
{
if (orginf == NULL)
orginf = current_inferior ();
- save_current_space_and_thread ();
+ scoped_restore_current_pspace_and_thread restore_pspace_thread;
for (i = 0; i < copies; ++i)
{
that. Do this after initialize_progspace, due to the
current_program_space reference. */
current_inferior_ = add_inferior (0);
+ current_inferior_->incref ();
current_inferior_->pspace = current_program_space;
current_inferior_->aspace = current_program_space->aspace;
/* The architecture will be initialized shortly, by