GDB (xrefs)
Loading...
Searching...
No Matches
fbsd-nat.h
Go to the documentation of this file.
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
48{
49public:
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
57 const char *annex,
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
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
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. */
133 {}
134
135 /* Hook to call prior to resuming a thread. */
137 {}
138
139protected:
140
141 void post_startup_inferior (ptid_t) override;
142
143private:
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
186protected:
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>
192 const struct regset *regset, int regbase = 0)
193 {
194 Regset regs;
196 &regs, sizeof (regs));
197 }
198
199 template <class Regset>
201 int store_op, const struct regset *regset,
202 int regbase = 0)
203 {
204 Regset regs;
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
238private:
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
245 {
246 pending_event (const ptid_t &_ptid, const target_waitstatus &_status) :
247 ptid (_ptid), status (_status) {}
248
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
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
282};
283
284/* Fetch the signal information for PTID and store it in *SIGINFO.
285 Return true if successful. */
286bool fbsd_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo);
287
288#endif /* fbsd-nat.h */
int regnum
bool can_async_p() override
Definition fbsd-nat.c:1022
gdb::optional< pending_event > take_pending_event(ptid_t filter)
Definition fbsd-nat.c:103
size_t have_regset(ptid_t ptid, int note)
Definition fbsd-nat.c:2388
std::list< pending_event > m_pending_events
Definition fbsd-nat.h:269
void mourn_inferior() override
Definition fbsd-nat.c:2166
int find_memory_regions(find_memory_region_ftype func, void *data) override
Definition fbsd-nat.c:149
bool store_regset(struct regcache *regcache, int regnum, int note, const struct regset *regset, int regbase, void *regs, size_t size)
Definition fbsd-nat.c:2429
void kill() override
Definition fbsd-nat.c:2118
bool fetch_register_set(struct regcache *regcache, int regnum, int fetch_op, const struct regset *regset, int regbase, void *regs, size_t size)
Definition fbsd-nat.c:2336
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 fbsd-nat.c:634
int remove_exec_catchpoint(int) override
Definition fbsd-nat.c:2298
bool store_register_set(struct regcache *regcache, int regnum, int fetch_op, int store_op, const struct regset *regset, int regbase, void *regs, size_t size)
Definition fbsd-nat.c:2360
int insert_exec_catchpoint(int) override
Definition fbsd-nat.c:2292
void detach_fork_children(thread_info *tp)
Definition fbsd-nat.c:1855
bool store_regset(struct regcache *regcache, int regnum, int note, const struct regset *regset, int regbase=0)
Definition fbsd-nat.h:230
bool store_register_set(struct regcache *regcache, int regnum, int fetch_op, int store_op, const struct regset *regset, int regbase=0)
Definition fbsd-nat.h:200
bool fetch_register_set(struct regcache *regcache, int regnum, int fetch_op, const struct regset *regset, int regbase=0)
Definition fbsd-nat.h:191
void add_pending_event(const ptid_t &ptid, const target_waitstatus &status)
Definition fbsd-nat.c:82
std::string pid_to_str(ptid_t) override
Definition fbsd-nat.c:865
bool supports_multi_process() override
Definition fbsd-nat.c:2318
void stop_process(inferior *)
Definition fbsd-nat.c:1585
void create_inferior(const char *, const std::string &, char **, int) override
Definition fbsd-nat.c:1822
void async(bool) override
Definition fbsd-nat.c:1054
bool supports_disable_randomization() override
Definition fbsd-nat.c:2324
bool fetch_regset(struct regcache *regcache, int regnum, int note, const struct regset *regset, int regbase=0)
Definition fbsd-nat.h:221
virtual void low_new_fork(ptid_t parent, pid_t child)
Definition fbsd-nat.h:128
void update_thread_list() override
Definition fbsd-nat.c:1004
void follow_exec(inferior *, ptid_t, const char *) override
Definition fbsd-nat.c:2173
void post_startup_inferior(ptid_t) override
Definition fbsd-nat.c:2275
thread_control_capabilities get_thread_control_capabilities() override
Definition fbsd-nat.h:76
bool info_proc(const char *, enum info_proc_what) override
Definition fbsd-nat.c:249
void attach(const char *, int) override
Definition fbsd-nat.c:1840
bool thread_alive(ptid_t ptid) override
Definition fbsd-nat.c:838
const char * pid_to_exec_file(int pid) override
Definition fbsd-nat.c:124
virtual void low_delete_thread(thread_info *)
Definition fbsd-nat.h:132
bool fetch_regset(struct regcache *regcache, int regnum, int note, const struct regset *regset, int regbase, void *regs, size_t size)
Definition fbsd-nat.c:2403
virtual void low_prepare_to_resume(thread_info *)
Definition fbsd-nat.h:136
void detach(inferior *, int) override
Definition fbsd-nat.c:2001
ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags) override
Definition fbsd-nat.c:1659
bool have_pending_event(ptid_t filter)
Definition fbsd-nat.c:92
void resume_one_process(ptid_t, int, enum gdb_signal)
Definition fbsd-nat.c:1187
ptid_t wait_1(ptid_t, struct target_waitstatus *, target_wait_flags)
Definition fbsd-nat.c:1349
void resume(ptid_t, int, enum gdb_signal) override
Definition fbsd-nat.c:1273
void post_attach(int) override
Definition fbsd-nat.c:2283
info_proc_what
Definition defs.h:380
int(* find_memory_region_ftype)(CORE_ADDR addr, unsigned long size, int read, int write, int exec, int modified, bool memory_tagged, void *data)
Definition defs.h:350
bool fbsd_nat_get_siginfo(ptid_t ptid, siginfo_t *siginfo)
Definition fbsd-nat.c:2460
const char * thread_name(thread_info *thread)
Definition thread.c:2095
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:1791
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition gnu-nat.c:1790
size_t size
Definition go32-nat.c:239
static bool follow_fork()
Definition infrun.c:740
void(* func)(remote_target *remote, char *)
pending_event(const ptid_t &_ptid, const target_waitstatus &_status)
Definition fbsd-nat.h:246
target_waitstatus status
Definition fbsd-nat.h:250
Definition gnu-nat.c:153
virtual bool stopped_by_sw_breakpoint() TARGET_DEFAULT_RETURN(false)
virtual int insert_fork_catchpoint(int) TARGET_DEFAULT_RETURN(1)
virtual bool supports_stopped_by_sw_breakpoint() TARGET_DEFAULT_RETURN(false)
virtual int insert_vfork_catchpoint(int) TARGET_DEFAULT_RETURN(1)
virtual int remove_fork_catchpoint(int) TARGET_DEFAULT_RETURN(1)
virtual int remove_vfork_catchpoint(int) TARGET_DEFAULT_RETURN(1)
virtual int set_syscall_catchpoint(int, bool, int, gdb::array_view< const int >) TARGET_DEFAULT_RETURN(1)
target_xfer_status
Definition target.h:219
target_object
Definition target.h:143
thread_control_capabilities
Definition target.h:105
@ tc_schedlock
Definition target.h:107
target_waitkind
Definition waitstatus.h:30