Commit | Line | Data |
---|---|---|
3b3dac9b PA |
1 | /* Abstract base class inherited by all process_stratum targets |
2 | ||
3666a048 | 3 | Copyright (C) 2018-2021 Free Software Foundation, Inc. |
3b3dac9b PA |
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 "process-stratum-target.h" | |
22 | #include "inferior.h" | |
23 | ||
24 | process_stratum_target::~process_stratum_target () | |
25 | { | |
26 | } | |
27 | ||
28 | struct address_space * | |
29 | process_stratum_target::thread_address_space (ptid_t ptid) | |
30 | { | |
31 | /* Fall-back to the "main" address space of the inferior. */ | |
5b6d1e4f | 32 | inferior *inf = find_inferior_ptid (this, ptid); |
3b3dac9b PA |
33 | |
34 | if (inf == NULL || inf->aspace == NULL) | |
35 | internal_error (__FILE__, __LINE__, | |
36 | _("Can't determine the current " | |
37 | "address space of thread %s\n"), | |
a068643d | 38 | target_pid_to_str (ptid).c_str ()); |
3b3dac9b PA |
39 | |
40 | return inf->aspace; | |
41 | } | |
42 | ||
43 | struct gdbarch * | |
44 | process_stratum_target::thread_architecture (ptid_t ptid) | |
45 | { | |
5b6d1e4f | 46 | inferior *inf = find_inferior_ptid (this, ptid); |
3b3dac9b PA |
47 | gdb_assert (inf != NULL); |
48 | return inf->gdbarch; | |
49 | } | |
f3d11a9a PA |
50 | |
51 | bool | |
52 | process_stratum_target::has_all_memory () | |
53 | { | |
54 | /* If no inferior selected, then we can't read memory here. */ | |
55 | return inferior_ptid != null_ptid; | |
56 | } | |
57 | ||
58 | bool | |
59 | process_stratum_target::has_memory () | |
60 | { | |
61 | /* If no inferior selected, then we can't read memory here. */ | |
62 | return inferior_ptid != null_ptid; | |
63 | } | |
64 | ||
65 | bool | |
66 | process_stratum_target::has_stack () | |
67 | { | |
68 | /* If no inferior selected, there's no stack. */ | |
69 | return inferior_ptid != null_ptid; | |
70 | } | |
71 | ||
72 | bool | |
73 | process_stratum_target::has_registers () | |
74 | { | |
75 | /* Can't read registers from no inferior. */ | |
76 | return inferior_ptid != null_ptid; | |
77 | } | |
78 | ||
79 | bool | |
5018ce90 | 80 | process_stratum_target::has_execution (inferior *inf) |
f3d11a9a | 81 | { |
5018ce90 PA |
82 | /* If there's a process running already, we can't make it run |
83 | through hoops. */ | |
84 | return inf->pid != 0; | |
f3d11a9a | 85 | } |
d890404b | 86 | |
294c36eb SM |
87 | void |
88 | process_stratum_target::follow_exec (inferior *follow_inf, ptid_t ptid, | |
89 | const char *execd_pathname) | |
90 | { | |
91 | inferior *orig_inf = current_inferior (); | |
92 | ||
93 | if (orig_inf != follow_inf) | |
94 | { | |
95 | /* Execution continues in a new inferior, push the original inferior's | |
96 | process target on the new inferior's target stack. The process target | |
97 | may decide to unpush itself from the original inferior's target stack | |
98 | after that, at its discretion. */ | |
99 | follow_inf->push_target (orig_inf->process_target ()); | |
100 | thread_info *t = add_thread (follow_inf->process_target (), ptid); | |
101 | ||
102 | /* Leave the new inferior / thread as the current inferior / thread. */ | |
103 | switch_to_thread (t); | |
104 | } | |
105 | } | |
106 | ||
d890404b TBA |
107 | /* See process-stratum-target.h. */ |
108 | ||
109 | std::set<process_stratum_target *> | |
110 | all_non_exited_process_targets () | |
111 | { | |
112 | /* Inferiors may share targets. To eliminate duplicates, use a set. */ | |
113 | std::set<process_stratum_target *> targets; | |
114 | for (inferior *inf : all_non_exited_inferiors ()) | |
115 | targets.insert (inf->process_target ()); | |
116 | ||
117 | return targets; | |
118 | } | |
119 | ||
120 | /* See process-stratum-target.h. */ | |
121 | ||
122 | void | |
123 | switch_to_target_no_thread (process_stratum_target *target) | |
124 | { | |
125 | for (inferior *inf : all_inferiors (target)) | |
126 | { | |
127 | switch_to_inferior_no_thread (inf); | |
128 | break; | |
129 | } | |
130 | } |