* registry.h (struct registry_fields): New.
[platform/upstream/binutils.git] / gdb / inferior.c
1 /* Multi-process control for GDB, the GNU debugger.
2
3    Copyright (C) 2008-2012 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include "defs.h"
21 #include "exec.h"
22 #include "inferior.h"
23 #include "target.h"
24 #include "command.h"
25 #include "completer.h"
26 #include "gdbcmd.h"
27 #include "gdbthread.h"
28 #include "ui-out.h"
29 #include "observer.h"
30 #include "gdbthread.h"
31 #include "gdbcore.h"
32 #include "symfile.h"
33 #include "environ.h"
34 #include "cli/cli-utils.h"
35 #include "continuations.h"
36
37 void _initialize_inferiors (void);
38
39 /* Keep a registry of per-inferior data-pointers required by other GDB
40    modules.  */
41
42 DEFINE_REGISTRY (inferior, REGISTRY_ACCESS_FIELD)
43
44 struct inferior *inferior_list = NULL;
45 static int highest_inferior_num;
46
47 /* Print notices on inferior events (attach, detach, etc.), set with
48    `set print inferior-events'.  */
49 static int print_inferior_events = 0;
50
51 /* The Current Inferior.  */
52 static struct inferior *current_inferior_ = NULL;
53
54 struct inferior*
55 current_inferior (void)
56 {
57   return current_inferior_;
58 }
59
60 void
61 set_current_inferior (struct inferior *inf)
62 {
63   /* There's always an inferior.  */
64   gdb_assert (inf != NULL);
65
66   current_inferior_ = inf;
67 }
68
69 /* A cleanups callback, helper for save_current_program_space
70    below.  */
71
72 static void
73 restore_inferior (void *arg)
74 {
75   struct inferior *saved_inferior = arg;
76
77   set_current_inferior (saved_inferior);
78 }
79
80 /* Save the current program space so that it may be restored by a later
81    call to do_cleanups.  Returns the struct cleanup pointer needed for
82    later doing the cleanup.  */
83
84 struct cleanup *
85 save_current_inferior (void)
86 {
87   struct cleanup *old_chain = make_cleanup (restore_inferior,
88                                             current_inferior_);
89
90   return old_chain;
91 }
92
93 static void
94 free_inferior (struct inferior *inf)
95 {
96   discard_all_inferior_continuations (inf);
97   inferior_free_data (inf);
98   xfree (inf->args);
99   xfree (inf->terminal);
100   free_environ (inf->environment);
101   xfree (inf->private);
102   xfree (inf);
103 }
104
105 void
106 init_inferior_list (void)
107 {
108   struct inferior *inf, *infnext;
109
110   highest_inferior_num = 0;
111   if (!inferior_list)
112     return;
113
114   for (inf = inferior_list; inf; inf = infnext)
115     {
116       infnext = inf->next;
117       free_inferior (inf);
118     }
119
120   inferior_list = NULL;
121 }
122
123 struct inferior *
124 add_inferior_silent (int pid)
125 {
126   struct inferior *inf;
127
128   inf = xmalloc (sizeof (*inf));
129   memset (inf, 0, sizeof (*inf));
130   inf->pid = pid;
131
132   inf->control.stop_soon = NO_STOP_QUIETLY;
133
134   inf->num = ++highest_inferior_num;
135   inf->next = inferior_list;
136   inferior_list = inf;
137
138   inf->environment = make_environ ();
139   init_environ (inf->environment);
140
141   inferior_alloc_data (inf);
142
143   observer_notify_inferior_added (inf);
144
145   if (pid != 0)
146     inferior_appeared (inf, pid);
147
148   return inf;
149 }
150
151 struct inferior *
152 add_inferior (int pid)
153 {
154   struct inferior *inf = add_inferior_silent (pid);
155
156   if (print_inferior_events)
157     printf_unfiltered (_("[New inferior %d]\n"), pid);
158
159   return inf;
160 }
161
162 struct delete_thread_of_inferior_arg
163 {
164   int pid;
165   int silent;
166 };
167
168 static int
169 delete_thread_of_inferior (struct thread_info *tp, void *data)
170 {
171   struct delete_thread_of_inferior_arg *arg = data;
172
173   if (ptid_get_pid (tp->ptid) == arg->pid)
174     {
175       if (arg->silent)
176         delete_thread_silent (tp->ptid);
177       else
178         delete_thread (tp->ptid);
179     }
180
181   return 0;
182 }
183
184 /* If SILENT then be quiet -- don't announce a inferior death, or the
185    exit of its threads.  */
186
187 void
188 delete_inferior_1 (struct inferior *todel, int silent)
189 {
190   struct inferior *inf, *infprev;
191   struct delete_thread_of_inferior_arg arg;
192
193   infprev = NULL;
194
195   for (inf = inferior_list; inf; infprev = inf, inf = inf->next)
196     if (inf == todel)
197       break;
198
199   if (!inf)
200     return;
201
202   arg.pid = inf->pid;
203   arg.silent = silent;
204
205   iterate_over_threads (delete_thread_of_inferior, &arg);
206
207   if (infprev)
208     infprev->next = inf->next;
209   else
210     inferior_list = inf->next;
211
212   observer_notify_inferior_removed (inf);
213
214   free_inferior (inf);
215 }
216
217 void
218 delete_inferior (int pid)
219 {
220   struct inferior *inf = find_inferior_pid (pid);
221
222   delete_inferior_1 (inf, 0);
223
224   if (print_inferior_events)
225     printf_unfiltered (_("[Inferior %d exited]\n"), pid);
226 }
227
228 void
229 delete_inferior_silent (int pid)
230 {
231   struct inferior *inf = find_inferior_pid (pid);
232
233   delete_inferior_1 (inf, 1);
234 }
235
236
237 /* If SILENT then be quiet -- don't announce a inferior exit, or the
238    exit of its threads.  */
239
240 static void
241 exit_inferior_1 (struct inferior *inftoex, int silent)
242 {
243   struct inferior *inf;
244   struct delete_thread_of_inferior_arg arg;
245
246   for (inf = inferior_list; inf; inf = inf->next)
247     if (inf == inftoex)
248       break;
249
250   if (!inf)
251     return;
252
253   arg.pid = inf->pid;
254   arg.silent = silent;
255
256   iterate_over_threads (delete_thread_of_inferior, &arg);
257
258   /* Notify the observers before removing the inferior from the list,
259      so that the observers have a chance to look it up.  */
260   observer_notify_inferior_exit (inf);
261
262   inf->pid = 0;
263   inf->fake_pid_p = 0;
264   if (inf->vfork_parent != NULL)
265     {
266       inf->vfork_parent->vfork_child = NULL;
267       inf->vfork_parent = NULL;
268     }
269
270   inf->has_exit_code = 0;
271   inf->exit_code = 0;
272 }
273
274 void
275 exit_inferior (int pid)
276 {
277   struct inferior *inf = find_inferior_pid (pid);
278
279   exit_inferior_1 (inf, 0);
280
281   if (print_inferior_events)
282     printf_unfiltered (_("[Inferior %d exited]\n"), pid);
283 }
284
285 void
286 exit_inferior_silent (int pid)
287 {
288   struct inferior *inf = find_inferior_pid (pid);
289
290   exit_inferior_1 (inf, 1);
291 }
292
293 void
294 exit_inferior_num_silent (int num)
295 {
296   struct inferior *inf = find_inferior_id (num);
297
298   exit_inferior_1 (inf, 1);
299 }
300
301 void
302 detach_inferior (int pid)
303 {
304   struct inferior *inf = find_inferior_pid (pid);
305
306   exit_inferior_1 (inf, 1);
307
308   if (print_inferior_events)
309     printf_unfiltered (_("[Inferior %d detached]\n"), pid);
310 }
311
312 void
313 inferior_appeared (struct inferior *inf, int pid)
314 {
315   inf->pid = pid;
316
317   observer_notify_inferior_appeared (inf);
318 }
319
320 void
321 discard_all_inferiors (void)
322 {
323   struct inferior *inf;
324
325   for (inf = inferior_list; inf; inf = inf->next)
326     {
327       if (inf->pid != 0)
328         exit_inferior_silent (inf->pid);
329     }
330 }
331
332 struct inferior *
333 find_inferior_id (int num)
334 {
335   struct inferior *inf;
336
337   for (inf = inferior_list; inf; inf = inf->next)
338     if (inf->num == num)
339       return inf;
340
341   return NULL;
342 }
343
344 struct inferior *
345 find_inferior_pid (int pid)
346 {
347   struct inferior *inf;
348
349   /* Looking for inferior pid == 0 is always wrong, and indicative of
350      a bug somewhere else.  There may be more than one with pid == 0,
351      for instance.  */
352   gdb_assert (pid != 0);
353
354   for (inf = inferior_list; inf; inf = inf->next)
355     if (inf->pid == pid)
356       return inf;
357
358   return NULL;
359 }
360
361 /* Find an inferior bound to PSPACE.  */
362
363 struct inferior *
364 find_inferior_for_program_space (struct program_space *pspace)
365 {
366   struct inferior *inf;
367
368   for (inf = inferior_list; inf != NULL; inf = inf->next)
369     {
370       if (inf->pspace == pspace)
371         return inf;
372     }
373
374   return NULL;
375 }
376
377 struct inferior *
378 iterate_over_inferiors (int (*callback) (struct inferior *, void *),
379                         void *data)
380 {
381   struct inferior *inf, *infnext;
382
383   for (inf = inferior_list; inf; inf = infnext)
384     {
385       infnext = inf->next;
386       if ((*callback) (inf, data))
387         return inf;
388     }
389
390   return NULL;
391 }
392
393 int
394 valid_gdb_inferior_id (int num)
395 {
396   struct inferior *inf;
397
398   for (inf = inferior_list; inf; inf = inf->next)
399     if (inf->num == num)
400       return 1;
401
402   return 0;
403 }
404
405 int
406 pid_to_gdb_inferior_id (int pid)
407 {
408   struct inferior *inf;
409
410   for (inf = inferior_list; inf; inf = inf->next)
411     if (inf->pid == pid)
412       return inf->num;
413
414   return 0;
415 }
416
417 int
418 gdb_inferior_id_to_pid (int num)
419 {
420   struct inferior *inferior = find_inferior_id (num);
421   if (inferior)
422     return inferior->pid;
423   else
424     return -1;
425 }
426
427 int
428 in_inferior_list (int pid)
429 {
430   struct inferior *inf;
431
432   for (inf = inferior_list; inf; inf = inf->next)
433     if (inf->pid == pid)
434       return 1;
435
436   return 0;
437 }
438
439 int
440 have_inferiors (void)
441 {
442   struct inferior *inf;
443
444   for (inf = inferior_list; inf; inf = inf->next)
445     if (inf->pid != 0)
446       return 1;
447
448   return 0;
449 }
450
451 int
452 have_live_inferiors (void)
453 {
454   struct inferior *inf;
455
456   for (inf = inferior_list; inf; inf = inf->next)
457     if (inf->pid != 0)
458       {
459         struct thread_info *tp;
460         
461         tp = any_thread_of_process (inf->pid);
462         if (tp && target_has_execution_1 (tp->ptid))
463           break;
464       }
465
466   return inf != NULL;
467 }
468
469 /* Prune away automatically added program spaces that aren't required
470    anymore.  */
471
472 void
473 prune_inferiors (void)
474 {
475   struct inferior *ss, **ss_link;
476   struct inferior *current = current_inferior ();
477
478   ss = inferior_list;
479   ss_link = &inferior_list;
480   while (ss)
481     {
482       if (ss == current
483           || !ss->removable
484           || ss->pid != 0)
485         {
486           ss_link = &ss->next;
487           ss = *ss_link;
488           continue;
489         }
490
491       *ss_link = ss->next;
492       delete_inferior_1 (ss, 1);
493       ss = *ss_link;
494     }
495
496   prune_program_spaces ();
497 }
498
499 /* Simply returns the count of inferiors.  */
500
501 int
502 number_of_inferiors (void)
503 {
504   struct inferior *inf;
505   int count = 0;
506
507   for (inf = inferior_list; inf != NULL; inf = inf->next)
508     count++;
509
510   return count;
511 }
512
513 /* Converts an inferior process id to a string.  Like
514    target_pid_to_str, but special cases the null process.  */
515
516 static char *
517 inferior_pid_to_str (int pid)
518 {
519   if (pid != 0)
520     return target_pid_to_str (pid_to_ptid (pid));
521   else
522     return _("<null>");
523 }
524
525 /* Prints the list of inferiors and their details on UIOUT.  This is a
526    version of 'info_inferior_command' suitable for use from MI.
527
528    If REQUESTED_INFERIORS is not NULL, it's a list of GDB ids of the
529    inferiors that should be printed.  Otherwise, all inferiors are
530    printed.  */
531
532 static void
533 print_inferior (struct ui_out *uiout, char *requested_inferiors)
534 {
535   struct inferior *inf;
536   struct cleanup *old_chain;
537   int inf_count = 0;
538
539   /* Compute number of inferiors we will print.  */
540   for (inf = inferior_list; inf; inf = inf->next)
541     {
542       if (!number_is_in_list (requested_inferiors, inf->num))
543         continue;
544
545       ++inf_count;
546     }
547
548   if (inf_count == 0)
549     {
550       ui_out_message (uiout, 0, "No inferiors.\n");
551       return;
552     }
553
554   old_chain = make_cleanup_ui_out_table_begin_end (uiout, 4, inf_count,
555                                                    "inferiors");
556   ui_out_table_header (uiout, 1, ui_left, "current", "");
557   ui_out_table_header (uiout, 4, ui_left, "number", "Num");
558   ui_out_table_header (uiout, 17, ui_left, "target-id", "Description");
559   ui_out_table_header (uiout, 17, ui_left, "exec", "Executable");
560
561   ui_out_table_body (uiout);
562   for (inf = inferior_list; inf; inf = inf->next)
563     {
564       struct cleanup *chain2;
565
566       if (!number_is_in_list (requested_inferiors, inf->num))
567         continue;
568
569       chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
570
571       if (inf == current_inferior ())
572         ui_out_field_string (uiout, "current", "*");
573       else
574         ui_out_field_skip (uiout, "current");
575
576       ui_out_field_int (uiout, "number", inf->num);
577
578       ui_out_field_string (uiout, "target-id",
579                            inferior_pid_to_str (inf->pid));
580
581       if (inf->pspace->ebfd)
582         ui_out_field_string (uiout, "exec",
583                              bfd_get_filename (inf->pspace->ebfd));
584       else
585         ui_out_field_skip (uiout, "exec");
586
587       /* Print extra info that isn't really fit to always present in
588          tabular form.  Currently we print the vfork parent/child
589          relationships, if any.  */
590       if (inf->vfork_parent)
591         {
592           ui_out_text (uiout, _("\n\tis vfork child of inferior "));
593           ui_out_field_int (uiout, "vfork-parent", inf->vfork_parent->num);
594         }
595       if (inf->vfork_child)
596         {
597           ui_out_text (uiout, _("\n\tis vfork parent of inferior "));
598           ui_out_field_int (uiout, "vfork-child", inf->vfork_child->num);
599         }
600
601       ui_out_text (uiout, "\n");
602       do_cleanups (chain2);
603     }
604
605   do_cleanups (old_chain);
606 }
607
608 static void
609 detach_inferior_command (char *args, int from_tty)
610 {
611   int num, pid;
612   struct thread_info *tp;
613   struct get_number_or_range_state state;
614
615   if (!args || !*args)
616     error (_("Requires argument (inferior id(s) to detach)"));
617
618   init_number_or_range (&state, args);
619   while (!state.finished)
620     {
621       num = get_number_or_range (&state);
622
623       if (!valid_gdb_inferior_id (num))
624         {
625           warning (_("Inferior ID %d not known."), num);
626           continue;
627         }
628
629       pid = gdb_inferior_id_to_pid (num);
630
631       tp = any_thread_of_process (pid);
632       if (!tp)
633         {
634           warning (_("Inferior ID %d has no threads."), num);
635           continue;
636         }
637
638       switch_to_thread (tp->ptid);
639
640       detach_command (NULL, from_tty);
641     }
642 }
643
644 static void
645 kill_inferior_command (char *args, int from_tty)
646 {
647   int num, pid;
648   struct thread_info *tp;
649   struct get_number_or_range_state state;
650
651   if (!args || !*args)
652     error (_("Requires argument (inferior id(s) to kill)"));
653
654   init_number_or_range (&state, args);
655   while (!state.finished)
656     {
657       num = get_number_or_range (&state);
658
659       if (!valid_gdb_inferior_id (num))
660         {
661           warning (_("Inferior ID %d not known."), num);
662           continue;
663         }
664
665       pid = gdb_inferior_id_to_pid (num);
666
667       tp = any_thread_of_process (pid);
668       if (!tp)
669         {
670           warning (_("Inferior ID %d has no threads."), num);
671           continue;
672         }
673
674       switch_to_thread (tp->ptid);
675
676       target_kill ();
677     }
678
679   bfd_cache_close_all ();
680 }
681
682 static void
683 inferior_command (char *args, int from_tty)
684 {
685   struct inferior *inf;
686   int num;
687
688   num = parse_and_eval_long (args);
689
690   inf = find_inferior_id (num);
691   if (inf == NULL)
692     error (_("Inferior ID %d not known."), num);
693
694   printf_filtered (_("[Switching to inferior %d [%s] (%s)]\n"),
695                    inf->num,
696                    inferior_pid_to_str (inf->pid),
697                    (inf->pspace->ebfd
698                     ? bfd_get_filename (inf->pspace->ebfd)
699                     : _("<noexec>")));
700
701   if (inf->pid != 0)
702     {
703       if (inf->pid != ptid_get_pid (inferior_ptid))
704         {
705           struct thread_info *tp;
706
707           tp = any_thread_of_process (inf->pid);
708           if (!tp)
709             error (_("Inferior has no threads."));
710
711           switch_to_thread (tp->ptid);
712         }
713
714       printf_filtered (_("[Switching to thread %d (%s)] "),
715                        pid_to_thread_id (inferior_ptid),
716                        target_pid_to_str (inferior_ptid));
717     }
718   else
719     {
720       struct inferior *inf;
721
722       inf = find_inferior_id (num);
723       set_current_inferior (inf);
724       switch_to_thread (null_ptid);
725       set_current_program_space (inf->pspace);
726     }
727
728   if (inf->pid != 0 && is_running (inferior_ptid))
729     ui_out_text (current_uiout, "(running)\n");
730   else if (inf->pid != 0)
731     {
732       ui_out_text (current_uiout, "\n");
733       print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
734     }
735 }
736
737 /* Print information about currently known inferiors.  */
738
739 static void
740 info_inferiors_command (char *args, int from_tty)
741 {
742   print_inferior (current_uiout, args);
743 }
744
745 /* remove-inferior ID */
746
747 static void
748 remove_inferior_command (char *args, int from_tty)
749 {
750   int num;
751   struct inferior *inf;
752   struct get_number_or_range_state state;
753
754   if (args == NULL || *args == '\0')
755     error (_("Requires an argument (inferior id(s) to remove)"));
756
757   init_number_or_range (&state, args);
758   while (!state.finished)
759     {
760       num = get_number_or_range (&state);
761       inf = find_inferior_id (num);
762
763       if (inf == NULL)
764         {
765           warning (_("Inferior ID %d not known."), num);
766           continue;
767         }
768
769       if (inf == current_inferior ())
770         {
771           warning (_("Can not remove current symbol inferior %d."), num);
772           continue;
773         }
774     
775       if (inf->pid != 0)
776         {
777           warning (_("Can not remove active inferior %d."), num);
778           continue;
779         }
780
781       delete_inferior_1 (inf, 1);
782     }
783 }
784
785 struct inferior *
786 add_inferior_with_spaces (void)
787 {
788   struct address_space *aspace;
789   struct program_space *pspace;
790   struct inferior *inf;
791
792   /* If all inferiors share an address space on this system, this
793      doesn't really return a new address space; otherwise, it
794      really does.  */
795   aspace = maybe_new_address_space ();
796   pspace = add_program_space (aspace);
797   inf = add_inferior (0);
798   inf->pspace = pspace;
799   inf->aspace = pspace->aspace;
800
801   return inf;
802 }
803
804 /* add-inferior [-copies N] [-exec FILENAME]  */
805
806 static void
807 add_inferior_command (char *args, int from_tty)
808 {
809   int i, copies = 1;
810   char *exec = NULL;
811   char **argv;
812   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
813
814   if (args)
815     {
816       argv = gdb_buildargv (args);
817       make_cleanup_freeargv (argv);
818
819       for (; *argv != NULL; argv++)
820         {
821           if (**argv == '-')
822             {
823               if (strcmp (*argv, "-copies") == 0)
824                 {
825                   ++argv;
826                   if (!*argv)
827                     error (_("No argument to -copies"));
828                   copies = parse_and_eval_long (*argv);
829                 }
830               else if (strcmp (*argv, "-exec") == 0)
831                 {
832                   ++argv;
833                   if (!*argv)
834                     error (_("No argument to -exec"));
835                   exec = *argv;
836                 }
837             }
838           else
839             error (_("Invalid argument"));
840         }
841     }
842
843   save_current_space_and_thread ();
844
845   for (i = 0; i < copies; ++i)
846     {
847       struct inferior *inf = add_inferior_with_spaces ();
848
849       printf_filtered (_("Added inferior %d\n"), inf->num);
850
851       if (exec != NULL)
852         {
853           /* Switch over temporarily, while reading executable and
854              symbols.q.  */
855           set_current_program_space (inf->pspace);
856           set_current_inferior (inf);
857           switch_to_thread (null_ptid);
858
859           exec_file_attach (exec, from_tty);
860           symbol_file_add_main (exec, from_tty);
861         }
862     }
863
864   do_cleanups (old_chain);
865 }
866
867 /* clone-inferior [-copies N] [ID] */
868
869 static void
870 clone_inferior_command (char *args, int from_tty)
871 {
872   int i, copies = 1;
873   char **argv;
874   struct inferior *orginf = NULL;
875   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
876
877   if (args)
878     {
879       argv = gdb_buildargv (args);
880       make_cleanup_freeargv (argv);
881
882       for (; *argv != NULL; argv++)
883         {
884           if (**argv == '-')
885             {
886               if (strcmp (*argv, "-copies") == 0)
887                 {
888                   ++argv;
889                   if (!*argv)
890                     error (_("No argument to -copies"));
891                   copies = parse_and_eval_long (*argv);
892
893                   if (copies < 0)
894                     error (_("Invalid copies number"));
895                 }
896             }
897           else
898             {
899               if (orginf == NULL)
900                 {
901                   int num;
902
903                   /* The first non-option (-) argument specified the
904                      program space ID.  */
905                   num = parse_and_eval_long (*argv);
906                   orginf = find_inferior_id (num);
907
908                   if (orginf == NULL)
909                     error (_("Inferior ID %d not known."), num);
910                   continue;
911                 }
912               else
913                 error (_("Invalid argument"));
914             }
915         }
916     }
917
918   /* If no inferior id was specified, then the user wants to clone the
919      current inferior.  */
920   if (orginf == NULL)
921     orginf = current_inferior ();
922
923   save_current_space_and_thread ();
924
925   for (i = 0; i < copies; ++i)
926     {
927       struct address_space *aspace;
928       struct program_space *pspace;
929       struct inferior *inf;
930
931       /* If all inferiors share an address space on this system, this
932          doesn't really return a new address space; otherwise, it
933          really does.  */
934       aspace = maybe_new_address_space ();
935       pspace = add_program_space (aspace);
936       inf = add_inferior (0);
937       inf->pspace = pspace;
938       inf->aspace = pspace->aspace;
939
940       printf_filtered (_("Added inferior %d.\n"), inf->num);
941
942       set_current_inferior (inf);
943       switch_to_thread (null_ptid);
944       clone_program_space (pspace, orginf->pspace);
945     }
946
947   do_cleanups (old_chain);
948 }
949
950 /* Print notices when new inferiors are created and die.  */
951 static void
952 show_print_inferior_events (struct ui_file *file, int from_tty,
953                            struct cmd_list_element *c, const char *value)
954 {
955   fprintf_filtered (file, _("Printing of inferior events is %s.\n"), value);
956 }
957
958 \f
959
960 void
961 initialize_inferiors (void)
962 {
963   struct cmd_list_element *c = NULL;
964
965   /* There's always one inferior.  Note that this function isn't an
966      automatic _initialize_foo function, since other _initialize_foo
967      routines may need to install their per-inferior data keys.  We
968      can only allocate an inferior when all those modules have done
969      that.  Do this after initialize_progspace, due to the
970      current_program_space reference.  */
971   current_inferior_ = add_inferior (0);
972   current_inferior_->pspace = current_program_space;
973   current_inferior_->aspace = current_program_space->aspace;
974
975   add_info ("inferiors", info_inferiors_command, 
976             _("IDs of specified inferiors (all inferiors if no argument)."));
977
978   c = add_com ("add-inferior", no_class, add_inferior_command, _("\
979 Add a new inferior.\n\
980 Usage: add-inferior [-copies <N>] [-exec <FILENAME>]\n\
981 N is the optional number of inferiors to add, default is 1.\n\
982 FILENAME is the file name of the executable to use\n\
983 as main program."));
984   set_cmd_completer (c, filename_completer);
985
986   add_com ("remove-inferiors", no_class, remove_inferior_command, _("\
987 Remove inferior ID (or list of IDs).\n\
988 Usage: remove-inferiors ID..."));
989
990   add_com ("clone-inferior", no_class, clone_inferior_command, _("\
991 Clone inferior ID.\n\
992 Usage: clone-inferior [-copies <N>] [ID]\n\
993 Add N copies of inferior ID.  The new inferior has the same\n\
994 executable loaded as the copied inferior.  If -copies is not specified,\n\
995 adds 1 copy.  If ID is not specified, it is the current inferior\n\
996 that is cloned."));
997
998   add_cmd ("inferiors", class_run, detach_inferior_command, _("\
999 Detach from inferior ID (or list of IDS)."),
1000            &detachlist);
1001
1002   add_cmd ("inferiors", class_run, kill_inferior_command, _("\
1003 Kill inferior ID (or list of IDs)."),
1004            &killlist);
1005
1006   add_cmd ("inferior", class_run, inferior_command, _("\
1007 Use this command to switch between inferiors.\n\
1008 The new inferior ID must be currently known."),
1009            &cmdlist);
1010
1011   add_setshow_boolean_cmd ("inferior-events", no_class,
1012          &print_inferior_events, _("\
1013 Set printing of inferior events (e.g., inferior start and exit)."), _("\
1014 Show printing of inferior events (e.g., inferior start and exit)."), NULL,
1015          NULL,
1016          show_print_inferior_events,
1017          &setprintlist, &showprintlist);
1018
1019 }