Commit | Line | Data |
---|---|---|
0274a8ce | 1 | /* Native debugging support for GNU/Linux (LWP layer). |
10d6c8cd | 2 | |
b811d2c2 | 3 | Copyright (C) 2000-2020 Free Software Foundation, Inc. |
0274a8ce MS |
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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
0274a8ce MS |
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 | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
0274a8ce | 19 | |
1a5c2598 TT |
20 | #ifndef LINUX_NAT_H |
21 | #define LINUX_NAT_H | |
22 | ||
6d4ee8c6 | 23 | #include "nat/linux-nat.h" |
f6ac5f3d | 24 | #include "inf-ptrace.h" |
a2f23071 | 25 | #include "target.h" |
9f0bdab8 DJ |
26 | #include <signal.h> |
27 | ||
f6ac5f3d PA |
28 | /* A prototype generic GNU/Linux target. A concrete instance should |
29 | override it with local methods. */ | |
30 | ||
31 | class linux_nat_target : public inf_ptrace_target | |
32 | { | |
33 | public: | |
34 | linux_nat_target (); | |
35 | ~linux_nat_target () override = 0; | |
36 | ||
37 | thread_control_capabilities get_thread_control_capabilities () override | |
38 | { return tc_schedlock; } | |
39 | ||
40 | void create_inferior (const char *, const std::string &, | |
41 | char **, int) override; | |
42 | ||
43 | void attach (const char *, int) override; | |
44 | ||
45 | void detach (inferior *, int) override; | |
46 | ||
47 | void resume (ptid_t, int, enum gdb_signal) override; | |
48 | ||
49 | ptid_t wait (ptid_t, struct target_waitstatus *, int) override; | |
50 | ||
adc6a863 | 51 | void pass_signals (gdb::array_view<const unsigned char>) override; |
f6ac5f3d PA |
52 | |
53 | enum target_xfer_status xfer_partial (enum target_object object, | |
54 | const char *annex, | |
55 | gdb_byte *readbuf, | |
56 | const gdb_byte *writebuf, | |
57 | ULONGEST offset, ULONGEST len, | |
58 | ULONGEST *xfered_len) override; | |
59 | ||
60 | void kill () override; | |
61 | ||
62 | void mourn_inferior () override; | |
57810aa7 | 63 | bool thread_alive (ptid_t ptid) override; |
f6ac5f3d PA |
64 | |
65 | void update_thread_list () override; | |
66 | ||
a068643d | 67 | std::string pid_to_str (ptid_t) override; |
f6ac5f3d PA |
68 | |
69 | const char *thread_name (struct thread_info *) override; | |
70 | ||
71 | struct address_space *thread_address_space (ptid_t) override; | |
72 | ||
57810aa7 | 73 | bool stopped_by_watchpoint () override; |
f6ac5f3d | 74 | |
57810aa7 | 75 | bool stopped_data_address (CORE_ADDR *) override; |
f6ac5f3d | 76 | |
57810aa7 PA |
77 | bool stopped_by_sw_breakpoint () override; |
78 | bool supports_stopped_by_sw_breakpoint () override; | |
f6ac5f3d | 79 | |
57810aa7 PA |
80 | bool stopped_by_hw_breakpoint () override; |
81 | bool supports_stopped_by_hw_breakpoint () override; | |
f6ac5f3d PA |
82 | |
83 | void thread_events (int) override; | |
84 | ||
57810aa7 PA |
85 | bool can_async_p () override; |
86 | bool is_async_p () override; | |
f6ac5f3d | 87 | |
57810aa7 PA |
88 | bool supports_non_stop () override; |
89 | bool always_non_stop_p () override; | |
f6ac5f3d | 90 | |
5b6d1e4f | 91 | int async_wait_fd () override; |
f6ac5f3d PA |
92 | void async (int) override; |
93 | ||
94 | void close () override; | |
95 | ||
96 | void stop (ptid_t) override; | |
97 | ||
57810aa7 | 98 | bool supports_multi_process () override; |
f6ac5f3d | 99 | |
57810aa7 | 100 | bool supports_disable_randomization () override; |
f6ac5f3d PA |
101 | |
102 | int core_of_thread (ptid_t ptid) override; | |
103 | ||
57810aa7 | 104 | bool filesystem_is_local () override; |
f6ac5f3d PA |
105 | |
106 | int fileio_open (struct inferior *inf, const char *filename, | |
107 | int flags, int mode, int warn_if_slow, | |
108 | int *target_errno) override; | |
109 | ||
110 | gdb::optional<std::string> | |
111 | fileio_readlink (struct inferior *inf, | |
112 | const char *filename, | |
113 | int *target_errno) override; | |
114 | ||
115 | int fileio_unlink (struct inferior *inf, | |
116 | const char *filename, | |
117 | int *target_errno) override; | |
118 | ||
119 | int insert_fork_catchpoint (int) override; | |
120 | int remove_fork_catchpoint (int) override; | |
121 | int insert_vfork_catchpoint (int) override; | |
122 | int remove_vfork_catchpoint (int) override; | |
123 | ||
124 | int insert_exec_catchpoint (int) override; | |
125 | int remove_exec_catchpoint (int) override; | |
126 | ||
127 | int set_syscall_catchpoint (int pid, bool needed, int any_count, | |
128 | gdb::array_view<const int> syscall_counts) override; | |
129 | ||
130 | char *pid_to_exec_file (int pid) override; | |
131 | ||
132 | void post_startup_inferior (ptid_t) override; | |
133 | ||
134 | void post_attach (int) override; | |
135 | ||
136 | int follow_fork (int, int) override; | |
137 | ||
138 | std::vector<static_tracepoint_marker> | |
139 | static_tracepoint_markers_by_strid (const char *id) override; | |
140 | ||
141 | /* Methods that are meant to overridden by the concrete | |
142 | arch-specific target instance. */ | |
143 | ||
144 | virtual void low_resume (ptid_t ptid, int step, enum gdb_signal sig) | |
145 | { inf_ptrace_target::resume (ptid, step, sig); } | |
146 | ||
57810aa7 PA |
147 | virtual bool low_stopped_by_watchpoint () |
148 | { return false; } | |
f6ac5f3d | 149 | |
57810aa7 PA |
150 | virtual bool low_stopped_data_address (CORE_ADDR *addr_p) |
151 | { return false; } | |
135340af PA |
152 | |
153 | /* The method to call, if any, when a new thread is attached. */ | |
154 | virtual void low_new_thread (struct lwp_info *) | |
155 | {} | |
156 | ||
157 | /* The method to call, if any, when a thread is destroyed. */ | |
158 | virtual void low_delete_thread (struct arch_lwp_info *lp) | |
159 | { | |
160 | gdb_assert (lp == NULL); | |
161 | } | |
162 | ||
163 | /* The method to call, if any, when a new fork is attached. */ | |
164 | virtual void low_new_fork (struct lwp_info *parent, pid_t child_pid) | |
165 | {} | |
166 | ||
167 | /* The method to call, if any, when a process is no longer | |
168 | attached. */ | |
169 | virtual void low_forget_process (pid_t pid) | |
170 | {} | |
171 | ||
172 | /* Hook to call prior to resuming a thread. */ | |
173 | virtual void low_prepare_to_resume (struct lwp_info *) | |
174 | {} | |
175 | ||
176 | /* Convert a ptrace/host siginfo object, into/from the siginfo in | |
177 | the layout of the inferiors' architecture. Returns true if any | |
178 | conversion was done; false otherwise, in which case the caller | |
179 | does a straight memcpy. If DIRECTION is 1, then copy from INF to | |
180 | PTRACE. If DIRECTION is 0, copy from PTRACE to INF. */ | |
181 | virtual bool low_siginfo_fixup (siginfo_t *ptrace, gdb_byte *inf, | |
182 | int direction) | |
183 | { return false; } | |
184 | ||
185 | /* SIGTRAP-like breakpoint status events recognizer. The default | |
186 | recognizes SIGTRAP only. */ | |
187 | virtual bool low_status_is_event (int status); | |
f6ac5f3d PA |
188 | }; |
189 | ||
190 | /* The final/concrete instance. */ | |
191 | extern linux_nat_target *linux_target; | |
192 | ||
7b50312a PA |
193 | struct arch_lwp_info; |
194 | ||
9f0bdab8 DJ |
195 | /* Structure describing an LWP. This is public only for the purposes |
196 | of ALL_LWPS; target-specific code should generally not access it | |
197 | directly. */ | |
0274a8ce MS |
198 | |
199 | struct lwp_info | |
200 | { | |
201 | /* The process id of the LWP. This is a combination of the LWP id | |
202 | and overall process id. */ | |
203 | ptid_t ptid; | |
204 | ||
8784d563 PA |
205 | /* If this flag is set, we need to set the event request flags the |
206 | next time we see this LWP stop. */ | |
207 | int must_set_ptrace_flags; | |
208 | ||
0274a8ce MS |
209 | /* Non-zero if we sent this LWP a SIGSTOP (but the LWP didn't report |
210 | it back yet). */ | |
211 | int signalled; | |
212 | ||
213 | /* Non-zero if this LWP is stopped. */ | |
214 | int stopped; | |
215 | ||
216 | /* Non-zero if this LWP will be/has been resumed. Note that an LWP | |
217 | can be marked both as stopped and resumed at the same time. This | |
218 | happens if we try to resume an LWP that has a wait status | |
219 | pending. We shouldn't let the LWP run until that wait status has | |
220 | been processed, but we should not report that wait status if GDB | |
221 | didn't try to let the LWP run. */ | |
222 | int resumed; | |
223 | ||
25289eb2 PA |
224 | /* The last resume GDB requested on this thread. */ |
225 | enum resume_kind last_resume_kind; | |
226 | ||
0274a8ce MS |
227 | /* If non-zero, a pending wait status. */ |
228 | int status; | |
229 | ||
9c02b525 PA |
230 | /* When 'stopped' is set, this is where the lwp last stopped, with |
231 | decr_pc_after_break already accounted for. If the LWP is | |
7da6a5b9 | 232 | running and stepping, this is the address at which the lwp was |
9c02b525 PA |
233 | resumed (that is, it's the previous stop PC). If the LWP is |
234 | running and not stepping, this is 0. */ | |
235 | CORE_ADDR stop_pc; | |
236 | ||
0274a8ce MS |
237 | /* Non-zero if we were stepping this LWP. */ |
238 | int step; | |
239 | ||
9c02b525 | 240 | /* The reason the LWP last stopped, if we need to track it |
7da6a5b9 | 241 | (breakpoint, watchpoint, etc.). */ |
15c66dd6 | 242 | enum target_stop_reason stop_reason; |
ebec9a0f PA |
243 | |
244 | /* On architectures where it is possible to know the data address of | |
245 | a triggered watchpoint, STOPPED_DATA_ADDRESS_P is non-zero, and | |
246 | STOPPED_DATA_ADDRESS contains such data address. Otherwise, | |
247 | STOPPED_DATA_ADDRESS_P is false, and STOPPED_DATA_ADDRESS is | |
248 | undefined. Only valid if STOPPED_BY_WATCHPOINT is true. */ | |
249 | int stopped_data_address_p; | |
250 | CORE_ADDR stopped_data_address; | |
251 | ||
57380f4e DJ |
252 | /* Non-zero if we expect a duplicated SIGINT. */ |
253 | int ignore_sigint; | |
254 | ||
a2f23071 DJ |
255 | /* If WAITSTATUS->KIND != TARGET_WAITKIND_SPURIOUS, the waitstatus |
256 | for this LWP's last event. This may correspond to STATUS above, | |
257 | or to a local variable in lin_lwp_wait. */ | |
258 | struct target_waitstatus waitstatus; | |
259 | ||
82075af2 | 260 | /* Signal whether we are in a SYSCALL_ENTRY or |
a96d9b2e SDJ |
261 | in a SYSCALL_RETURN event. |
262 | Values: | |
263 | - TARGET_WAITKIND_SYSCALL_ENTRY | |
264 | - TARGET_WAITKIND_SYSCALL_RETURN */ | |
f486487f | 265 | enum target_waitkind syscall_state; |
a96d9b2e | 266 | |
dc146f7c VP |
267 | /* The processor core this LWP was last seen on. */ |
268 | int core; | |
269 | ||
7b50312a PA |
270 | /* Arch-specific additions. */ |
271 | struct arch_lwp_info *arch_private; | |
272 | ||
774113b0 PA |
273 | /* Previous and next pointers in doubly-linked list of known LWPs, |
274 | sorted by reverse creation order. */ | |
275 | struct lwp_info *prev; | |
0274a8ce MS |
276 | struct lwp_info *next; |
277 | }; | |
278 | ||
9f0bdab8 DJ |
279 | /* The global list of LWPs, for ALL_LWPS. Unlike the threads list, |
280 | there is always at least one LWP on the list while the GNU/Linux | |
281 | native target is active. */ | |
282 | extern struct lwp_info *lwp_list; | |
283 | ||
433bbbf8 | 284 | /* Does the current host support PTRACE_GETREGSET? */ |
0bdb2f78 | 285 | extern enum tribool have_ptrace_getregset; |
433bbbf8 | 286 | |
4c38200f PA |
287 | /* Iterate over each active thread (light-weight process). */ |
288 | #define ALL_LWPS(LP) \ | |
289 | for ((LP) = lwp_list; \ | |
9f0bdab8 | 290 | (LP) != NULL; \ |
4c38200f | 291 | (LP) = (LP)->next) |
9f0bdab8 | 292 | |
0ec9a092 DJ |
293 | /* Attempt to initialize libthread_db. */ |
294 | void check_for_thread_db (void); | |
0274a8ce | 295 | |
2db9a427 PA |
296 | /* Called from the LWP layer to inform the thread_db layer that PARENT |
297 | spawned CHILD. Both LWPs are currently stopped. This function | |
298 | does whatever is required to have the child LWP under the | |
299 | thread_db's control --- e.g., enabling event reporting. Returns | |
300 | true on success, false if the process isn't using libpthread. */ | |
301 | extern int thread_db_notice_clone (ptid_t parent, ptid_t child); | |
4c28f408 | 302 | |
669211f5 UW |
303 | /* Return the set of signals used by the threads library. */ |
304 | extern void lin_thread_get_thread_signals (sigset_t *mask); | |
305 | ||
bfb39158 | 306 | /* Find process PID's pending signal set from /proc/pid/status. */ |
3e43a32a MS |
307 | void linux_proc_pending_signals (int pid, sigset_t *pending, |
308 | sigset_t *blocked, sigset_t *ignored); | |
bfb39158 | 309 | |
b2f7c7e8 | 310 | /* For linux_stop_lwp see nat/linux-nat.h. */ |
7b50312a | 311 | |
2db9a427 PA |
312 | /* Stop all LWPs, synchronously. (Any events that trigger while LWPs |
313 | are being stopped are left pending.) */ | |
314 | extern void linux_stop_and_wait_all_lwps (void); | |
315 | ||
316 | /* Set resumed LWPs running again, as they were before being stopped | |
317 | with linux_stop_and_wait_all_lwps. (LWPS with pending events are | |
318 | left stopped.) */ | |
319 | extern void linux_unstop_all_lwps (void); | |
320 | ||
f973ed9c DJ |
321 | /* Update linux-nat internal state when changing from one fork |
322 | to another. */ | |
323 | void linux_nat_switch_fork (ptid_t new_ptid); | |
9f0bdab8 | 324 | |
f865ee35 JK |
325 | /* Store the saved siginfo associated with PTID in *SIGINFO. |
326 | Return 1 if it was retrieved successfully, 0 otherwise (*SIGINFO is | |
327 | uninitialized in such case). */ | |
328 | int linux_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo); | |
1a5c2598 TT |
329 | |
330 | #endif /* LINUX_NAT_H */ |