lto: Add a test for PR ld/32083
[binutils-gdb.git] / gdb / linux-nat.h
blobee8603743f664cf8ab138e6b9eb6e3a5a2d6aaf5
1 /* Native debugging support for GNU/Linux (LWP layer).
3 Copyright (C) 2000-2024 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/>. */
20 #ifndef LINUX_NAT_H
21 #define LINUX_NAT_H
23 #include "nat/linux-nat.h"
24 #include "inf-ptrace.h"
25 #include "target.h"
26 #include <signal.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
33 public:
34 linux_nat_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 *, target_wait_flags) override;
51 void pass_signals (gdb::array_view<const unsigned char>) override;
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;
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 bool stopped_by_watchpoint () override;
73 bool stopped_data_address (CORE_ADDR *) override;
75 bool stopped_by_sw_breakpoint () override;
76 bool supports_stopped_by_sw_breakpoint () override;
78 bool stopped_by_hw_breakpoint () override;
79 bool supports_stopped_by_hw_breakpoint () override;
81 void thread_events (bool) override;
83 bool supports_set_thread_options (gdb_thread_options options) override;
85 bool can_async_p () override;
87 bool supports_non_stop () override;
88 bool always_non_stop_p () override;
90 void async (bool) override;
92 void stop (ptid_t) override;
94 bool supports_multi_process () override;
96 bool supports_disable_randomization () override;
98 int core_of_thread (ptid_t ptid) override;
100 bool filesystem_is_local () override;
102 int fileio_open (struct inferior *inf, const char *filename,
103 int flags, int mode, int warn_if_slow,
104 fileio_error *target_errno) override;
106 std::optional<std::string>
107 fileio_readlink (struct inferior *inf,
108 const char *filename,
109 fileio_error *target_errno) override;
111 int fileio_unlink (struct inferior *inf,
112 const char *filename,
113 fileio_error *target_errno) override;
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;
120 int insert_exec_catchpoint (int) override;
121 int remove_exec_catchpoint (int) override;
123 int set_syscall_catchpoint (int pid, bool needed, int any_count,
124 gdb::array_view<const int> syscall_counts) override;
126 const char *pid_to_exec_file (int pid) override;
128 void post_attach (int) override;
130 void follow_fork (inferior *, ptid_t, target_waitkind, bool, bool) override;
132 void follow_clone (ptid_t) override;
134 std::vector<static_tracepoint_marker>
135 static_tracepoint_markers_by_strid (const char *id) override;
137 /* Methods that are meant to overridden by the concrete
138 arch-specific target instance. */
140 virtual void low_resume (ptid_t ptid, int step, enum gdb_signal sig)
141 { inf_ptrace_target::resume (ptid, step, sig); }
143 virtual bool low_stopped_by_watchpoint ()
144 { return false; }
146 virtual bool low_stopped_data_address (CORE_ADDR *addr_p)
147 { return false; }
149 /* The method to call, if any, when a new thread is attached. */
150 virtual void low_new_thread (struct lwp_info *)
153 /* The method to call, if any, when a thread is destroyed. */
154 virtual void low_delete_thread (struct arch_lwp_info *lp)
156 gdb_assert (lp == NULL);
159 /* The method to call, if any, when a new fork is attached. */
160 virtual void low_new_fork (struct lwp_info *parent, pid_t child_pid)
163 /* The method to call, if any, when a new clone event is detected. */
164 virtual void low_new_clone (struct lwp_info *parent, pid_t child_lwp)
167 /* The method to call, if any, when we have a new (from run/attach,
168 not fork) process to debug. The process is ptrace-stopped when
169 this is called. */
170 virtual void low_init_process (pid_t pid)
173 /* The method to call, if any, when a process is no longer
174 attached. */
175 virtual void low_forget_process (pid_t pid)
178 /* Hook to call prior to resuming a thread. */
179 virtual void low_prepare_to_resume (struct lwp_info *)
182 /* Convert a ptrace/host siginfo object, into/from the siginfo in
183 the layout of the inferiors' architecture. Returns true if any
184 conversion was done; false otherwise, in which case the caller
185 does a straight memcpy. If DIRECTION is 1, then copy from INF to
186 PTRACE. If DIRECTION is 0, copy from PTRACE to INF. */
187 virtual bool low_siginfo_fixup (siginfo_t *ptrace, gdb_byte *inf,
188 int direction)
189 { return false; }
191 /* SIGTRAP-like breakpoint status events recognizer. The default
192 recognizes SIGTRAP only. */
193 virtual bool low_status_is_event (int status);
195 protected:
197 void post_startup_inferior (ptid_t) override;
200 /* The final/concrete instance. */
201 extern linux_nat_target *linux_target;
203 struct arch_lwp_info;
205 /* Structure describing an LWP. */
207 struct lwp_info : intrusive_list_node<lwp_info>
209 lwp_info (ptid_t ptid)
210 : ptid (ptid)
213 ~lwp_info ();
215 DISABLE_COPY_AND_ASSIGN (lwp_info);
217 /* The process id of the LWP. This is a combination of the LWP id
218 and overall process id. */
219 ptid_t ptid = null_ptid;
221 /* If this flag is set, we need to set the event request flags the
222 next time we see this LWP stop. */
223 int must_set_ptrace_flags = 0;
225 /* Non-zero if we sent this LWP a SIGSTOP (but the LWP didn't report
226 it back yet). */
227 int signalled = 0;
229 /* Non-zero if this LWP is stopped. */
230 int stopped = 0;
232 /* Non-zero if this LWP will be/has been resumed. Note that an LWP
233 can be marked both as stopped and resumed at the same time. This
234 happens if we try to resume an LWP that has a wait status
235 pending. We shouldn't let the LWP run until that wait status has
236 been processed, but we should not report that wait status if GDB
237 didn't try to let the LWP run. */
238 int resumed = 0;
240 /* The last resume GDB requested on this thread. */
241 resume_kind last_resume_kind = resume_continue;
243 /* If non-zero, a pending wait status. A pending process exit is
244 recorded in WAITSTATUS, because W_EXITCODE(0,0) happens to be
245 0. */
246 int status = 0;
248 /* When 'stopped' is set, this is where the lwp last stopped, with
249 decr_pc_after_break already accounted for. If the LWP is
250 running and stepping, this is the address at which the lwp was
251 resumed (that is, it's the previous stop PC). If the LWP is
252 running and not stepping, this is 0. */
253 CORE_ADDR stop_pc = 0;
255 /* Non-zero if we were stepping this LWP. */
256 int step = 0;
258 /* The reason the LWP last stopped, if we need to track it
259 (breakpoint, watchpoint, etc.). */
260 target_stop_reason stop_reason = TARGET_STOPPED_BY_NO_REASON;
262 /* On architectures where it is possible to know the data address of
263 a triggered watchpoint, STOPPED_DATA_ADDRESS_P is non-zero, and
264 STOPPED_DATA_ADDRESS contains such data address. Otherwise,
265 STOPPED_DATA_ADDRESS_P is false, and STOPPED_DATA_ADDRESS is
266 undefined. Only valid if STOPPED_BY_WATCHPOINT is true. */
267 int stopped_data_address_p = 0;
268 CORE_ADDR stopped_data_address = 0;
270 /* Non-zero if we expect a duplicated SIGINT. */
271 int ignore_sigint = 0;
273 /* If WAITSTATUS->KIND != TARGET_WAITKIND_IGNORE, the waitstatus for
274 this LWP's last event. This usually corresponds to STATUS above,
275 however because W_EXITCODE(0,0) happens to be 0, a process exit
276 will be recorded here, while 'status == 0' is ambiguous. */
277 struct target_waitstatus waitstatus;
279 /* Signal whether we are in a SYSCALL_ENTRY or
280 in a SYSCALL_RETURN event.
281 Values:
282 - TARGET_WAITKIND_SYSCALL_ENTRY
283 - TARGET_WAITKIND_SYSCALL_RETURN */
284 enum target_waitkind syscall_state;
286 /* The processor core this LWP was last seen on. */
287 int core = -1;
289 /* Arch-specific additions. */
290 struct arch_lwp_info *arch_private = nullptr;
293 /* lwp_info iterator and range types. */
295 using lwp_info_iterator
296 = reference_to_pointer_iterator<intrusive_list<lwp_info>::iterator>;
297 using lwp_info_range = iterator_range<lwp_info_iterator>;
298 using lwp_info_safe_range = basic_safe_range<lwp_info_range>;
300 /* Get an iterable range over all lwps. */
302 lwp_info_range all_lwps ();
304 /* Same as the above, but safe against deletion while iterating. */
306 lwp_info_safe_range all_lwps_safe ();
308 /* Called from the LWP layer to inform the thread_db layer that PARENT
309 spawned CHILD. Both LWPs are currently stopped. This function
310 does whatever is required to have the child LWP under the
311 thread_db's control --- e.g., enabling event reporting. Returns
312 true on success, false if the process isn't using libpthread. */
313 extern int thread_db_notice_clone (ptid_t parent, ptid_t child);
315 /* Return the number of signals used by the threads library. */
316 extern unsigned int lin_thread_get_thread_signal_num (void);
318 /* Return the i-th signal used by the threads library. */
319 extern int lin_thread_get_thread_signal (unsigned int i);
321 /* Find process PID's pending signal set from /proc/pid/status. */
322 void linux_proc_pending_signals (int pid, sigset_t *pending,
323 sigset_t *blocked, sigset_t *ignored);
325 /* For linux_stop_lwp see nat/linux-nat.h. */
327 /* Stop all LWPs, synchronously. (Any events that trigger while LWPs
328 are being stopped are left pending.) */
329 extern void linux_stop_and_wait_all_lwps (void);
331 /* Set resumed LWPs running again, as they were before being stopped
332 with linux_stop_and_wait_all_lwps. (LWPS with pending events are
333 left stopped.) */
334 extern void linux_unstop_all_lwps (void);
336 /* Update linux-nat internal state when changing from one fork
337 to another. */
338 void linux_nat_switch_fork (ptid_t new_ptid);
340 /* Store the saved siginfo associated with PTID in *SIGINFO.
341 Return true if it was retrieved successfully, false otherwise (*SIGINFO is
342 uninitialized in such case). */
343 bool linux_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo);
345 #endif /* LINUX_NAT_H */