Remove path name from test case
[binutils-gdb.git] / gdb / fbsd-nat.h
1 /* Native-dependent code for FreeBSD.
2
3 Copyright (C) 2004-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 FBSD_NAT_H
21 #define FBSD_NAT_H
22
23 #include "gdbsupport/gdb_optional.h"
24 #include "inf-ptrace.h"
25 #include "regcache.h"
26 #include "regset.h"
27 #include <osreldate.h>
28 #include <sys/proc.h>
29
30 #include <list>
31
32 /* FreeBSD kernels 11.3 and later report valid si_code values for
33 SIGTRAP on all architectures. Older FreeBSD kernels that supported
34 TRAP_BRKPT did not report valid values for MIPS and sparc64. Even
35 older kernels without TRAP_BRKPT support did not report valid
36 values on any architecture. */
37 #if (__FreeBSD_kernel_version >= 1102502) || (__FreeBSD_version >= 1102502)
38 # define USE_SIGTRAP_SIGINFO
39 #elif defined(TRAP_BRKPT)
40 # if !defined(__mips__) && !defined(__sparc64__)
41 # define USE_SIGTRAP_SIGINFO
42 # endif
43 #endif
44
45 /* A prototype FreeBSD target. */
46
47 class fbsd_nat_target : public inf_ptrace_target
48 {
49 public:
50 const char *pid_to_exec_file (int pid) override;
51
52 int find_memory_regions (find_memory_region_ftype func, void *data) override;
53
54 bool info_proc (const char *, enum info_proc_what) override;
55
56 enum target_xfer_status xfer_partial (enum target_object object,
57 const char *annex,
58 gdb_byte *readbuf,
59 const gdb_byte *writebuf,
60 ULONGEST offset, ULONGEST len,
61 ULONGEST *xfered_len) override;
62
63 bool thread_alive (ptid_t ptid) override;
64 std::string pid_to_str (ptid_t) override;
65
66 #ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_TDNAME
67 const char *thread_name (struct thread_info *) override;
68 #endif
69
70 void update_thread_list () override;
71
72 bool can_async_p () override;
73
74 void async (bool) override;
75
76 thread_control_capabilities get_thread_control_capabilities () override
77 { return tc_schedlock; }
78
79 void create_inferior (const char *, const std::string &,
80 char **, int) override;
81
82 void attach (const char *, int) override;
83
84 void detach (inferior *, int) override;
85
86 void kill () override;
87
88 void mourn_inferior () override;
89
90 void resume (ptid_t, int, enum gdb_signal) override;
91
92 ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
93
94 void post_attach (int) override;
95
96 #ifdef USE_SIGTRAP_SIGINFO
97 bool supports_stopped_by_sw_breakpoint () override;
98 bool stopped_by_sw_breakpoint () override;
99 #endif
100
101 void follow_exec (inferior *, ptid_t, const char *) override;
102
103 #ifdef TDP_RFPPWAIT
104 void follow_fork (inferior *, ptid_t, target_waitkind, bool, bool) override;
105
106 int insert_fork_catchpoint (int) override;
107 int remove_fork_catchpoint (int) override;
108
109 int insert_vfork_catchpoint (int) override;
110 int remove_vfork_catchpoint (int) override;
111 #endif
112
113 int insert_exec_catchpoint (int) override;
114 int remove_exec_catchpoint (int) override;
115
116 #ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_SYSCALL_CODE
117 int set_syscall_catchpoint (int, bool, int, gdb::array_view<const int>)
118 override;
119 #endif
120
121 bool supports_multi_process () override;
122
123 bool supports_disable_randomization () override;
124
125 /* Methods meant to be overridden by arch-specific target
126 classes. */
127
128 virtual void low_new_fork (ptid_t parent, pid_t child)
129 {}
130
131 /* The method to call, if any, when a thread is destroyed. */
132 virtual void low_delete_thread (thread_info *)
133 {}
134
135 /* Hook to call prior to resuming a thread. */
136 virtual void low_prepare_to_resume (thread_info *)
137 {}
138
139 protected:
140
141 void post_startup_inferior (ptid_t) override;
142
143 private:
144 ptid_t wait_1 (ptid_t, struct target_waitstatus *, target_wait_flags);
145
146 void resume_one_process (ptid_t, int, enum gdb_signal);
147
148 void stop_process (inferior *);
149
150 /* Helper routines for use in fetch_registers and store_registers in
151 subclasses. These routines fetch and store a single set of
152 registers described by REGSET. The REGSET's 'regmap' field must
153 point to an array of 'struct regcache_map_entry'. The valid
154 register numbers in the register map are relative to REGBASE.
155
156 FETCH_OP is a ptrace operation to fetch the set of registers from
157 a native thread. STORE_OP is a ptrace operation to store the set
158 of registers to a native thread.
159
160 The caller must provide storage for the set of registers in REGS,
161 and SIZE is the size of the storage.
162
163 Returns true if the register set was transferred due to a
164 matching REGNUM. */
165
166 bool fetch_register_set (struct regcache *regcache, int regnum, int fetch_op,
167 const struct regset *regset, int regbase, void *regs,
168 size_t size);
169
170 bool store_register_set (struct regcache *regcache, int regnum, int fetch_op,
171 int store_op, const struct regset *regset,
172 int regbase, void *regs, size_t size);
173
174 /* Helper routines which use PT_GETREGSET and PT_SETREGSET for the
175 specified NOTE instead of regset-specific fetch and store
176 ops. */
177
178 bool fetch_regset (struct regcache *regcache, int regnum, int note,
179 const struct regset *regset, int regbase, void *regs,
180 size_t size);
181
182 bool store_regset (struct regcache *regcache, int regnum, int note,
183 const struct regset *regset, int regbase, void *regs,
184 size_t size);
185
186 protected:
187 /* Wrapper versions of the above helpers which accept a register set
188 type such as 'struct reg' or 'struct fpreg'. */
189
190 template <class Regset>
191 bool fetch_register_set (struct regcache *regcache, int regnum, int fetch_op,
192 const struct regset *regset, int regbase = 0)
193 {
194 Regset regs;
195 return fetch_register_set (regcache, regnum, fetch_op, regset, regbase,
196 &regs, sizeof (regs));
197 }
198
199 template <class Regset>
200 bool store_register_set (struct regcache *regcache, int regnum, int fetch_op,
201 int store_op, const struct regset *regset,
202 int regbase = 0)
203 {
204 Regset regs;
205 return store_register_set (regcache, regnum, fetch_op, store_op, regset,
206 regbase, &regs, sizeof (regs));
207 }
208
209 /* Helper routine for use in read_description in subclasses. This
210 routine checks if the register set for the specified NOTE is
211 present for a given PTID. If the register set is present, the
212 the size of the register set is returned. If the register set is
213 not present, zero is returned. */
214
215 size_t have_regset (ptid_t ptid, int note);
216
217 /* Wrapper versions of the PT_GETREGSET and PT_REGSET helpers which
218 accept a register set type. */
219
220 template <class Regset>
221 bool fetch_regset (struct regcache *regcache, int regnum, int note,
222 const struct regset *regset, int regbase = 0)
223 {
224 Regset regs;
225 return fetch_regset (regcache, regnum, note, regset, regbase, &regs,
226 sizeof (regs));
227 }
228
229 template <class Regset>
230 bool store_regset (struct regcache *regcache, int regnum, int note,
231 const struct regset *regset, int regbase = 0)
232 {
233 Regset regs;
234 return store_regset (regcache, regnum, note, regset, regbase, &regs,
235 sizeof (regs));
236 }
237
238 private:
239 /* If an event is triggered asynchronously (fake vfork_done events)
240 or occurs when the core is not expecting it, a pending event is
241 created. This event is then returned by a future call to the
242 target wait method. */
243
244 struct pending_event
245 {
246 pending_event (const ptid_t &_ptid, const target_waitstatus &_status) :
247 ptid (_ptid), status (_status) {}
248
249 ptid_t ptid;
250 target_waitstatus status;
251 };
252
253 /* Add a new pending event to the list. */
254
255 void add_pending_event (const ptid_t &ptid, const target_waitstatus &status);
256
257 /* Return true if there is a pending event matching FILTER. */
258
259 bool have_pending_event (ptid_t filter);
260
261 /* Check if there is a pending event for a resumed process matching
262 FILTER. If there is a matching event, the event is removed from
263 the pending list and returned. */
264
265 gdb::optional<pending_event> take_pending_event (ptid_t filter);
266
267 /* List of pending events. */
268
269 std::list<pending_event> m_pending_events;
270
271 /* If this thread has a pending fork event, there is a child process
272 GDB is attached to that the core of GDB doesn't know about.
273 Detach from it. */
274
275 void detach_fork_children (thread_info *tp);
276
277 /* Detach from any child processes associated with pending fork events
278 for a stopped process. Returns true if the process has terminated
279 and false if it is still alive. */
280
281 bool detach_fork_children (inferior *inf);
282 };
283
284 /* Fetch the signal information for PTID and store it in *SIGINFO.
285 Return true if successful. */
286 bool fbsd_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo);
287
288 #endif /* fbsd-nat.h */