GDB (xrefs)
Loading...
Searching...
No Matches
inferior.c
Go to the documentation of this file.
1/* Multi-process control for GDB, the GNU debugger.
2
3 Copyright (C) 2008-2023 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 "observable.h"
30#include "gdbcore.h"
31#include "symfile.h"
32#include "gdbsupport/environ.h"
33#include "cli/cli-utils.h"
34#include "arch-utils.h"
35#include "target-descriptions.h"
36#include "target-connection.h"
37#include "readline/tilde.h"
39#include "gdbsupport/buildargv.h"
40#include "cli/cli-style.h"
41
42intrusive_list<inferior> inferior_list;
44
45/* See inferior.h. */
47
48/* The Current Inferior. This is a strong reference. I.e., whenever
49 an inferior is the current inferior, its refcount is
50 incremented. */
52
53struct inferior*
55{
56 return current_inferior_.get ();
57}
58
59void
61{
62 /* There's always an inferior. */
63 gdb_assert (inf != NULL);
64
65 current_inferior_ = inferior_ref::new_reference (inf);
66}
67
69
71{
72 inferior *inf = this;
73
74 /* Before the inferior is deleted, all target_ops should be popped from
75 the target stack, this leaves just the dummy_target behind. If this
76 is not done, then any target left in the target stack will be left
77 with an artificially high reference count. As the dummy_target is
78 still on the target stack then we are about to loose a reference to
79 that target, leaving its reference count artificially high. However,
80 this is not critical as the dummy_target is a singleton. */
81 gdb_assert (m_target_stack.top ()->stratum () == dummy_stratum);
82
83 m_continuations.clear ();
84 target_desc_info_free (inf->tdesc_info);
85}
86
89 pid (pid_),
90 environment (gdb_environ::from_host_environ ())
91{
93}
94
95/* See inferior.h. */
96
97int
99{
100 /* If unpushing the process stratum target from the inferior while threads
101 exist in the inferior, ensure that we don't leave any threads of the
102 inferior in the target's "resumed with pending wait status" list.
103
104 See also the comment in set_thread_exited. */
105 if (t->stratum () == process_stratum)
106 {
108
109 for (thread_info *thread : this->non_exited_threads ())
111 }
112
113 return m_target_stack.unpush (t);
114}
115
116/* See inferior.h. */
117
118void
120{
121 gdb_assert (current_inferior () == this);
122
123 if (!unpush_target (target))
124 internal_error ("pop_all_targets couldn't find target %s\n",
125 target->shortname ());
126}
127
128/* See inferior.h. */
129
130void
132{
133 /* Unpushing a target might cause it to close. Some targets currently
134 rely on the current_inferior being set for their ::close method, so we
135 temporarily switch inferior now. */
136 scoped_restore_current_pspace_and_thread restore_pspace_and_thread;
138
139 while (top_target ()->stratum () > stratum)
141}
142
143/* See inferior.h. */
144
145void
147{
148 /* Unpushing a target might cause it to close. Some targets currently
149 rely on the current_inferior being set for their ::close method, so we
150 temporarily switch inferior now. */
151 scoped_restore_current_pspace_and_thread restore_pspace_and_thread;
153
154 while (top_target ()->stratum () >= stratum)
156}
157
158void
159inferior::set_tty (std::string terminal_name)
160{
161 m_terminal = std::move (terminal_name);
162}
163
164const std::string &
166{
167 return m_terminal;
168}
169
170void
171inferior::add_continuation (std::function<void ()> &&cont)
172{
173 m_continuations.emplace_front (std::move (cont));
174}
175
176void
178{
179 while (!m_continuations.empty ())
180 {
181 auto iter = m_continuations.begin ();
182 (*iter) ();
183 m_continuations.erase (iter);
184 }
185}
186
187struct inferior *
189{
190 inferior *inf = new inferior (pid);
191
192 inferior_list.push_back (*inf);
193
195
196 if (pid != 0)
198
199 return inf;
200}
201
202struct inferior *
204{
206
208 {
209 if (pid != 0)
210 gdb_printf (_("[New inferior %d (%s)]\n"),
211 inf->num,
212 target_pid_to_str (ptid_t (pid)).c_str ());
213 else
214 gdb_printf (_("[New inferior %d]\n"), inf->num);
215 }
216
217 return inf;
218}
219
220/* See inferior.h. */
221
222void
224{
225 thread_list.clear_and_dispose ([=] (thread_info *thr)
226 {
227 threads_debug_printf ("deleting thread %s, silent = %d",
228 thr->ptid.to_string ().c_str (), silent);
229 set_thread_exited (thr, silent);
230 if (thr->deletable ())
231 delete thr;
232 });
233 ptid_thread_map.clear ();
234}
235
236void
238{
239 inf->clear_thread_list (true);
240
241 auto it = inferior_list.iterator_to (*inf);
242 inferior_list.erase (it);
243
245
246 /* Pop all targets now, this ensures that inferior::unpush is called
247 correctly. As pop_all_targets ends up making a temporary switch to
248 inferior INF then we need to make this call before we delete the
249 program space, which we do below. */
250 inf->pop_all_targets ();
251
252 /* If this program space is rendered useless, remove it. */
253 if (inf->pspace->empty ())
254 delete inf->pspace;
255
256 delete inf;
257}
258
259/* If SILENT then be quiet -- don't announce a inferior exit, or the
260 exit of its threads. */
261
262static void
263exit_inferior_1 (struct inferior *inf, int silent)
264{
265 inf->clear_thread_list (silent);
266
268
269 inf->pid = 0;
270 inf->fake_pid_p = false;
271 inf->priv = NULL;
272
273 if (inf->vfork_parent != NULL)
274 {
275 inf->vfork_parent->vfork_child = NULL;
276 inf->vfork_parent = NULL;
277 }
278 if (inf->vfork_child != NULL)
279 {
280 inf->vfork_child->vfork_parent = NULL;
281 inf->vfork_child = NULL;
282 }
283
284 inf->pending_detach = false;
285 /* Reset it. */
287
288 /* Clear the register cache and the frame cache. */
291}
292
293void
295{
296 exit_inferior_1 (inf, 0);
297}
298
299void
301{
302 exit_inferior_1 (inf, 1);
303}
304
305/* See inferior.h. */
306
307void
309{
310 /* Save the pid, since exit_inferior_1 will reset it. */
311 int pid = inf->pid;
312
313 exit_inferior_1 (inf, 0);
314
316 gdb_printf (_("[Inferior %d (%s) detached]\n"),
317 inf->num,
318 target_pid_to_str (ptid_t (pid)).c_str ());
319}
320
321void
323{
324 /* If this is the first inferior with threads, reset the global
325 thread id. */
327 if (!any_thread_p ())
329
330 inf->pid = pid;
331 inf->has_exit_code = false;
332 inf->exit_code = 0;
333
335}
336
337struct inferior *
339{
340 for (inferior *inf : all_inferiors ())
341 if (inf->num == num)
342 return inf;
343
344 return NULL;
345}
346
347struct inferior *
349{
350 /* Looking for inferior pid == 0 is always wrong, and indicative of
351 a bug somewhere else. There may be more than one with pid == 0,
352 for instance. */
353 gdb_assert (pid != 0);
354
355 for (inferior *inf : all_inferiors (targ))
356 if (inf->pid == pid)
357 return inf;
358
359 return NULL;
360}
361
362/* See inferior.h */
363
364struct inferior *
366{
367 return find_inferior_pid (targ, ptid.pid ());
368}
369
370/* See inferior.h. */
371
372struct inferior *
374{
375 struct inferior *cur_inf = current_inferior ();
376
377 if (cur_inf->pspace == pspace)
378 return cur_inf;
379
380 for (inferior *inf : all_inferiors ())
381 if (inf->pspace == pspace)
382 return inf;
383
384 return NULL;
385}
386
387int
389{
390 for (inferior *inf ATTRIBUTE_UNUSED : all_non_exited_inferiors ())
391 return 1;
392
393 return 0;
394}
395
396/* Return the number of live inferiors. We account for the case
397 where an inferior might have a non-zero pid but no threads, as
398 in the middle of a 'mourn' operation. */
399
400int
402{
403 int num_inf = 0;
404
405 for (inferior *inf : all_non_exited_inferiors (proc_target))
406 if (inf->has_execution ())
407 for (thread_info *tp ATTRIBUTE_UNUSED : inf->non_exited_threads ())
408 {
409 /* Found a live thread in this inferior, go to the next
410 inferior. */
411 ++num_inf;
412 break;
413 }
414
415 return num_inf;
416}
417
418/* Return true if there is at least one live inferior. */
419
420int
422{
423 return number_of_live_inferiors (NULL) > 0;
424}
425
426/* Prune away any unused inferiors, and then prune away no longer used
427 program spaces. */
428
429void
431{
433 {
434 if (!inf->deletable ()
435 || !inf->removable
436 || inf->pid != 0)
437 continue;
438
440 }
441}
442
443/* Simply returns the count of inferiors. */
444
445int
447{
448 auto rng = all_inferiors ();
449 return std::distance (rng.begin (), rng.end ());
450}
451
452/* Converts an inferior process id to a string. Like
453 target_pid_to_str, but special cases the null process. */
454
455static std::string
457{
458 if (pid != 0)
459 return target_pid_to_str (ptid_t (pid));
460 else
461 return _("<null>");
462}
463
464/* See inferior.h. */
465
466void
468{
469 struct inferior *inf = current_inferior ();
470 const char *filename = inf->pspace->exec_filename.get ();
471
472 if (filename == NULL)
473 filename = _("<noexec>");
474
475 uiout->message (_("[Switching to inferior %d [%s] (%s)]\n"),
476 inf->num, inferior_pid_to_str (inf->pid).c_str (), filename);
477}
478
479/* Helper for print_inferior. Returns the 'connection-id' string for
480 PROC_TARGET. */
481
482static std::string
484{
485 if (proc_target == NULL)
486 return {};
487 else
488 {
489 std::string conn_str = make_target_connection_string (proc_target);
490 return string_printf ("%d (%s)", proc_target->connection_number,
491 conn_str.c_str ());
492 }
493}
494
495/* Prints the list of inferiors and their details on UIOUT. This is a
496 version of 'info_inferior_command' suitable for use from MI.
497
498 If REQUESTED_INFERIORS is not NULL, it's a list of GDB ids of the
499 inferiors that should be printed. Otherwise, all inferiors are
500 printed. */
501
502static void
503print_inferior (struct ui_out *uiout, const char *requested_inferiors)
504{
505 int inf_count = 0;
506 size_t connection_id_len = 20;
507
508 /* Compute number of inferiors we will print. */
509 for (inferior *inf : all_inferiors ())
510 {
511 if (!number_is_in_list (requested_inferiors, inf->num))
512 continue;
513
514 std::string conn = uiout_field_connection (inf->process_target ());
515 if (connection_id_len < conn.size ())
516 connection_id_len = conn.size ();
517
518 ++inf_count;
519 }
520
521 if (inf_count == 0)
522 {
523 uiout->message ("No inferiors.\n");
524 return;
525 }
526
527 ui_out_emit_table table_emitter (uiout, 5, inf_count, "inferiors");
528 uiout->table_header (1, ui_left, "current", "");
529 uiout->table_header (4, ui_left, "number", "Num");
530 uiout->table_header (17, ui_left, "target-id", "Description");
531 uiout->table_header (connection_id_len, ui_left,
532 "connection-id", "Connection");
533 uiout->table_header (17, ui_left, "exec", "Executable");
534
535 uiout->table_body ();
536
537 /* Restore the current thread after the loop because we switch the
538 inferior in the loop. */
539 scoped_restore_current_pspace_and_thread restore_pspace_thread;
540 inferior *current_inf = current_inferior ();
541 for (inferior *inf : all_inferiors ())
542 {
543 if (!number_is_in_list (requested_inferiors, inf->num))
544 continue;
545
546 ui_out_emit_tuple tuple_emitter (uiout, NULL);
547
548 if (inf == current_inf)
549 uiout->field_string ("current", "*");
550 else
551 uiout->field_skip ("current");
552
553 uiout->field_signed ("number", inf->num);
554
555 /* Because target_pid_to_str uses the current inferior,
556 switch the inferior. */
558
559 uiout->field_string ("target-id", inferior_pid_to_str (inf->pid));
560
561 std::string conn = uiout_field_connection (inf->process_target ());
562 uiout->field_string ("connection-id", conn);
563
564 if (inf->pspace->exec_filename != nullptr)
565 uiout->field_string ("exec", inf->pspace->exec_filename.get (),
567 else
568 uiout->field_skip ("exec");
569
570 /* Print extra info that isn't really fit to always present in
571 tabular form. Currently we print the vfork parent/child
572 relationships, if any. */
573 if (inf->vfork_parent)
574 {
575 uiout->text (_("\n\tis vfork child of inferior "));
576 uiout->field_signed ("vfork-parent", inf->vfork_parent->num);
577 }
578 if (inf->vfork_child)
579 {
580 uiout->text (_("\n\tis vfork parent of inferior "));
581 uiout->field_signed ("vfork-child", inf->vfork_child->num);
582 }
583
584 uiout->text ("\n");
585 }
586}
587
588static void
589detach_inferior_command (const char *args, int from_tty)
590{
591 if (!args || !*args)
592 error (_("Requires argument (inferior id(s) to detach)"));
593
594 scoped_restore_current_thread restore_thread;
595
597 while (!parser.finished ())
598 {
599 int num = parser.get_number ();
600
602 if (inf == NULL)
603 {
604 warning (_("Inferior ID %d not known."), num);
605 continue;
606 }
607
608 if (inf->pid == 0)
609 {
610 warning (_("Inferior ID %d is not running."), num);
611 continue;
612 }
613
615 if (tp == NULL)
616 {
617 warning (_("Inferior ID %d has no threads."), num);
618 continue;
619 }
620
621 switch_to_thread (tp);
622
623 detach_command (NULL, from_tty);
624 }
625}
626
627static void
628kill_inferior_command (const char *args, int from_tty)
629{
630 if (!args || !*args)
631 error (_("Requires argument (inferior id(s) to kill)"));
632
633 scoped_restore_current_thread restore_thread;
634
636 while (!parser.finished ())
637 {
638 int num = parser.get_number ();
639
641 if (inf == NULL)
642 {
643 warning (_("Inferior ID %d not known."), num);
644 continue;
645 }
646
647 if (inf->pid == 0)
648 {
649 warning (_("Inferior ID %d is not running."), num);
650 continue;
651 }
652
654 if (tp == NULL)
655 {
656 warning (_("Inferior ID %d has no threads."), num);
657 continue;
658 }
659
660 switch_to_thread (tp);
661
662 target_kill ();
663 }
664
665 bfd_cache_close_all ();
666}
667
668/* See inferior.h. */
669
670void
672{
676}
677
678static void
679inferior_command (const char *args, int from_tty)
680{
681 struct inferior *inf;
682 int num;
683
684 if (args == nullptr)
685 {
687 gdb_assert (inf != nullptr);
688 const char *filename = inf->pspace->exec_filename.get ();
689
690 if (filename == nullptr)
691 filename = _("<noexec>");
692
693 gdb_printf (_("[Current inferior is %d [%s] (%s)]\n"),
694 inf->num, inferior_pid_to_str (inf->pid).c_str (),
695 filename);
696 }
697 else
698 {
700
702 if (inf == NULL)
703 error (_("Inferior ID %d not known."), num);
704
705 if (inf->pid != 0)
706 {
707 if (inf != current_inferior ())
708 {
710 if (tp == NULL)
711 error (_("Inferior has no threads."));
712
713 switch_to_thread (tp);
714 }
715
720 }
721 else
722 {
724
727 }
728 }
729}
730
731/* Print information about currently known inferiors. */
732
733static void
734info_inferiors_command (const char *args, int from_tty)
735{
737}
738
739/* remove-inferior ID */
740
741static void
742remove_inferior_command (const char *args, int from_tty)
743{
744 if (args == NULL || *args == '\0')
745 error (_("Requires an argument (inferior id(s) to remove)"));
746
748 while (!parser.finished ())
749 {
750 int num = parser.get_number ();
751 struct inferior *inf = find_inferior_id (num);
752
753 if (inf == NULL)
754 {
755 warning (_("Inferior ID %d not known."), num);
756 continue;
757 }
758
759 if (!inf->deletable ())
760 {
761 warning (_("Can not remove current inferior %d."), num);
762 continue;
763 }
764
765 if (inf->pid != 0)
766 {
767 warning (_("Can not remove active inferior %d."), num);
768 continue;
769 }
770
772 }
773}
774
775struct inferior *
777{
778 struct address_space *aspace;
779 struct program_space *pspace;
780 struct inferior *inf;
781
782 /* If all inferiors share an address space on this system, this
783 doesn't really return a new address space; otherwise, it
784 really does. */
787 inf = add_inferior (0);
788 inf->pspace = pspace;
789 inf->aspace = pspace->aspace;
790
791 /* Setup the inferior's initial arch, based on information obtained
792 from the global "set ..." options. */
793 gdbarch_info info;
794 inf->gdbarch = gdbarch_find_by_info (info);
795 /* The "set ..." options reject invalid settings, so we should
796 always have a valid arch by now. */
797 gdb_assert (inf->gdbarch != NULL);
798
799 return inf;
800}
801
802/* See inferior.h. */
803
804void
806 bool no_connection, inferior *org_inf)
807{
808 process_stratum_target *proc_target = org_inf->process_target ();
809
810 /* Switch over temporarily, while reading executable and
811 symbols. */
813
814 /* Reuse the target for new inferior. */
815 if (!no_connection && proc_target != NULL)
816 {
817 new_inf->push_target (proc_target);
818 gdb_printf (_("Added inferior %d on connection %d (%s)\n"),
819 new_inf->num,
820 proc_target->connection_number,
821 make_target_connection_string (proc_target).c_str ());
822 }
823 else
824 gdb_printf (_("Added inferior %d\n"), new_inf->num);
825}
826
827/* add-inferior [-copies N] [-exec FILENAME] [-no-connection] */
828
829static void
830add_inferior_command (const char *args, int from_tty)
831{
832 int i, copies = 1;
833 gdb::unique_xmalloc_ptr<char> exec;
834 symfile_add_flags add_flags = 0;
835 bool no_connection = false;
836
837 if (from_tty)
838 add_flags |= SYMFILE_VERBOSE;
839
840 if (args)
841 {
842 gdb_argv built_argv (args);
843
844 for (char **argv = built_argv.get (); *argv != NULL; argv++)
845 {
846 if (**argv == '-')
847 {
848 if (strcmp (*argv, "-copies") == 0)
849 {
850 ++argv;
851 if (!*argv)
852 error (_("No argument to -copies"));
853 copies = parse_and_eval_long (*argv);
854 }
855 else if (strcmp (*argv, "-no-connection") == 0)
856 no_connection = true;
857 else if (strcmp (*argv, "-exec") == 0)
858 {
859 ++argv;
860 if (!*argv)
861 error (_("No argument to -exec"));
862 exec.reset (tilde_expand (*argv));
863 }
864 }
865 else
866 error (_("Invalid argument"));
867 }
868 }
869
870 inferior *orginf = current_inferior ();
871
872 scoped_restore_current_pspace_and_thread restore_pspace_thread;
873
874 for (i = 0; i < copies; ++i)
875 {
877
878 switch_to_inferior_and_push_target (inf, no_connection, orginf);
879
880 if (exec != NULL)
881 {
882 exec_file_attach (exec.get (), from_tty);
883 symbol_file_add_main (exec.get (), add_flags);
884 }
885 }
886}
887
888/* clone-inferior [-copies N] [ID] [-no-connection] */
889
890static void
891clone_inferior_command (const char *args, int from_tty)
892{
893 int i, copies = 1;
894 struct inferior *orginf = NULL;
895 bool no_connection = false;
896
897 if (args)
898 {
899 gdb_argv built_argv (args);
900
901 char **argv = built_argv.get ();
902 for (; *argv != NULL; argv++)
903 {
904 if (**argv == '-')
905 {
906 if (strcmp (*argv, "-copies") == 0)
907 {
908 ++argv;
909 if (!*argv)
910 error (_("No argument to -copies"));
911 copies = parse_and_eval_long (*argv);
912
913 if (copies < 0)
914 error (_("Invalid copies number"));
915 }
916 else if (strcmp (*argv, "-no-connection") == 0)
917 no_connection = true;
918 }
919 else
920 {
921 if (orginf == NULL)
922 {
923 int num;
924
925 /* The first non-option (-) argument specified the
926 program space ID. */
927 num = parse_and_eval_long (*argv);
928 orginf = find_inferior_id (num);
929
930 if (orginf == NULL)
931 error (_("Inferior ID %d not known."), num);
932 continue;
933 }
934 else
935 error (_("Invalid argument"));
936 }
937 }
938 }
939
940 /* If no inferior id was specified, then the user wants to clone the
941 current inferior. */
942 if (orginf == NULL)
943 orginf = current_inferior ();
944
945 scoped_restore_current_pspace_and_thread restore_pspace_thread;
946
947 for (i = 0; i < copies; ++i)
948 {
949 struct address_space *aspace;
950 struct program_space *pspace;
951 struct inferior *inf;
952
953 /* If all inferiors share an address space on this system, this
954 doesn't really return a new address space; otherwise, it
955 really does. */
958 inf = add_inferior (0);
959 inf->pspace = pspace;
960 inf->aspace = pspace->aspace;
961 inf->gdbarch = orginf->gdbarch;
962
963 switch_to_inferior_and_push_target (inf, no_connection, orginf);
964
965 /* If the original inferior had a user specified target
966 description, make the clone use it too. */
967 if (target_desc_info_from_user_p (inf->tdesc_info))
969
971
972 /* Copy properties from the original inferior to the new one. */
973 inf->set_args (orginf->args ());
974 inf->set_cwd (orginf->cwd ());
975 inf->set_tty (orginf->tty ());
976 for (const std::string &set_var : orginf->environment.user_set_env ())
977 {
978 /* set_var has the form NAME=value. Split on the first '='. */
979 const std::string::size_type pos = set_var.find ('=');
980 gdb_assert (pos != std::string::npos);
981 const std::string varname = set_var.substr (0, pos);
982 inf->environment.set
983 (varname.c_str (), orginf->environment.get (varname.c_str ()));
984 }
985 for (const std::string &unset_var
986 : orginf->environment.user_unset_env ())
987 inf->environment.unset (unset_var.c_str ());
988 }
989}
990
991/* Print notices when new inferiors are created and die. */
992static void
993show_print_inferior_events (struct ui_file *file, int from_tty,
994 struct cmd_list_element *c, const char *value)
995{
996 gdb_printf (file, _("Printing of inferior events is %s.\n"), value);
997}
998
999/* Return a new value for the selected inferior's id. */
1000
1001static struct value *
1003 void *ignore)
1004{
1005 struct inferior *inf = current_inferior ();
1006
1007 return value_from_longest (builtin_type (gdbarch)->builtin_int, inf->num);
1008}
1009
1010/* Implementation of `$_inferior' variable. */
1011
1013{
1015 NULL,
1016};
1017
1018
1019
1020void
1022{
1023 struct cmd_list_element *c = NULL;
1024
1025 /* There's always one inferior. Note that this function isn't an
1026 automatic _initialize_foo function, since other _initialize_foo
1027 routines may need to install their per-inferior data keys. We
1028 can only allocate an inferior when all those modules have done
1029 that. Do this after initialize_progspace, due to the
1030 current_program_space reference. */
1034 /* The architecture will be initialized shortly, by
1035 initialize_current_architecture. */
1036
1037 add_info ("inferiors", info_inferiors_command,
1038 _("Print a list of inferiors being managed.\n\
1039Usage: info inferiors [ID]...\n\
1040If IDs are specified, the list is limited to just those inferiors.\n\
1041By default all inferiors are displayed."));
1042
1043 c = add_com ("add-inferior", no_class, add_inferior_command, _("\
1044Add a new inferior.\n\
1045Usage: add-inferior [-copies N] [-exec FILENAME] [-no-connection]\n\
1046N is the optional number of inferiors to add, default is 1.\n\
1047FILENAME is the file name of the executable to use\n\
1048as main program.\n\
1049By default, the new inferior inherits the current inferior's connection.\n\
1050If -no-connection is specified, the new inferior begins with\n\
1051no target connection yet."));
1053
1054 add_com ("remove-inferiors", no_class, remove_inferior_command, _("\
1055Remove inferior ID (or list of IDs).\n\
1056Usage: remove-inferiors ID..."));
1057
1058 add_com ("clone-inferior", no_class, clone_inferior_command, _("\
1059Clone inferior ID.\n\
1060Usage: clone-inferior [-copies N] [-no-connection] [ID]\n\
1061Add N copies of inferior ID. The new inferiors have the same\n\
1062executable loaded as the copied inferior. If -copies is not specified,\n\
1063adds 1 copy. If ID is not specified, it is the current inferior\n\
1064that is cloned.\n\
1065By default, the new inferiors inherit the copied inferior's connection.\n\
1066If -no-connection is specified, the new inferiors begin with\n\
1067no target connection yet."));
1068
1069 add_cmd ("inferiors", class_run, detach_inferior_command, _("\
1070Detach from inferior ID (or list of IDS).\n\
1071Usage; detach inferiors ID..."),
1072 &detachlist);
1073
1074 add_cmd ("inferiors", class_run, kill_inferior_command, _("\
1075Kill inferior ID (or list of IDs).\n\
1076Usage: kill inferiors ID..."),
1077 &killlist);
1078
1079 add_cmd ("inferior", class_run, inferior_command, _("\
1080Use this command to switch between inferiors.\n\
1081Usage: inferior ID\n\
1082The new inferior ID must be currently known."),
1083 &cmdlist);
1084
1085 add_setshow_boolean_cmd ("inferior-events", no_class,
1087Set printing of inferior events (such as inferior start and exit)."), _("\
1088Show printing of inferior events (such as inferior start and exit)."), NULL,
1089 NULL,
1092
1093 create_internalvar_type_lazy ("_inferior", &inferior_funcs, NULL);
1094}
struct gdbarch * gdbarch_find_by_info(struct gdbarch_info info)
ui_file_style style() const
Definition cli-style.c:169
target_ops * top_target()
Definition inferior.h:398
std::string m_terminal
Definition inferior.h:643
void pop_all_targets_above(enum strata stratum)
Definition inferior.c:131
int unpush_target(struct target_ops *t)
Definition inferior.c:98
void unpush_target_and_assert(struct target_ops *target)
Definition inferior.c:119
void do_all_continuations()
Definition inferior.c:177
gdb_environ environment
Definition inferior.h:555
const std::string & cwd() const
Definition inferior.h:515
target_stack m_target_stack
Definition inferior.h:640
void push_target(struct target_ops *t)
Definition inferior.h:376
struct process_stratum_target * process_target()
Definition inferior.h:419
const std::string & args() const
Definition inferior.h:498
void add_continuation(std::function< void()> &&cont)
Definition inferior.c:171
struct address_space * aspace
Definition inferior.h:544
std::unordered_map< ptid_t, thread_info *, hash_ptid > ptid_thread_map
Definition inferior.h:434
void pop_all_targets_at_and_above(enum strata stratum)
Definition inferior.c:146
struct gdbarch * gdbarch
Definition inferior.h:626
const std::string & tty()
Definition inferior.c:165
inf_non_exited_threads_range non_exited_threads()
Definition inferior.h:451
~inferior()
Definition inferior.c:70
void set_tty(std::string terminal_name)
Definition inferior.c:159
intrusive_list< thread_info > thread_list
Definition inferior.h:430
std::list< std::function< void()> > m_continuations
Definition inferior.h:646
void clear_thread_list(bool silent)
Definition inferior.c:223
inferior(int pid)
Definition inferior.c:87
int num
Definition inferior.h:522
struct program_space * pspace
Definition inferior.h:547
bool finished() const
Definition cli-utils.c:327
void maybe_remove_resumed_with_pending_wait_status(thread_info *thread)
void push(target_ops *t)
Definition target.c:1183
bool unpush(target_ops *t)
Definition target.c:1212
target_ops * top() const
Definition target.h:1391
ptid_t ptid
Definition gdbthread.h:256
bool deletable() const
Definition thread.c:332
void field_string(const char *fldname, const char *string, const ui_file_style &style=ui_file_style())
Definition ui-out.c:511
void field_signed(const char *fldname, LONGEST value)
Definition ui-out.c:437
void field_skip(const char *fldname)
Definition ui-out.c:499
void text(const char *string)
Definition ui-out.c:566
void table_header(int width, ui_align align, const std::string &col_name, const std::string &col_hdr)
Definition ui-out.c:363
void table_body()
Definition ui-out.c:376
void message(const char *format,...) ATTRIBUTE_PRINTF(2
Definition ui-out.c:774
struct cmd_list_element * showprintlist
Definition cli-cmds.c:161
struct cmd_list_element * cmdlist
Definition cli-cmds.c:85
struct cmd_list_element * setprintlist
Definition cli-cmds.c:159
struct cmd_list_element * detachlist
Definition cli-cmds.c:109
struct cmd_list_element * killlist
Definition cli-cmds.c:113
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition cli-decode.c:233
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
Definition cli-decode.c:117
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:739
struct cmd_list_element * add_info(const char *name, cmd_simple_func_ftype *fun, const char *doc)
cli_style_option file_name_style
int number_is_in_list(const char *list, int number)
Definition cli-utils.c:348
@ class_run
Definition command.h:54
@ no_class
Definition command.h:53
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
Definition completer.c:204
@ USER_SELECTED_THREAD
Definition defs.h:644
@ USER_SELECTED_FRAME
Definition defs.h:647
@ USER_SELECTED_INFERIOR
Definition defs.h:641
LONGEST parse_and_eval_long(const char *exp)
Definition eval.c:62
void exec_file_attach(const char *filename, int from_tty)
Definition exec.c:365
void reinit_frame_cache(void)
Definition frame.c:2006
bool any_thread_p()
Definition thread.c:578
void set_thread_exited(thread_info *tp, bool silent)
Definition thread.c:195
void switch_to_thread(struct thread_info *thr)
Definition thread.c:1335
struct thread_info * any_thread_of_inferior(inferior *inf)
Definition thread.c:629
#define threads_debug_printf(fmt,...)
Definition gdbthread.h:49
void switch_to_no_thread()
Definition thread.c:1320
void delete_exited_threads(void)
Definition thread.c:734
void init_thread_list(void)
Definition thread.c:233
gdb::ref_ptr< struct inferior, refcounted_object_ref_policy > inferior_ref
Definition gdbthread.h:599
static struct inf * cur_inf(void)
Definition gnu-nat.c:2085
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
Definition gnu-nat.c:1792
void detach_command(const char *args, int from_tty)
Definition infcmd.c:2794
static void add_inferior_command(const char *args, int from_tty)
Definition inferior.c:830
void inferior_appeared(struct inferior *inf, int pid)
Definition inferior.c:322
static void remove_inferior_command(const char *args, int from_tty)
Definition inferior.c:742
struct inferior * add_inferior_silent(int pid)
Definition inferior.c:188
struct inferior * add_inferior_with_spaces(void)
Definition inferior.c:776
void initialize_inferiors(void)
Definition inferior.c:1021
void print_selected_inferior(struct ui_out *uiout)
Definition inferior.c:467
static std::string inferior_pid_to_str(int pid)
Definition inferior.c:456
void exit_inferior(inferior *inf)
Definition inferior.c:294
static inferior_ref current_inferior_
Definition inferior.c:51
struct inferior * find_inferior_ptid(process_stratum_target *targ, ptid_t ptid)
Definition inferior.c:365
static struct value * inferior_id_make_value(struct gdbarch *gdbarch, struct internalvar *var, void *ignore)
Definition inferior.c:1002
struct inferior * find_inferior_pid(process_stratum_target *targ, int pid)
Definition inferior.c:348
static std::string uiout_field_connection(process_stratum_target *proc_target)
Definition inferior.c:483
void set_current_inferior(struct inferior *inf)
Definition inferior.c:60
int number_of_inferiors(void)
Definition inferior.c:446
bool print_inferior_events
Definition inferior.c:46
void delete_inferior(struct inferior *inf)
Definition inferior.c:237
static void clone_inferior_command(const char *args, int from_tty)
Definition inferior.c:891
int have_inferiors(void)
Definition inferior.c:388
static void exit_inferior_1(struct inferior *inf, int silent)
Definition inferior.c:263
static void detach_inferior_command(const char *args, int from_tty)
Definition inferior.c:589
void detach_inferior(inferior *inf)
Definition inferior.c:308
int have_live_inferiors(void)
Definition inferior.c:421
void switch_to_inferior_and_push_target(inferior *new_inf, bool no_connection, inferior *org_inf)
Definition inferior.c:805
static void kill_inferior_command(const char *args, int from_tty)
Definition inferior.c:628
struct inferior * current_inferior(void)
Definition inferior.c:54
struct inferior * add_inferior(int pid)
Definition inferior.c:203
struct inferior * find_inferior_for_program_space(struct program_space *pspace)
Definition inferior.c:373
static int highest_inferior_num
Definition inferior.c:43
void switch_to_inferior_no_thread(inferior *inf)
Definition inferior.c:671
static const struct internalvar_funcs inferior_funcs
Definition inferior.c:1012
static void show_print_inferior_events(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition inferior.c:993
void prune_inferiors(void)
Definition inferior.c:430
static void inferior_command(const char *args, int from_tty)
Definition inferior.c:679
static void print_inferior(struct ui_out *uiout, const char *requested_inferiors)
Definition inferior.c:503
static void info_inferiors_command(const char *args, int from_tty)
Definition inferior.c:734
intrusive_list< inferior > inferior_list
Definition inferior.c:42
int number_of_live_inferiors(process_stratum_target *proc_target)
Definition inferior.c:401
void exit_inferior_silent(inferior *inf)
Definition inferior.c:300
struct inferior * find_inferior_id(int num)
Definition inferior.c:338
all_inferiors_safe_range all_inferiors_safe()
Definition inferior.h:745
all_inferiors_range all_inferiors(process_stratum_target *proc_target=nullptr)
Definition inferior.h:758
@ NO_STOP_QUIETLY
Definition inferior.h:299
inferior * current_inferior()
Definition inferior.c:54
void switch_to_inferior_no_thread(inferior *inf)
Definition inferior.c:671
all_non_exited_inferiors_range all_non_exited_inferiors(process_stratum_target *proc_target=nullptr)
Definition inferior.h:767
observable< struct inferior * > inferior_added
observable< struct inferior * > inferior_exit
observable< struct inferior * > inferior_removed
observable< user_selected_what > user_selected_context_changed
observable< struct inferior * > inferior_appeared
static process_stratum_target * as_process_stratum_target(target_ops *target)
struct program_space * current_program_space
Definition progspace.c:39
void set_current_program_space(struct program_space *pspace)
Definition progspace.c:224
struct program_space * clone_program_space(struct program_space *dest, struct program_space *src)
Definition progspace.c:203
struct address_space * maybe_new_address_space(void)
Definition progspace.c:58
void registers_changed(void)
Definition regcache.c:577
Definition gnu-nat.c:154
pid_t pid
Definition gnu-nat.c:166
virtual ~private_inferior()=0
struct address_space * aspace
Definition progspace.h:335
virtual strata stratum() const =0
const char * shortname() const
Definition target.h:451
Definition value.c:181
@ SYMFILE_VERBOSE
void symbol_file_add_main(const char *args, symfile_add_flags add_flags)
Definition symfile.c:1194
std::string make_target_connection_string(process_stratum_target *t)
void copy_inferior_target_desc_info(struct inferior *destinf, struct inferior *srcinf)
void target_desc_info_free(struct target_desc_info *tdesc_info)
int target_desc_info_from_user_p(struct target_desc_info *info)
void target_kill(void)
Definition target.c:908
target_ops * get_dummy_target()
Definition target.c:3711
std::string target_pid_to_str(ptid_t ptid)
Definition target.c:2602
strata
Definition target.h:89
@ process_stratum
Definition target.h:92
@ dummy_stratum
Definition target.h:90
@ ui_left
Definition ui-out.h:45
#define current_uiout
Definition ui-out.h:40
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1865
struct internalvar * create_internalvar_type_lazy(const char *name, const struct internalvar_funcs *funcs, void *data)
Definition value.c:2200
struct value * value_from_longest(struct type *type, LONGEST num)
Definition value.c:3625