1 /* Native debugging support for GNU/Linux (LWP layer).
3 Copyright (C) 2000-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
23 #include "nat/linux-nat.h"
24 #include "inf-ptrace.h"
28 /* A prototype generic GNU/Linux target. A concrete instance should
29 override it with local methods. */
31 class linux_nat_target
: public inf_ptrace_target
35 ~linux_nat_target () override
= 0;
37 thread_control_capabilities
get_thread_control_capabilities () override
38 { return tc_schedlock
; }
40 void create_inferior (const char *, const std::string
&,
41 char **, int) override
;
43 void attach (const char *, int) override
;
45 void detach (inferior
*, int) override
;
47 void resume (ptid_t
, int, enum gdb_signal
) override
;
49 ptid_t
wait (ptid_t
, struct target_waitstatus
*, int) override
;
51 void pass_signals (gdb::array_view
<const unsigned char>) override
;
53 enum target_xfer_status
xfer_partial (enum target_object object
,
56 const gdb_byte
*writebuf
,
57 ULONGEST offset
, ULONGEST len
,
58 ULONGEST
*xfered_len
) override
;
60 void kill () override
;
62 void mourn_inferior () override
;
63 bool thread_alive (ptid_t ptid
) override
;
65 void update_thread_list () override
;
67 std::string
pid_to_str (ptid_t
) override
;
69 const char *thread_name (struct thread_info
*) override
;
71 struct address_space
*thread_address_space (ptid_t
) override
;
73 bool stopped_by_watchpoint () override
;
75 bool stopped_data_address (CORE_ADDR
*) override
;
77 bool stopped_by_sw_breakpoint () override
;
78 bool supports_stopped_by_sw_breakpoint () override
;
80 bool stopped_by_hw_breakpoint () override
;
81 bool supports_stopped_by_hw_breakpoint () override
;
83 void thread_events (int) override
;
85 bool can_async_p () override
;
86 bool is_async_p () override
;
88 bool supports_non_stop () override
;
89 bool always_non_stop_p () override
;
91 void async (int) override
;
93 void close () override
;
95 void stop (ptid_t
) override
;
97 bool supports_multi_process () override
;
99 bool supports_disable_randomization () override
;
101 int core_of_thread (ptid_t ptid
) override
;
103 bool filesystem_is_local () override
;
105 int fileio_open (struct inferior
*inf
, const char *filename
,
106 int flags
, int mode
, int warn_if_slow
,
107 int *target_errno
) override
;
109 gdb::optional
<std::string
>
110 fileio_readlink (struct inferior
*inf
,
111 const char *filename
,
112 int *target_errno
) override
;
114 int fileio_unlink (struct inferior
*inf
,
115 const char *filename
,
116 int *target_errno
) override
;
118 int insert_fork_catchpoint (int) override
;
119 int remove_fork_catchpoint (int) override
;
120 int insert_vfork_catchpoint (int) override
;
121 int remove_vfork_catchpoint (int) override
;
123 int insert_exec_catchpoint (int) override
;
124 int remove_exec_catchpoint (int) override
;
126 int set_syscall_catchpoint (int pid
, bool needed
, int any_count
,
127 gdb::array_view
<const int> syscall_counts
) override
;
129 char *pid_to_exec_file (int pid
) override
;
131 void post_startup_inferior (ptid_t
) override
;
133 void post_attach (int) override
;
135 int follow_fork (int, int) override
;
137 std::vector
<static_tracepoint_marker
>
138 static_tracepoint_markers_by_strid (const char *id
) override
;
140 /* Methods that are meant to overridden by the concrete
141 arch-specific target instance. */
143 virtual void low_resume (ptid_t ptid
, int step
, enum gdb_signal sig
)
144 { inf_ptrace_target::resume (ptid
, step
, sig
); }
146 virtual bool low_stopped_by_watchpoint ()
149 virtual bool low_stopped_data_address (CORE_ADDR
*addr_p
)
152 /* The method to call, if any, when a new thread is attached. */
153 virtual void low_new_thread (struct lwp_info
*)
156 /* The method to call, if any, when a thread is destroyed. */
157 virtual void low_delete_thread (struct arch_lwp_info
*lp
)
159 gdb_assert (lp
== NULL
);
162 /* The method to call, if any, when a new fork is attached. */
163 virtual void low_new_fork (struct lwp_info
*parent
, pid_t child_pid
)
166 /* The method to call, if any, when a process is no longer
168 virtual void low_forget_process (pid_t pid
)
171 /* Hook to call prior to resuming a thread. */
172 virtual void low_prepare_to_resume (struct lwp_info
*)
175 /* Convert a ptrace/host siginfo object, into/from the siginfo in
176 the layout of the inferiors' architecture. Returns true if any
177 conversion was done; false otherwise, in which case the caller
178 does a straight memcpy. If DIRECTION is 1, then copy from INF to
179 PTRACE. If DIRECTION is 0, copy from PTRACE to INF. */
180 virtual bool low_siginfo_fixup (siginfo_t
*ptrace
, gdb_byte
*inf
,
184 /* SIGTRAP-like breakpoint status events recognizer. The default
185 recognizes SIGTRAP only. */
186 virtual bool low_status_is_event (int status
);
189 /* The final/concrete instance. */
190 extern linux_nat_target
*linux_target
;
192 struct arch_lwp_info
;
194 /* Structure describing an LWP. This is public only for the purposes
195 of ALL_LWPS; target-specific code should generally not access it
200 /* The process id of the LWP. This is a combination of the LWP id
201 and overall process id. */
204 /* If this flag is set, we need to set the event request flags the
205 next time we see this LWP stop. */
206 int must_set_ptrace_flags
;
208 /* Non-zero if we sent this LWP a SIGSTOP (but the LWP didn't report
212 /* Non-zero if this LWP is stopped. */
215 /* Non-zero if this LWP will be/has been resumed. Note that an LWP
216 can be marked both as stopped and resumed at the same time. This
217 happens if we try to resume an LWP that has a wait status
218 pending. We shouldn't let the LWP run until that wait status has
219 been processed, but we should not report that wait status if GDB
220 didn't try to let the LWP run. */
223 /* The last resume GDB requested on this thread. */
224 enum resume_kind last_resume_kind
;
226 /* If non-zero, a pending wait status. */
229 /* When 'stopped' is set, this is where the lwp last stopped, with
230 decr_pc_after_break already accounted for. If the LWP is
231 running, and stepping, this is the address at which the lwp was
232 resumed (that is, it's the previous stop PC). If the LWP is
233 running and not stepping, this is 0. */
236 /* Non-zero if we were stepping this LWP. */
239 /* The reason the LWP last stopped, if we need to track it
240 (breakpoint, watchpoint, etc.) */
241 enum target_stop_reason stop_reason
;
243 /* On architectures where it is possible to know the data address of
244 a triggered watchpoint, STOPPED_DATA_ADDRESS_P is non-zero, and
245 STOPPED_DATA_ADDRESS contains such data address. Otherwise,
246 STOPPED_DATA_ADDRESS_P is false, and STOPPED_DATA_ADDRESS is
247 undefined. Only valid if STOPPED_BY_WATCHPOINT is true. */
248 int stopped_data_address_p
;
249 CORE_ADDR stopped_data_address
;
251 /* Non-zero if we expect a duplicated SIGINT. */
254 /* If WAITSTATUS->KIND != TARGET_WAITKIND_SPURIOUS, the waitstatus
255 for this LWP's last event. This may correspond to STATUS above,
256 or to a local variable in lin_lwp_wait. */
257 struct target_waitstatus waitstatus
;
259 /* Signal whether we are in a SYSCALL_ENTRY or
260 in a SYSCALL_RETURN event.
262 - TARGET_WAITKIND_SYSCALL_ENTRY
263 - TARGET_WAITKIND_SYSCALL_RETURN */
264 enum target_waitkind syscall_state
;
266 /* The processor core this LWP was last seen on. */
269 /* Arch-specific additions. */
270 struct arch_lwp_info
*arch_private
;
272 /* Previous and next pointers in doubly-linked list of known LWPs,
273 sorted by reverse creation order. */
274 struct lwp_info
*prev
;
275 struct lwp_info
*next
;
278 /* The global list of LWPs, for ALL_LWPS. Unlike the threads list,
279 there is always at least one LWP on the list while the GNU/Linux
280 native target is active. */
281 extern struct lwp_info
*lwp_list
;
283 /* Does the current host support PTRACE_GETREGSET? */
284 extern enum tribool have_ptrace_getregset
;
286 /* Iterate over each active thread (light-weight process). */
287 #define ALL_LWPS(LP) \
288 for ((LP) = lwp_list; \
292 /* Attempt to initialize libthread_db. */
293 void check_for_thread_db (void);
295 /* Called from the LWP layer to inform the thread_db layer that PARENT
296 spawned CHILD. Both LWPs are currently stopped. This function
297 does whatever is required to have the child LWP under the
298 thread_db's control --- e.g., enabling event reporting. Returns
299 true on success, false if the process isn't using libpthread. */
300 extern int thread_db_notice_clone (ptid_t parent
, ptid_t child
);
302 /* Return the set of signals used by the threads library. */
303 extern void lin_thread_get_thread_signals (sigset_t
*mask
);
305 /* Find process PID's pending signal set from /proc/pid/status. */
306 void linux_proc_pending_signals (int pid
, sigset_t
*pending
,
307 sigset_t
*blocked
, sigset_t
*ignored
);
309 /* For linux_stop_lwp see nat/linux-nat.h. */
311 /* Stop all LWPs, synchronously. (Any events that trigger while LWPs
312 are being stopped are left pending.) */
313 extern void linux_stop_and_wait_all_lwps (void);
315 /* Set resumed LWPs running again, as they were before being stopped
316 with linux_stop_and_wait_all_lwps. (LWPS with pending events are
318 extern void linux_unstop_all_lwps (void);
320 /* Update linux-nat internal state when changing from one fork
322 void linux_nat_switch_fork (ptid_t new_ptid
);
324 /* Store the saved siginfo associated with PTID in *SIGINFO.
325 Return 1 if it was retrieved successfully, 0 otherwise (*SIGINFO is
326 uninitialized in such case). */
327 int linux_nat_get_siginfo (ptid_t ptid
, siginfo_t
*siginfo
);
329 #endif /* LINUX_NAT_H */