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