+ int num;
+ struct inferior *inf;
+
+ num = parse_and_eval_long (args);
+ inf = find_inferior_id (num);
+
+ if (inf == NULL)
+ error (_("Inferior ID %d not known."), num);
+
+ if (inf == current_inferior ())
+ error (_("Can not remove current symbol inferior."));
+
+ 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] */
+
+void
+add_inferior_command (char *args, int from_tty)
+{
+ int i, copies = 1;
+ char *exec = NULL;
+ char **argv;
+ struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
+
+ if (args)
+ {
+ argv = gdb_buildargv (args);
+ make_cleanup_freeargv (argv);
+
+ for (; *argv != NULL; argv++)
+ {
+ if (**argv == '-')
+ {
+ if (strcmp (*argv, "-copies") == 0)
+ {
+ ++argv;
+ if (!*argv)
+ error (_("No argument to -copies"));
+ copies = parse_and_eval_long (*argv);
+ }
+ else if (strcmp (*argv, "-exec") == 0)
+ {
+ ++argv;
+ if (!*argv)
+ error (_("No argument to -exec"));
+ exec = *argv;
+ }
+ }
+ else
+ error (_("Invalid argument"));
+ }
+ }
+
+ save_current_space_and_thread ();
+
+ for (i = 0; i < copies; ++i)
+ {
+ struct inferior *inf = add_inferior_with_spaces ();
+
+ printf_filtered (_("Added inferior %d\n"), inf->num);
+
+ if (exec != NULL)
+ {
+ /* Switch over temporarily, while reading executable and
+ symbols.q */
+ set_current_program_space (inf->pspace);
+ set_current_inferior (inf);
+ switch_to_thread (null_ptid);
+
+ exec_file_attach (exec, from_tty);
+ symbol_file_add_main (exec, from_tty);
+ }
+ }
+
+ do_cleanups (old_chain);
+}
+
+/* clone-inferior [-copies N] [ID] */
+
+void
+clone_inferior_command (char *args, int from_tty)
+{
+ int i, copies = 1;
+ char **argv;
+ struct inferior *orginf = NULL;
+ struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
+
+ if (args)
+ {
+ argv = gdb_buildargv (args);
+ make_cleanup_freeargv (argv);
+
+ for (; *argv != NULL; argv++)
+ {
+ if (**argv == '-')
+ {
+ if (strcmp (*argv, "-copies") == 0)
+ {
+ ++argv;
+ if (!*argv)
+ error (_("No argument to -copies"));
+ copies = parse_and_eval_long (*argv);
+
+ if (copies < 0)
+ error (_("Invalid copies number"));
+ }
+ }
+ else
+ {
+ if (orginf == NULL)
+ {
+ int num;
+
+ /* The first non-option (-) argument specified the
+ program space ID. */
+ num = parse_and_eval_long (*argv);
+ orginf = find_inferior_id (num);
+
+ if (orginf == NULL)
+ error (_("Inferior ID %d not known."), num);
+ continue;
+ }
+ else
+ error (_("Invalid argument"));
+ }
+ }
+ }
+
+ /* If no inferior id was specified, then the user wants to clone the
+ current inferior. */
+ if (orginf == NULL)
+ orginf = current_inferior ();
+
+ save_current_space_and_thread ();
+
+ 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;
+
+ printf_filtered (_("Added inferior %d.\n"), inf->num);
+
+ set_current_inferior (inf);
+ switch_to_thread (null_ptid);
+ clone_program_space (pspace, orginf->pspace);
+ }
+
+ do_cleanups (old_chain);