GDB (xrefs)
Loading...
Searching...
No Matches
linux-nat.h
Go to the documentation of this file.
1/* Native debugging support for GNU/Linux (LWP layer).
2
3 Copyright (C) 2000-2023 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 LINUX_NAT_H
21#define LINUX_NAT_H
22
23#include "nat/linux-nat.h"
24#include "inf-ptrace.h"
25#include "target.h"
26#include <signal.h>
27
28/* A prototype generic GNU/Linux target. A concrete instance should
29 override it with local methods. */
30
32{
33public:
35 ~linux_nat_target () override = 0;
36
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 *, target_wait_flags) override;
50
51 void pass_signals (gdb::array_view<const unsigned char>) override;
52
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;
63 bool thread_alive (ptid_t ptid) override;
64
65 void update_thread_list () override;
66
67 std::string pid_to_str (ptid_t) override;
68
69 const char *thread_name (struct thread_info *) override;
70
71 struct address_space *thread_address_space (ptid_t) override;
72
73 bool stopped_by_watchpoint () override;
74
75 bool stopped_data_address (CORE_ADDR *) override;
76
77 bool stopped_by_sw_breakpoint () override;
78 bool supports_stopped_by_sw_breakpoint () override;
79
80 bool stopped_by_hw_breakpoint () override;
81 bool supports_stopped_by_hw_breakpoint () override;
82
83 void thread_events (int) override;
84
85 bool can_async_p () override;
86
87 bool supports_non_stop () override;
88 bool always_non_stop_p () override;
89
90 void async (bool) override;
91
92 void stop (ptid_t) override;
93
94 bool supports_multi_process () override;
95
96 bool supports_disable_randomization () override;
97
98 int core_of_thread (ptid_t ptid) override;
99
100 bool 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 fileio_error *target_errno) override;
105
106 gdb::optional<std::string>
108 const char *filename,
109 fileio_error *target_errno) override;
110
111 int fileio_unlink (struct inferior *inf,
112 const char *filename,
113 fileio_error *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 const char *pid_to_exec_file (int pid) override;
127
128 void post_attach (int) override;
129
130 void follow_fork (inferior *, ptid_t, target_waitkind, bool, bool) override;
131
132 std::vector<static_tracepoint_marker>
133 static_tracepoint_markers_by_strid (const char *id) override;
134
135 /* Methods that are meant to overridden by the concrete
136 arch-specific target instance. */
137
138 virtual void low_resume (ptid_t ptid, int step, enum gdb_signal sig)
139 { inf_ptrace_target::resume (ptid, step, sig); }
140
142 { return false; }
143
144 virtual bool low_stopped_data_address (CORE_ADDR *addr_p)
145 { return false; }
146
147 /* The method to call, if any, when a new thread is attached. */
148 virtual void low_new_thread (struct lwp_info *)
149 {}
150
151 /* The method to call, if any, when a thread is destroyed. */
152 virtual void low_delete_thread (struct arch_lwp_info *lp)
153 {
154 gdb_assert (lp == NULL);
155 }
156
157 /* The method to call, if any, when a new fork is attached. */
158 virtual void low_new_fork (struct lwp_info *parent, pid_t child_pid)
159 {}
160
161 /* The method to call, if any, when a new clone event is detected. */
162 virtual void low_new_clone (struct lwp_info *parent, pid_t child_lwp)
163 {}
164
165 /* The method to call, if any, when a process is no longer
166 attached. */
167 virtual void low_forget_process (pid_t pid)
168 {}
169
170 /* Hook to call prior to resuming a thread. */
171 virtual void low_prepare_to_resume (struct lwp_info *)
172 {}
173
174 /* Convert a ptrace/host siginfo object, into/from the siginfo in
175 the layout of the inferiors' architecture. Returns true if any
176 conversion was done; false otherwise, in which case the caller
177 does a straight memcpy. If DIRECTION is 1, then copy from INF to
178 PTRACE. If DIRECTION is 0, copy from PTRACE to INF. */
179 virtual bool low_siginfo_fixup (siginfo_t *ptrace, gdb_byte *inf,
180 int direction)
181 { return false; }
182
183 /* SIGTRAP-like breakpoint status events recognizer. The default
184 recognizes SIGTRAP only. */
185 virtual bool low_status_is_event (int status);
186
187protected:
188
189 void post_startup_inferior (ptid_t) override;
190};
191
192/* The final/concrete instance. */
194
195struct arch_lwp_info;
196
197/* Structure describing an LWP. */
198
199struct lwp_info : intrusive_list_node<lwp_info>
200{
201 lwp_info (ptid_t ptid)
202 : ptid (ptid)
203 {}
204
205 ~lwp_info ();
206
208
209 /* The process id of the LWP. This is a combination of the LWP id
210 and overall process id. */
211 ptid_t ptid = null_ptid;
212
213 /* If this flag is set, we need to set the event request flags the
214 next time we see this LWP stop. */
216
217 /* Non-zero if we sent this LWP a SIGSTOP (but the LWP didn't report
218 it back yet). */
219 int signalled = 0;
220
221 /* Non-zero if this LWP is stopped. */
222 int stopped = 0;
223
224 /* Non-zero if this LWP will be/has been resumed. Note that an LWP
225 can be marked both as stopped and resumed at the same time. This
226 happens if we try to resume an LWP that has a wait status
227 pending. We shouldn't let the LWP run until that wait status has
228 been processed, but we should not report that wait status if GDB
229 didn't try to let the LWP run. */
230 int resumed = 0;
231
232 /* The last resume GDB requested on this thread. */
234
235 /* If non-zero, a pending wait status. */
236 int status = 0;
237
238 /* When 'stopped' is set, this is where the lwp last stopped, with
239 decr_pc_after_break already accounted for. If the LWP is
240 running and stepping, this is the address at which the lwp was
241 resumed (that is, it's the previous stop PC). If the LWP is
242 running and not stepping, this is 0. */
243 CORE_ADDR stop_pc = 0;
244
245 /* Non-zero if we were stepping this LWP. */
246 int step = 0;
247
248 /* The reason the LWP last stopped, if we need to track it
249 (breakpoint, watchpoint, etc.). */
251
252 /* On architectures where it is possible to know the data address of
253 a triggered watchpoint, STOPPED_DATA_ADDRESS_P is non-zero, and
254 STOPPED_DATA_ADDRESS contains such data address. Otherwise,
255 STOPPED_DATA_ADDRESS_P is false, and STOPPED_DATA_ADDRESS is
256 undefined. Only valid if STOPPED_BY_WATCHPOINT is true. */
258 CORE_ADDR stopped_data_address = 0;
259
260 /* Non-zero if we expect a duplicated SIGINT. */
262
263 /* If WAITSTATUS->KIND != TARGET_WAITKIND_SPURIOUS, the waitstatus
264 for this LWP's last event. This may correspond to STATUS above,
265 or to a local variable in lin_lwp_wait. */
267
268 /* Signal whether we are in a SYSCALL_ENTRY or
269 in a SYSCALL_RETURN event.
270 Values:
271 - TARGET_WAITKIND_SYSCALL_ENTRY
272 - TARGET_WAITKIND_SYSCALL_RETURN */
274
275 /* The processor core this LWP was last seen on. */
276 int core = -1;
277
278 /* Arch-specific additions. */
279 struct arch_lwp_info *arch_private = nullptr;
280};
281
282/* lwp_info iterator and range types. */
283
285 = reference_to_pointer_iterator<intrusive_list<lwp_info>::iterator>;
286using lwp_info_range = iterator_range<lwp_info_iterator>;
287using lwp_info_safe_range = basic_safe_range<lwp_info_range>;
288
289/* Get an iterable range over all lwps. */
290
292
293/* Same as the above, but safe against deletion while iterating. */
294
296
297/* Does the current host support PTRACE_GETREGSET? */
298extern enum tribool have_ptrace_getregset;
299
300/* Called from the LWP layer to inform the thread_db layer that PARENT
301 spawned CHILD. Both LWPs are currently stopped. This function
302 does whatever is required to have the child LWP under the
303 thread_db's control --- e.g., enabling event reporting. Returns
304 true on success, false if the process isn't using libpthread. */
305extern int thread_db_notice_clone (ptid_t parent, ptid_t child);
306
307/* Return the number of signals used by the threads library. */
308extern unsigned int lin_thread_get_thread_signal_num (void);
309
310/* Return the i-th signal used by the threads library. */
311extern int lin_thread_get_thread_signal (unsigned int i);
312
313/* Find process PID's pending signal set from /proc/pid/status. */
314void linux_proc_pending_signals (int pid, sigset_t *pending,
315 sigset_t *blocked, sigset_t *ignored);
316
317/* For linux_stop_lwp see nat/linux-nat.h. */
318
319/* Stop all LWPs, synchronously. (Any events that trigger while LWPs
320 are being stopped are left pending.) */
321extern void linux_stop_and_wait_all_lwps (void);
322
323/* Set resumed LWPs running again, as they were before being stopped
324 with linux_stop_and_wait_all_lwps. (LWPS with pending events are
325 left stopped.) */
326extern void linux_unstop_all_lwps (void);
327
328/* Update linux-nat internal state when changing from one fork
329 to another. */
330void linux_nat_switch_fork (ptid_t new_ptid);
331
332/* Store the saved siginfo associated with PTID in *SIGINFO.
333 Return true if it was retrieved successfully, false otherwise (*SIGINFO is
334 uninitialized in such case). */
335bool linux_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo);
336
337#endif /* LINUX_NAT_H */
gdb::optional< std::string > fileio_readlink(struct inferior *inf, const char *filename, fileio_error *target_errno) override
Definition linux-nat.c:4393
struct address_space * thread_address_space(ptid_t) override
Definition linux-nat.c:4298
void kill() override
Definition linux-nat.c:3540
void post_startup_inferior(ptid_t) override
Definition linux-nat.c:390
int core_of_thread(ptid_t ptid) override
Definition linux-nat.c:4325
bool always_non_stop_p() override
Definition linux-nat.c:4166
virtual void low_prepare_to_resume(struct lwp_info *)
Definition linux-nat.h:171
thread_control_capabilities get_thread_control_capabilities() override
Definition linux-nat.h:37
bool thread_alive(ptid_t ptid) override
Definition linux-nat.c:3722
bool supports_stopped_by_sw_breakpoint() override
Definition linux-nat.c:2651
void attach(const char *, int) override
Definition linux-nat.c:1057
void post_attach(int) override
Definition linux-nat.c:382
virtual bool low_status_is_event(int status)
Definition linux-nat.c:2327
~linux_nat_target() override=0
Definition linux-nat.c:378
void resume(ptid_t, int, enum gdb_signal) override
Definition linux-nat.c:1599
int insert_exec_catchpoint(int) override
Definition linux-nat.c:545
virtual void low_new_thread(struct lwp_info *)
Definition linux-nat.h:148
std::string pid_to_str(ptid_t) override
Definition linux-nat.c:3752
const char * pid_to_exec_file(int pid) override
Definition linux-nat.c:3772
bool can_async_p() override
Definition linux-nat.c:4148
int fileio_open(struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, fileio_error *target_errno) override
Definition linux-nat.c:4367
int fileio_unlink(struct inferior *inf, const char *filename, fileio_error *target_errno) override
Definition linux-nat.c:4413
ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags) override
Definition linux-nat.c:3391
virtual void low_resume(ptid_t ptid, int step, enum gdb_signal sig)
Definition linux-nat.h:138
virtual void low_forget_process(pid_t pid)
Definition linux-nat.h:167
virtual void low_delete_thread(struct arch_lwp_info *lp)
Definition linux-nat.h:152
bool supports_stopped_by_hw_breakpoint() override
Definition linux-nat.c:2672
bool supports_disable_randomization() override
Definition linux-nat.c:4178
void detach(inferior *, int) override
Definition linux-nat.c:1384
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
Definition linux-nat.c:3670
bool stopped_by_sw_breakpoint() override
Definition linux-nat.c:2639
virtual bool low_stopped_data_address(CORE_ADDR *addr_p)
Definition linux-nat.h:144
int insert_fork_catchpoint(int) override
Definition linux-nat.c:521
virtual void low_new_clone(struct lwp_info *parent, pid_t child_lwp)
Definition linux-nat.h:162
bool stopped_by_hw_breakpoint() override
Definition linux-nat.c:2660
bool stopped_by_watchpoint() override
Definition linux-nat.c:2303
virtual void low_new_fork(struct lwp_info *parent, pid_t child_pid)
Definition linux-nat.h:158
int remove_exec_catchpoint(int) override
Definition linux-nat.c:551
const char * thread_name(struct thread_info *) override
Definition linux-nat.c:3763
virtual bool low_stopped_by_watchpoint()
Definition linux-nat.h:141
int insert_vfork_catchpoint(int) override
Definition linux-nat.c:533
bool filesystem_is_local() override
Definition linux-nat.c:4337
int remove_fork_catchpoint(int) override
Definition linux-nat.c:527
void update_thread_list() override
Definition linux-nat.c:3732
void thread_events(int) override
Definition linux-nat.c:4429
bool supports_multi_process() override
Definition linux-nat.c:4172
int set_syscall_catchpoint(int pid, bool needed, int any_count, gdb::array_view< const int > syscall_counts) override
Definition linux-nat.c:557
std::vector< static_tracepoint_marker > static_tracepoint_markers_by_strid(const char *id) override
Definition linux-nat.c:4105
void create_inferior(const char *, const std::string &, char **, int) override
Definition linux-nat.c:966
void async(bool) override
Definition linux-nat.c:4216
int remove_vfork_catchpoint(int) override
Definition linux-nat.c:539
virtual bool low_siginfo_fixup(siginfo_t *ptrace, gdb_byte *inf, int direction)
Definition linux-nat.h:179
void mourn_inferior() override
Definition linux-nat.c:3571
bool stopped_data_address(CORE_ADDR *) override
Definition linux-nat.c:2313
bool supports_non_stop() override
Definition linux-nat.c:4158
void pass_signals(gdb::array_view< const unsigned char >) override
Definition linux-nat.c:697
#define ptrace(request, pid, addr, data)
Definition gdb_ptrace.h:141
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1862
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
Definition gnu-nat.c:1792
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition gnu-nat.c:1791
static bool follow_fork()
Definition infrun.c:694
void linux_unstop_all_lwps(void)
Definition linux-nat.c:2208
int lin_thread_get_thread_signal(unsigned int i)
Definition linux-nat.c:4521
lwp_info_range all_lwps()
Definition linux-nat.c:626
void linux_proc_pending_signals(int pid, sigset_t *pending, sigset_t *blocked, sigset_t *ignored)
Definition linux-nat.c:4055
bool linux_nat_get_siginfo(ptid_t ptid, siginfo_t *siginfo)
Definition linux-nat.c:4446
int thread_db_notice_clone(ptid_t parent, ptid_t child)
lwp_info_safe_range all_lwps_safe()
Definition linux-nat.c:634
linux_nat_target * linux_target
Definition linux-nat.c:190
unsigned int lin_thread_get_thread_signal_num(void)
Definition linux-nat.c:4513
reference_to_pointer_iterator< intrusive_list< lwp_info >::iterator > lwp_info_iterator
Definition linux-nat.h:285
void linux_stop_and_wait_all_lwps(void)
Definition linux-nat.c:2195
enum tribool have_ptrace_getregset
Definition linux-nat.c:193
iterator_range< lwp_info_iterator > lwp_info_range
Definition linux-nat.h:286
basic_safe_range< lwp_info_range > lwp_info_safe_range
Definition linux-nat.h:287
void linux_nat_switch_fork(ptid_t new_ptid)
Definition linux-nat.c:869
resume_kind
Definition resume.h:26
@ resume_continue
Definition resume.h:28
void resume(ptid_t, int, enum gdb_signal) override
Definition inf-ptrace.c:256
Definition gnu-nat.c:154
ptid_t ptid
Definition linux-nat.h:211
struct target_waitstatus waitstatus
Definition linux-nat.h:266
int resumed
Definition linux-nat.h:230
CORE_ADDR stop_pc
Definition linux-nat.h:243
DISABLE_COPY_AND_ASSIGN(lwp_info)
CORE_ADDR stopped_data_address
Definition linux-nat.h:258
int signalled
Definition linux-nat.h:219
int stopped
Definition linux-nat.h:222
target_stop_reason stop_reason
Definition linux-nat.h:250
int must_set_ptrace_flags
Definition linux-nat.h:215
int status
Definition linux-nat.h:236
int stopped_data_address_p
Definition linux-nat.h:257
int ignore_sigint
Definition linux-nat.h:261
resume_kind last_resume_kind
Definition linux-nat.h:233
struct arch_lwp_info * arch_private
Definition linux-nat.h:279
lwp_info(ptid_t ptid)
Definition linux-nat.h:201
enum target_waitkind syscall_state
Definition linux-nat.h:273
virtual gdb::byte_vector virtual thread_info_to_thread_handle(struct thread_info *) TARGET_DEFAULT_RETURN(gdb voi stop)(ptid_t) TARGET_DEFAULT_IGNORE()
Definition target.h:684
target_xfer_status
Definition target.h:214
target_object
Definition target.h:138
thread_control_capabilities
Definition target.h:100
@ tc_schedlock
Definition target.h:102
target_waitkind
Definition waitstatus.h:30
target_stop_reason
Definition waitstatus.h:428
@ TARGET_STOPPED_BY_NO_REASON
Definition waitstatus.h:431