[gdb/testsuite] Fix gdb.threads/threadcrash.exp with glibc debuginfo
[binutils-gdb.git] / gdb / fbsd-nat.h
blob35c06b2c985b1382110dbec3ad69a5d981f99bbd
1 /* Native-dependent code for FreeBSD.
3 Copyright (C) 2004-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 FBSD_NAT_H
21 #define FBSD_NAT_H
23 #include <optional>
24 #include "inf-ptrace.h"
25 #include "regcache.h"
26 #include "regset.h"
27 #include <osreldate.h>
28 #include <sys/proc.h>
30 #include <list>
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
45 /* A prototype FreeBSD target. */
47 class fbsd_nat_target : public inf_ptrace_target
49 public:
50 const char *pid_to_exec_file (int pid) override;
52 int find_memory_regions (find_memory_region_ftype func, void *data) override;
54 bool info_proc (const char *, enum info_proc_what) override;
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;
63 bool thread_alive (ptid_t ptid) override;
64 std::string pid_to_str (ptid_t) override;
66 #ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_TDNAME
67 const char *thread_name (struct thread_info *) override;
68 #endif
70 void update_thread_list () override;
72 bool can_async_p () override;
74 void async (bool) override;
76 thread_control_capabilities get_thread_control_capabilities () override
77 { return tc_schedlock; }
79 void create_inferior (const char *, const std::string &,
80 char **, int) override;
82 void attach (const char *, int) override;
84 void detach (inferior *, int) override;
86 void kill () override;
88 void mourn_inferior () override;
90 void resume (ptid_t, int, enum gdb_signal) override;
92 ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
94 void post_attach (int) override;
96 #ifdef USE_SIGTRAP_SIGINFO
97 bool supports_stopped_by_sw_breakpoint () override;
98 bool stopped_by_sw_breakpoint () override;
99 #endif
101 void follow_exec (inferior *, ptid_t, const char *) override;
103 #ifdef TDP_RFPPWAIT
104 void follow_fork (inferior *, ptid_t, target_waitkind, bool, bool) override;
106 int insert_fork_catchpoint (int) override;
107 int remove_fork_catchpoint (int) override;
109 int insert_vfork_catchpoint (int) override;
110 int remove_vfork_catchpoint (int) override;
111 #endif
113 int insert_exec_catchpoint (int) override;
114 int remove_exec_catchpoint (int) override;
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
121 bool supports_multi_process () override;
123 bool supports_disable_randomization () override;
125 /* Methods meant to be overridden by arch-specific target
126 classes. */
128 virtual void low_new_fork (ptid_t parent, pid_t child)
131 /* The method to call, if any, when a thread is destroyed. */
132 virtual void low_delete_thread (thread_info *)
135 /* Hook to call prior to resuming a thread. */
136 virtual void low_prepare_to_resume (thread_info *)
139 protected:
141 void post_startup_inferior (ptid_t) override;
143 private:
144 ptid_t wait_1 (ptid_t, struct target_waitstatus *, target_wait_flags);
146 void resume_one_process (ptid_t, int, enum gdb_signal);
148 void stop_process (inferior *);
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.
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.
160 The caller must provide storage for the set of registers in REGS,
161 and SIZE is the size of the storage.
163 Returns true if the register set was transferred due to a
164 matching REGNUM. */
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);
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);
174 /* Helper routines which use PT_GETREGSET and PT_SETREGSET for the
175 specified NOTE instead of regset-specific fetch and store
176 ops. */
178 bool fetch_regset (struct regcache *regcache, int regnum, int note,
179 const struct regset *regset, int regbase, void *regs,
180 size_t size);
182 bool store_regset (struct regcache *regcache, int regnum, int note,
183 const struct regset *regset, int regbase, void *regs,
184 size_t size);
186 protected:
187 /* Wrapper versions of the above helpers which accept a register set
188 type such as 'struct reg' or 'struct fpreg'. */
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)
194 Regset regs;
195 return fetch_register_set (regcache, regnum, fetch_op, regset, regbase,
196 &regs, sizeof (regs));
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)
204 Regset regs;
205 return store_register_set (regcache, regnum, fetch_op, store_op, regset,
206 regbase, &regs, sizeof (regs));
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. */
215 size_t have_regset (ptid_t ptid, int note);
217 /* Wrapper versions of the PT_GETREGSET and PT_REGSET helpers which
218 accept a register set type. */
220 template <class Regset>
221 bool fetch_regset (struct regcache *regcache, int regnum, int note,
222 const struct regset *regset, int regbase = 0)
224 Regset regs;
225 return fetch_regset (regcache, regnum, note, regset, regbase, &regs,
226 sizeof (regs));
229 template <class Regset>
230 bool store_regset (struct regcache *regcache, int regnum, int note,
231 const struct regset *regset, int regbase = 0)
233 Regset regs;
234 return store_regset (regcache, regnum, note, regset, regbase, &regs,
235 sizeof (regs));
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. */
244 struct pending_event
246 pending_event (const ptid_t &_ptid, const target_waitstatus &_status) :
247 ptid (_ptid), status (_status) {}
249 ptid_t ptid;
250 target_waitstatus status;
253 /* Add a new pending event to the list. */
255 void add_pending_event (const ptid_t &ptid, const target_waitstatus &status);
257 /* Return true if there is a pending event matching FILTER. */
259 bool have_pending_event (ptid_t filter);
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. */
265 std::optional<pending_event> take_pending_event (ptid_t filter);
267 /* List of pending events. */
269 std::list<pending_event> m_pending_events;
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. */
275 void detach_fork_children (thread_info *tp);
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. */
281 bool detach_fork_children (inferior *inf);
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);
288 #endif /* fbsd-nat.h */