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