restore_inferior (void *arg)
{
struct inferior *saved_inferior = arg;
+
set_current_inferior (saved_inferior);
}
{
struct cleanup *old_chain = make_cleanup (restore_inferior,
current_inferior_);
+
return old_chain;
}
inferior_alloc_data (inf);
+ observer_notify_inferior_added (inf);
+
if (pid != 0)
inferior_appeared (inf, pid);
/* If SILENT then be quiet -- don't announce a inferior death, or the
exit of its threads. */
-static void
+void
delete_inferior_1 (struct inferior *todel, int silent)
{
struct inferior *inf, *infprev;
else
inferior_list = inf->next;
+ observer_notify_inferior_removed (inf);
+
free_inferior (inf);
}
/* Notify the observers before removing the inferior from the list,
so that the observers have a chance to look it up. */
- observer_notify_inferior_exit (inf->pid);
+ observer_notify_inferior_exit (inf);
inf->pid = 0;
if (inf->vfork_parent != NULL)
exit_inferior (int pid)
{
struct inferior *inf = find_inferior_pid (pid);
+
exit_inferior_1 (inf, 0);
if (print_inferior_events)
exit_inferior_silent (int pid)
{
struct inferior *inf = find_inferior_pid (pid);
+
exit_inferior_1 (inf, 1);
}
detach_inferior (int pid)
{
struct inferior *inf = find_inferior_pid (pid);
+
exit_inferior_1 (inf, 1);
if (print_inferior_events)
{
inf->pid = pid;
- observer_notify_inferior_appeared (pid);
+ observer_notify_inferior_appeared (inf);
}
void
int
have_live_inferiors (void)
{
- struct target_ops *t;
+ struct cleanup *old_chain;
+ struct inferior *inf;
- /* The check on stratum suffices, as GDB doesn't currently support
- multiple target interfaces. */
- if (have_inferiors ())
- for (t = current_target.beneath; t != NULL; t = t->beneath)
- if (t->to_stratum == process_stratum)
- return 1;
+ old_chain = make_cleanup_restore_current_thread ();
- return 0;
+ for (inf = inferior_list; inf; inf = inf->next)
+ if (inf->pid != 0)
+ {
+ struct thread_info *tp;
+
+ tp = any_thread_of_process (inf->pid);
+ if (tp)
+ {
+ switch_to_thread (tp->ptid);
+
+ if (target_has_execution)
+ break;
+ }
+ }
+
+ do_cleanups (old_chain);
+
+ return inf != NULL;
}
/* Prune away automatically added program spaces that aren't required
/* Compute number of inferiors we will print. */
for (inf = inferior_list; inf; inf = inf->next)
{
- struct cleanup *chain2;
-
if (requested_inferior != -1 && inf->num != requested_inferior)
continue;
delete_inferior_1 (inf, 1);
}
+struct inferior *
+add_inferior_with_spaces (void)
+{
+ struct address_space *aspace;
+ struct program_space *pspace;
+ struct inferior *inf;
+
+ /* If all inferiors share an address space on this system, this
+ doesn't really return a new address space; otherwise, it
+ really does. */
+ aspace = maybe_new_address_space ();
+ pspace = add_program_space (aspace);
+ inf = add_inferior (0);
+ inf->pspace = pspace;
+ inf->aspace = pspace->aspace;
+
+ return inf;
+}
/* add-inferior [-copies N] [-exec FILENAME] */
for (i = 0; i < copies; ++i)
{
- struct address_space *aspace;
- struct program_space *pspace;
- struct inferior *inf;
-
- /* If all inferiors share an address space on this system, this
- doesn't really return a new address space; otherwise, it
- really does. */
- aspace = maybe_new_address_space ();
- pspace = add_program_space (aspace);
- inf = add_inferior (0);
- inf->pspace = pspace;
- inf->aspace = pspace->aspace;
+ struct inferior *inf = add_inferior_with_spaces ();
printf_filtered (_("Added inferior %d\n"), inf->num);
{
/* Switch over temporarily, while reading executable and
symbols.q */
- set_current_program_space (pspace);
+ set_current_program_space (inf->pspace);
set_current_inferior (inf);
switch_to_thread (null_ptid);