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