ODR warnings for "struct insn_info"
[binutils-gdb.git] / gdb / process-stratum-target.h
1 /* Abstract base class inherited by all process_stratum targets
2
3 Copyright (C) 2018-2022 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 #ifndef PROCESS_STRATUM_TARGET_H
21 #define PROCESS_STRATUM_TARGET_H
22
23 #include "target.h"
24 #include <set>
25 #include "gdbsupport/intrusive_list.h"
26 #include "gdbthread.h"
27
28 /* Abstract base class inherited by all process_stratum targets. */
29
30 class process_stratum_target : public target_ops
31 {
32 public:
33 ~process_stratum_target () override = 0;
34
35 strata stratum () const final override { return process_stratum; }
36
37 /* Return a string representation of this target's open connection.
38 This string is used to distinguish different instances of a given
39 target type. For example, when remote debugging, the target is
40 called "remote", but since we may have more than one remote
41 target open, connection_string() returns the connection serial
42 connection name, e.g., "localhost:10001", "192.168.0.1:20000",
43 etc. This string is shown in several places, e.g., in "info
44 connections" and "info inferiors". */
45 virtual const char *connection_string () { return nullptr; }
46
47 /* We must default these because they must be implemented by any
48 target that can run. */
49 bool can_async_p () override { return false; }
50 bool supports_non_stop () override { return false; }
51 bool supports_disable_randomization () override { return false; }
52
53 /* This default implementation returns the inferior's address
54 space. */
55 struct address_space *thread_address_space (ptid_t ptid) override;
56
57 /* This default implementation always returns target_gdbarch (). */
58 struct gdbarch *thread_architecture (ptid_t ptid) override;
59
60 /* Default implementations for process_stratum targets. Return true
61 if there's a selected inferior, false otherwise. */
62 bool has_all_memory () override;
63 bool has_memory () override;
64 bool has_stack () override;
65 bool has_registers () override;
66 bool has_execution (inferior *inf) override;
67
68 /* Default implementation of follow_exec.
69
70 If the current inferior and FOLLOW_INF are different (execution continues
71 in a new inferior), push this process target to FOLLOW_INF's target stack
72 and add an initial thread to FOLLOW_INF. */
73 void follow_exec (inferior *follow_inf, ptid_t ptid,
74 const char *execd_pathname) override;
75
76 /* Default implementation of follow_fork.
77
78 If a child inferior was created by infrun while following the fork
79 (CHILD_INF is non-nullptr), push this target on CHILD_INF's target stack
80 and add an initial thread with ptid CHILD_PTID. */
81 void follow_fork (inferior *child_inf, ptid_t child_ptid,
82 target_waitkind fork_kind, bool follow_child,
83 bool detach_on_fork) override;
84
85 /* True if any thread is, or may be executing. We need to track
86 this separately because until we fully sync the thread list, we
87 won't know whether the target is fully stopped, even if we see
88 stop events for all known threads, because any of those threads
89 may have spawned new threads we haven't heard of yet. */
90 bool threads_executing = false;
91
92 /* If THREAD is resumed and has a pending wait status, add it to the
93 target's "resumed with pending wait status" list. */
94 void maybe_add_resumed_with_pending_wait_status (thread_info *thread);
95
96 /* If THREAD is resumed and has a pending wait status, remove it from the
97 target's "resumed with pending wait status" list. */
98 void maybe_remove_resumed_with_pending_wait_status (thread_info *thread);
99
100 /* Return true if this target has at least one resumed thread with a pending
101 wait status. */
102 bool has_resumed_with_pending_wait_status () const
103 { return !m_resumed_with_pending_wait_status.empty (); }
104
105 /* Return a random resumed thread with pending wait status belonging to INF
106 and matching FILTER_PTID. */
107 thread_info *random_resumed_with_pending_wait_status
108 (inferior *inf, ptid_t filter_ptid);
109
110 /* The connection number. Visible in "info connections". */
111 int connection_number = 0;
112
113 /* Whether resumed threads must be committed to the target.
114
115 When true, resumed threads must be committed to the execution
116 target.
117
118 When false, the target may leave resumed threads stopped when
119 it's convenient or efficient to do so. When the core requires
120 resumed threads to be committed again, this is set back to true
121 and calls the `commit_resumed` method to allow the target to do
122 so.
123
124 To simplify the implementation of targets, the following methods
125 are guaranteed to be called with COMMIT_RESUMED_STATE set to
126 false:
127
128 - resume
129 - stop
130 - wait
131
132 Knowing this, the target doesn't need to implement different
133 behaviors depending on the COMMIT_RESUMED_STATE, and can simply
134 assume that it is false.
135
136 Targets can take advantage of this to batch resumption requests,
137 for example. In that case, the target doesn't actually resume in
138 its `resume` implementation. Instead, it takes note of the
139 resumption intent in `resume` and defers the actual resumption to
140 `commit_resumed`. For example, the remote target uses this to
141 coalesce multiple resumption requests in a single vCont
142 packet. */
143 bool commit_resumed_state = false;
144
145 private:
146 /* List of threads managed by this target which simultaneously are resumed
147 and have a pending wait status.
148
149 This is done for optimization reasons, it would be possible to walk the
150 inferior thread lists to find these threads. But since this is something
151 we need to do quite frequently in the hot path, maintaining this list
152 avoids walking the thread lists repeatedly. */
153 thread_info_resumed_with_pending_wait_status_list
154 m_resumed_with_pending_wait_status;
155 };
156
157 /* Downcast TARGET to process_stratum_target. */
158
159 static inline process_stratum_target *
160 as_process_stratum_target (target_ops *target)
161 {
162 gdb_assert (target->stratum () == process_stratum);
163 return static_cast<process_stratum_target *> (target);
164 }
165
166 /* Return a collection of targets that have non-exited inferiors. */
167
168 extern std::set<process_stratum_target *> all_non_exited_process_targets ();
169
170 /* Switch to the first inferior (and program space) of TARGET, and
171 switch to no thread selected. */
172
173 extern void switch_to_target_no_thread (process_stratum_target *target);
174
175 #endif /* !defined (PROCESS_STRATUM_TARGET_H) */