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