gdb/
[binutils-gdb.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 if (inf->vfork_child != NULL)
270 {
271 inf->vfork_child->vfork_parent = NULL;
272 inf->vfork_child = NULL;
273 }
274
275 inf->has_exit_code = 0;
276 inf->exit_code = 0;
277 inf->pending_detach = 0;
278 }
279
280 void
281 exit_inferior (int pid)
282 {
283 struct inferior *inf = find_inferior_pid (pid);
284
285 exit_inferior_1 (inf, 0);
286
287 if (print_inferior_events)
288 printf_unfiltered (_("[Inferior %d exited]\n"), pid);
289 }
290
291 void
292 exit_inferior_silent (int pid)
293 {
294 struct inferior *inf = find_inferior_pid (pid);
295
296 exit_inferior_1 (inf, 1);
297 }
298
299 void
300 exit_inferior_num_silent (int num)
301 {
302 struct inferior *inf = find_inferior_id (num);
303
304 exit_inferior_1 (inf, 1);
305 }
306
307 void
308 detach_inferior (int pid)
309 {
310 struct inferior *inf = find_inferior_pid (pid);
311
312 exit_inferior_1 (inf, 1);
313
314 if (print_inferior_events)
315 printf_unfiltered (_("[Inferior %d detached]\n"), pid);
316 }
317
318 void
319 inferior_appeared (struct inferior *inf, int pid)
320 {
321 inf->pid = pid;
322
323 observer_notify_inferior_appeared (inf);
324 }
325
326 void
327 discard_all_inferiors (void)
328 {
329 struct inferior *inf;
330
331 for (inf = inferior_list; inf; inf = inf->next)
332 {
333 if (inf->pid != 0)
334 exit_inferior_silent (inf->pid);
335 }
336 }
337
338 struct inferior *
339 find_inferior_id (int num)
340 {
341 struct inferior *inf;
342
343 for (inf = inferior_list; inf; inf = inf->next)
344 if (inf->num == num)
345 return inf;
346
347 return NULL;
348 }
349
350 struct inferior *
351 find_inferior_pid (int pid)
352 {
353 struct inferior *inf;
354
355 /* Looking for inferior pid == 0 is always wrong, and indicative of
356 a bug somewhere else. There may be more than one with pid == 0,
357 for instance. */
358 gdb_assert (pid != 0);
359
360 for (inf = inferior_list; inf; inf = inf->next)
361 if (inf->pid == pid)
362 return inf;
363
364 return NULL;
365 }
366
367 /* Find an inferior bound to PSPACE. */
368
369 struct inferior *
370 find_inferior_for_program_space (struct program_space *pspace)
371 {
372 struct inferior *inf;
373
374 for (inf = inferior_list; inf != NULL; inf = inf->next)
375 {
376 if (inf->pspace == pspace)
377 return inf;
378 }
379
380 return NULL;
381 }
382
383 struct inferior *
384 iterate_over_inferiors (int (*callback) (struct inferior *, void *),
385 void *data)
386 {
387 struct inferior *inf, *infnext;
388
389 for (inf = inferior_list; inf; inf = infnext)
390 {
391 infnext = inf->next;
392 if ((*callback) (inf, data))
393 return inf;
394 }
395
396 return NULL;
397 }
398
399 int
400 valid_gdb_inferior_id (int num)
401 {
402 struct inferior *inf;
403
404 for (inf = inferior_list; inf; inf = inf->next)
405 if (inf->num == num)
406 return 1;
407
408 return 0;
409 }
410
411 int
412 pid_to_gdb_inferior_id (int pid)
413 {
414 struct inferior *inf;
415
416 for (inf = inferior_list; inf; inf = inf->next)
417 if (inf->pid == pid)
418 return inf->num;
419
420 return 0;
421 }
422
423 int
424 gdb_inferior_id_to_pid (int num)
425 {
426 struct inferior *inferior = find_inferior_id (num);
427 if (inferior)
428 return inferior->pid;
429 else
430 return -1;
431 }
432
433 int
434 in_inferior_list (int pid)
435 {
436 struct inferior *inf;
437
438 for (inf = inferior_list; inf; inf = inf->next)
439 if (inf->pid == pid)
440 return 1;
441
442 return 0;
443 }
444
445 int
446 have_inferiors (void)
447 {
448 struct inferior *inf;
449
450 for (inf = inferior_list; inf; inf = inf->next)
451 if (inf->pid != 0)
452 return 1;
453
454 return 0;
455 }
456
457 int
458 have_live_inferiors (void)
459 {
460 struct inferior *inf;
461
462 for (inf = inferior_list; inf; inf = inf->next)
463 if (inf->pid != 0)
464 {
465 struct thread_info *tp;
466
467 tp = any_thread_of_process (inf->pid);
468 if (tp && target_has_execution_1 (tp->ptid))
469 break;
470 }
471
472 return inf != NULL;
473 }
474
475 /* Prune away automatically added program spaces that aren't required
476 anymore. */
477
478 void
479 prune_inferiors (void)
480 {
481 struct inferior *ss, **ss_link;
482 struct inferior *current = current_inferior ();
483
484 ss = inferior_list;
485 ss_link = &inferior_list;
486 while (ss)
487 {
488 if (ss == current
489 || !ss->removable
490 || ss->pid != 0)
491 {
492 ss_link = &ss->next;
493 ss = *ss_link;
494 continue;
495 }
496
497 *ss_link = ss->next;
498 delete_inferior_1 (ss, 1);
499 ss = *ss_link;
500 }
501
502 prune_program_spaces ();
503 }
504
505 /* Simply returns the count of inferiors. */
506
507 int
508 number_of_inferiors (void)
509 {
510 struct inferior *inf;
511 int count = 0;
512
513 for (inf = inferior_list; inf != NULL; inf = inf->next)
514 count++;
515
516 return count;
517 }
518
519 /* Converts an inferior process id to a string. Like
520 target_pid_to_str, but special cases the null process. */
521
522 static char *
523 inferior_pid_to_str (int pid)
524 {
525 if (pid != 0)
526 return target_pid_to_str (pid_to_ptid (pid));
527 else
528 return _("<null>");
529 }
530
531 /* Prints the list of inferiors and their details on UIOUT. This is a
532 version of 'info_inferior_command' suitable for use from MI.
533
534 If REQUESTED_INFERIORS is not NULL, it's a list of GDB ids of the
535 inferiors that should be printed. Otherwise, all inferiors are
536 printed. */
537
538 static void
539 print_inferior (struct ui_out *uiout, char *requested_inferiors)
540 {
541 struct inferior *inf;
542 struct cleanup *old_chain;
543 int inf_count = 0;
544
545 /* Compute number of inferiors we will print. */
546 for (inf = inferior_list; inf; inf = inf->next)
547 {
548 if (!number_is_in_list (requested_inferiors, inf->num))
549 continue;
550
551 ++inf_count;
552 }
553
554 if (inf_count == 0)
555 {
556 ui_out_message (uiout, 0, "No inferiors.\n");
557 return;
558 }
559
560 old_chain = make_cleanup_ui_out_table_begin_end (uiout, 4, inf_count,
561 "inferiors");
562 ui_out_table_header (uiout, 1, ui_left, "current", "");
563 ui_out_table_header (uiout, 4, ui_left, "number", "Num");
564 ui_out_table_header (uiout, 17, ui_left, "target-id", "Description");
565 ui_out_table_header (uiout, 17, ui_left, "exec", "Executable");
566
567 ui_out_table_body (uiout);
568 for (inf = inferior_list; inf; inf = inf->next)
569 {
570 struct cleanup *chain2;
571
572 if (!number_is_in_list (requested_inferiors, inf->num))
573 continue;
574
575 chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
576
577 if (inf == current_inferior ())
578 ui_out_field_string (uiout, "current", "*");
579 else
580 ui_out_field_skip (uiout, "current");
581
582 ui_out_field_int (uiout, "number", inf->num);
583
584 ui_out_field_string (uiout, "target-id",
585 inferior_pid_to_str (inf->pid));
586
587 if (inf->pspace->ebfd)
588 ui_out_field_string (uiout, "exec",
589 bfd_get_filename (inf->pspace->ebfd));
590 else
591 ui_out_field_skip (uiout, "exec");
592
593 /* Print extra info that isn't really fit to always present in
594 tabular form. Currently we print the vfork parent/child
595 relationships, if any. */
596 if (inf->vfork_parent)
597 {
598 ui_out_text (uiout, _("\n\tis vfork child of inferior "));
599 ui_out_field_int (uiout, "vfork-parent", inf->vfork_parent->num);
600 }
601 if (inf->vfork_child)
602 {
603 ui_out_text (uiout, _("\n\tis vfork parent of inferior "));
604 ui_out_field_int (uiout, "vfork-child", inf->vfork_child->num);
605 }
606
607 ui_out_text (uiout, "\n");
608 do_cleanups (chain2);
609 }
610
611 do_cleanups (old_chain);
612 }
613
614 static void
615 detach_inferior_command (char *args, int from_tty)
616 {
617 int num, pid;
618 struct thread_info *tp;
619 struct get_number_or_range_state state;
620
621 if (!args || !*args)
622 error (_("Requires argument (inferior id(s) to detach)"));
623
624 init_number_or_range (&state, args);
625 while (!state.finished)
626 {
627 num = get_number_or_range (&state);
628
629 if (!valid_gdb_inferior_id (num))
630 {
631 warning (_("Inferior ID %d not known."), num);
632 continue;
633 }
634
635 pid = gdb_inferior_id_to_pid (num);
636
637 tp = any_thread_of_process (pid);
638 if (!tp)
639 {
640 warning (_("Inferior ID %d has no threads."), num);
641 continue;
642 }
643
644 switch_to_thread (tp->ptid);
645
646 detach_command (NULL, from_tty);
647 }
648 }
649
650 static void
651 kill_inferior_command (char *args, int from_tty)
652 {
653 int num, pid;
654 struct thread_info *tp;
655 struct get_number_or_range_state state;
656
657 if (!args || !*args)
658 error (_("Requires argument (inferior id(s) to kill)"));
659
660 init_number_or_range (&state, args);
661 while (!state.finished)
662 {
663 num = get_number_or_range (&state);
664
665 if (!valid_gdb_inferior_id (num))
666 {
667 warning (_("Inferior ID %d not known."), num);
668 continue;
669 }
670
671 pid = gdb_inferior_id_to_pid (num);
672
673 tp = any_thread_of_process (pid);
674 if (!tp)
675 {
676 warning (_("Inferior ID %d has no threads."), num);
677 continue;
678 }
679
680 switch_to_thread (tp->ptid);
681
682 target_kill ();
683 }
684
685 bfd_cache_close_all ();
686 }
687
688 static void
689 inferior_command (char *args, int from_tty)
690 {
691 struct inferior *inf;
692 int num;
693
694 num = parse_and_eval_long (args);
695
696 inf = find_inferior_id (num);
697 if (inf == NULL)
698 error (_("Inferior ID %d not known."), num);
699
700 printf_filtered (_("[Switching to inferior %d [%s] (%s)]\n"),
701 inf->num,
702 inferior_pid_to_str (inf->pid),
703 (inf->pspace->ebfd
704 ? bfd_get_filename (inf->pspace->ebfd)
705 : _("<noexec>")));
706
707 if (inf->pid != 0)
708 {
709 if (inf->pid != ptid_get_pid (inferior_ptid))
710 {
711 struct thread_info *tp;
712
713 tp = any_thread_of_process (inf->pid);
714 if (!tp)
715 error (_("Inferior has no threads."));
716
717 switch_to_thread (tp->ptid);
718 }
719
720 printf_filtered (_("[Switching to thread %d (%s)] "),
721 pid_to_thread_id (inferior_ptid),
722 target_pid_to_str (inferior_ptid));
723 }
724 else
725 {
726 struct inferior *inf;
727
728 inf = find_inferior_id (num);
729 set_current_inferior (inf);
730 switch_to_thread (null_ptid);
731 set_current_program_space (inf->pspace);
732 }
733
734 if (inf->pid != 0 && is_running (inferior_ptid))
735 ui_out_text (current_uiout, "(running)\n");
736 else if (inf->pid != 0)
737 {
738 ui_out_text (current_uiout, "\n");
739 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
740 }
741 }
742
743 /* Print information about currently known inferiors. */
744
745 static void
746 info_inferiors_command (char *args, int from_tty)
747 {
748 print_inferior (current_uiout, args);
749 }
750
751 /* remove-inferior ID */
752
753 static void
754 remove_inferior_command (char *args, int from_tty)
755 {
756 int num;
757 struct inferior *inf;
758 struct get_number_or_range_state state;
759
760 if (args == NULL || *args == '\0')
761 error (_("Requires an argument (inferior id(s) to remove)"));
762
763 init_number_or_range (&state, args);
764 while (!state.finished)
765 {
766 num = get_number_or_range (&state);
767 inf = find_inferior_id (num);
768
769 if (inf == NULL)
770 {
771 warning (_("Inferior ID %d not known."), num);
772 continue;
773 }
774
775 if (inf == current_inferior ())
776 {
777 warning (_("Can not remove current symbol inferior %d."), num);
778 continue;
779 }
780
781 if (inf->pid != 0)
782 {
783 warning (_("Can not remove active inferior %d."), num);
784 continue;
785 }
786
787 delete_inferior_1 (inf, 1);
788 }
789 }
790
791 struct inferior *
792 add_inferior_with_spaces (void)
793 {
794 struct address_space *aspace;
795 struct program_space *pspace;
796 struct inferior *inf;
797
798 /* If all inferiors share an address space on this system, this
799 doesn't really return a new address space; otherwise, it
800 really does. */
801 aspace = maybe_new_address_space ();
802 pspace = add_program_space (aspace);
803 inf = add_inferior (0);
804 inf->pspace = pspace;
805 inf->aspace = pspace->aspace;
806
807 return inf;
808 }
809
810 /* add-inferior [-copies N] [-exec FILENAME] */
811
812 static void
813 add_inferior_command (char *args, int from_tty)
814 {
815 int i, copies = 1;
816 char *exec = NULL;
817 char **argv;
818 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
819
820 if (args)
821 {
822 argv = gdb_buildargv (args);
823 make_cleanup_freeargv (argv);
824
825 for (; *argv != NULL; argv++)
826 {
827 if (**argv == '-')
828 {
829 if (strcmp (*argv, "-copies") == 0)
830 {
831 ++argv;
832 if (!*argv)
833 error (_("No argument to -copies"));
834 copies = parse_and_eval_long (*argv);
835 }
836 else if (strcmp (*argv, "-exec") == 0)
837 {
838 ++argv;
839 if (!*argv)
840 error (_("No argument to -exec"));
841 exec = *argv;
842 }
843 }
844 else
845 error (_("Invalid argument"));
846 }
847 }
848
849 save_current_space_and_thread ();
850
851 for (i = 0; i < copies; ++i)
852 {
853 struct inferior *inf = add_inferior_with_spaces ();
854
855 printf_filtered (_("Added inferior %d\n"), inf->num);
856
857 if (exec != NULL)
858 {
859 /* Switch over temporarily, while reading executable and
860 symbols.q. */
861 set_current_program_space (inf->pspace);
862 set_current_inferior (inf);
863 switch_to_thread (null_ptid);
864
865 exec_file_attach (exec, from_tty);
866 symbol_file_add_main (exec, from_tty);
867 }
868 }
869
870 do_cleanups (old_chain);
871 }
872
873 /* clone-inferior [-copies N] [ID] */
874
875 static void
876 clone_inferior_command (char *args, int from_tty)
877 {
878 int i, copies = 1;
879 char **argv;
880 struct inferior *orginf = NULL;
881 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
882
883 if (args)
884 {
885 argv = gdb_buildargv (args);
886 make_cleanup_freeargv (argv);
887
888 for (; *argv != NULL; argv++)
889 {
890 if (**argv == '-')
891 {
892 if (strcmp (*argv, "-copies") == 0)
893 {
894 ++argv;
895 if (!*argv)
896 error (_("No argument to -copies"));
897 copies = parse_and_eval_long (*argv);
898
899 if (copies < 0)
900 error (_("Invalid copies number"));
901 }
902 }
903 else
904 {
905 if (orginf == NULL)
906 {
907 int num;
908
909 /* The first non-option (-) argument specified the
910 program space ID. */
911 num = parse_and_eval_long (*argv);
912 orginf = find_inferior_id (num);
913
914 if (orginf == NULL)
915 error (_("Inferior ID %d not known."), num);
916 continue;
917 }
918 else
919 error (_("Invalid argument"));
920 }
921 }
922 }
923
924 /* If no inferior id was specified, then the user wants to clone the
925 current inferior. */
926 if (orginf == NULL)
927 orginf = current_inferior ();
928
929 save_current_space_and_thread ();
930
931 for (i = 0; i < copies; ++i)
932 {
933 struct address_space *aspace;
934 struct program_space *pspace;
935 struct inferior *inf;
936
937 /* If all inferiors share an address space on this system, this
938 doesn't really return a new address space; otherwise, it
939 really does. */
940 aspace = maybe_new_address_space ();
941 pspace = add_program_space (aspace);
942 inf = add_inferior (0);
943 inf->pspace = pspace;
944 inf->aspace = pspace->aspace;
945
946 printf_filtered (_("Added inferior %d.\n"), inf->num);
947
948 set_current_inferior (inf);
949 switch_to_thread (null_ptid);
950 clone_program_space (pspace, orginf->pspace);
951 }
952
953 do_cleanups (old_chain);
954 }
955
956 /* Print notices when new inferiors are created and die. */
957 static void
958 show_print_inferior_events (struct ui_file *file, int from_tty,
959 struct cmd_list_element *c, const char *value)
960 {
961 fprintf_filtered (file, _("Printing of inferior events is %s.\n"), value);
962 }
963
964 \f
965
966 void
967 initialize_inferiors (void)
968 {
969 struct cmd_list_element *c = NULL;
970
971 /* There's always one inferior. Note that this function isn't an
972 automatic _initialize_foo function, since other _initialize_foo
973 routines may need to install their per-inferior data keys. We
974 can only allocate an inferior when all those modules have done
975 that. Do this after initialize_progspace, due to the
976 current_program_space reference. */
977 current_inferior_ = add_inferior (0);
978 current_inferior_->pspace = current_program_space;
979 current_inferior_->aspace = current_program_space->aspace;
980
981 add_info ("inferiors", info_inferiors_command,
982 _("IDs of specified inferiors (all inferiors if no argument)."));
983
984 c = add_com ("add-inferior", no_class, add_inferior_command, _("\
985 Add a new inferior.\n\
986 Usage: add-inferior [-copies <N>] [-exec <FILENAME>]\n\
987 N is the optional number of inferiors to add, default is 1.\n\
988 FILENAME is the file name of the executable to use\n\
989 as main program."));
990 set_cmd_completer (c, filename_completer);
991
992 add_com ("remove-inferiors", no_class, remove_inferior_command, _("\
993 Remove inferior ID (or list of IDs).\n\
994 Usage: remove-inferiors ID..."));
995
996 add_com ("clone-inferior", no_class, clone_inferior_command, _("\
997 Clone inferior ID.\n\
998 Usage: clone-inferior [-copies <N>] [ID]\n\
999 Add N copies of inferior ID. The new inferior has the same\n\
1000 executable loaded as the copied inferior. If -copies is not specified,\n\
1001 adds 1 copy. If ID is not specified, it is the current inferior\n\
1002 that is cloned."));
1003
1004 add_cmd ("inferiors", class_run, detach_inferior_command, _("\
1005 Detach from inferior ID (or list of IDS)."),
1006 &detachlist);
1007
1008 add_cmd ("inferiors", class_run, kill_inferior_command, _("\
1009 Kill inferior ID (or list of IDs)."),
1010 &killlist);
1011
1012 add_cmd ("inferior", class_run, inferior_command, _("\
1013 Use this command to switch between inferiors.\n\
1014 The new inferior ID must be currently known."),
1015 &cmdlist);
1016
1017 add_setshow_boolean_cmd ("inferior-events", no_class,
1018 &print_inferior_events, _("\
1019 Set printing of inferior events (e.g., inferior start and exit)."), _("\
1020 Show printing of inferior events (e.g., inferior start and exit)."), NULL,
1021 NULL,
1022 show_print_inferior_events,
1023 &setprintlist, &showprintlist);
1024
1025 }