fbsd-nat.h revision 1.10 1 1.1 christos /* Native-dependent code for FreeBSD.
2 1.1 christos
3 1.10 christos Copyright (C) 2004-2023 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This file is part of GDB.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #ifndef FBSD_NAT_H
21 1.1 christos #define FBSD_NAT_H
22 1.1 christos
23 1.8 christos #include "inf-ptrace.h"
24 1.10 christos #include "regcache.h"
25 1.10 christos #include "regset.h"
26 1.9 christos #include <osreldate.h>
27 1.8 christos #include <sys/proc.h>
28 1.8 christos
29 1.9 christos /* FreeBSD kernels 11.3 and later report valid si_code values for
30 1.9 christos SIGTRAP on all architectures. Older FreeBSD kernels that supported
31 1.9 christos TRAP_BRKPT did not report valid values for MIPS and sparc64. Even
32 1.9 christos older kernels without TRAP_BRKPT support did not report valid
33 1.9 christos values on any architecture. */
34 1.9 christos #if (__FreeBSD_kernel_version >= 1102502) || (__FreeBSD_version >= 1102502)
35 1.9 christos # define USE_SIGTRAP_SIGINFO
36 1.9 christos #elif defined(TRAP_BRKPT)
37 1.8 christos # if !defined(__mips__) && !defined(__sparc64__)
38 1.8 christos # define USE_SIGTRAP_SIGINFO
39 1.8 christos # endif
40 1.8 christos #endif
41 1.8 christos
42 1.8 christos /* A prototype FreeBSD target. */
43 1.8 christos
44 1.8 christos class fbsd_nat_target : public inf_ptrace_target
45 1.8 christos {
46 1.8 christos public:
47 1.10 christos const char *pid_to_exec_file (int pid) override;
48 1.8 christos
49 1.8 christos int find_memory_regions (find_memory_region_ftype func, void *data) override;
50 1.8 christos
51 1.8 christos bool info_proc (const char *, enum info_proc_what) override;
52 1.8 christos
53 1.8 christos enum target_xfer_status xfer_partial (enum target_object object,
54 1.8 christos const char *annex,
55 1.8 christos gdb_byte *readbuf,
56 1.8 christos const gdb_byte *writebuf,
57 1.8 christos ULONGEST offset, ULONGEST len,
58 1.8 christos ULONGEST *xfered_len) override;
59 1.8 christos
60 1.8 christos bool thread_alive (ptid_t ptid) override;
61 1.9 christos std::string pid_to_str (ptid_t) override;
62 1.8 christos
63 1.8 christos #ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_TDNAME
64 1.8 christos const char *thread_name (struct thread_info *) override;
65 1.8 christos #endif
66 1.8 christos
67 1.8 christos void update_thread_list () override;
68 1.8 christos
69 1.10 christos bool can_async_p () override;
70 1.10 christos
71 1.10 christos void async (bool) override;
72 1.10 christos
73 1.8 christos thread_control_capabilities get_thread_control_capabilities () override
74 1.8 christos { return tc_schedlock; }
75 1.8 christos
76 1.10 christos void create_inferior (const char *, const std::string &,
77 1.10 christos char **, int) override;
78 1.10 christos
79 1.8 christos void resume (ptid_t, int, enum gdb_signal) override;
80 1.8 christos
81 1.10 christos ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
82 1.8 christos
83 1.8 christos void post_attach (int) override;
84 1.8 christos
85 1.8 christos #ifdef USE_SIGTRAP_SIGINFO
86 1.8 christos bool supports_stopped_by_sw_breakpoint () override;
87 1.8 christos bool stopped_by_sw_breakpoint () override;
88 1.8 christos #endif
89 1.8 christos
90 1.8 christos #ifdef TDP_RFPPWAIT
91 1.10 christos void follow_fork (inferior *, ptid_t, target_waitkind, bool, bool) override;
92 1.8 christos
93 1.8 christos int insert_fork_catchpoint (int) override;
94 1.8 christos int remove_fork_catchpoint (int) override;
95 1.8 christos
96 1.8 christos int insert_vfork_catchpoint (int) override;
97 1.8 christos int remove_vfork_catchpoint (int) override;
98 1.8 christos #endif
99 1.8 christos
100 1.8 christos int insert_exec_catchpoint (int) override;
101 1.8 christos int remove_exec_catchpoint (int) override;
102 1.8 christos
103 1.8 christos #ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_SYSCALL_CODE
104 1.8 christos int set_syscall_catchpoint (int, bool, int, gdb::array_view<const int>)
105 1.8 christos override;
106 1.8 christos #endif
107 1.9 christos
108 1.9 christos bool supports_multi_process () override;
109 1.10 christos
110 1.10 christos bool supports_disable_randomization () override;
111 1.10 christos
112 1.10 christos /* Methods meant to be overridden by arch-specific target
113 1.10 christos classes. */
114 1.10 christos
115 1.10 christos virtual void low_new_fork (ptid_t parent, pid_t child)
116 1.10 christos {}
117 1.10 christos
118 1.10 christos /* The method to call, if any, when a thread is destroyed. */
119 1.10 christos virtual void low_delete_thread (thread_info *)
120 1.10 christos {}
121 1.10 christos
122 1.10 christos /* Hook to call prior to resuming a thread. */
123 1.10 christos virtual void low_prepare_to_resume (thread_info *)
124 1.10 christos {}
125 1.10 christos
126 1.10 christos protected:
127 1.10 christos
128 1.10 christos void post_startup_inferior (ptid_t) override;
129 1.10 christos
130 1.10 christos private:
131 1.10 christos ptid_t wait_1 (ptid_t, struct target_waitstatus *, target_wait_flags);
132 1.10 christos
133 1.10 christos /* Helper routines for use in fetch_registers and store_registers in
134 1.10 christos subclasses. These routines fetch and store a single set of
135 1.10 christos registers described by REGSET. The REGSET's 'regmap' field must
136 1.10 christos point to an array of 'struct regcache_map_entry'. The valid
137 1.10 christos register numbers in the register map are relative to REGBASE.
138 1.10 christos
139 1.10 christos FETCH_OP is a ptrace operation to fetch the set of registers from
140 1.10 christos a native thread. STORE_OP is a ptrace operation to store the set
141 1.10 christos of registers to a native thread.
142 1.10 christos
143 1.10 christos The caller must provide storage for the set of registers in REGS,
144 1.10 christos and SIZE is the size of the storage.
145 1.10 christos
146 1.10 christos Returns true if the register set was transferred due to a
147 1.10 christos matching REGNUM. */
148 1.10 christos
149 1.10 christos bool fetch_register_set (struct regcache *regcache, int regnum, int fetch_op,
150 1.10 christos const struct regset *regset, int regbase, void *regs,
151 1.10 christos size_t size);
152 1.10 christos
153 1.10 christos bool store_register_set (struct regcache *regcache, int regnum, int fetch_op,
154 1.10 christos int store_op, const struct regset *regset,
155 1.10 christos int regbase, void *regs, size_t size);
156 1.10 christos
157 1.10 christos /* Helper routines which use PT_GETREGSET and PT_SETREGSET for the
158 1.10 christos specified NOTE instead of regset-specific fetch and store
159 1.10 christos ops. */
160 1.10 christos
161 1.10 christos bool fetch_regset (struct regcache *regcache, int regnum, int note,
162 1.10 christos const struct regset *regset, int regbase, void *regs,
163 1.10 christos size_t size);
164 1.10 christos
165 1.10 christos bool store_regset (struct regcache *regcache, int regnum, int note,
166 1.10 christos const struct regset *regset, int regbase, void *regs,
167 1.10 christos size_t size);
168 1.10 christos
169 1.10 christos protected:
170 1.10 christos /* Wrapper versions of the above helpers which accept a register set
171 1.10 christos type such as 'struct reg' or 'struct fpreg'. */
172 1.10 christos
173 1.10 christos template <class Regset>
174 1.10 christos bool fetch_register_set (struct regcache *regcache, int regnum, int fetch_op,
175 1.10 christos const struct regset *regset, int regbase = 0)
176 1.10 christos {
177 1.10 christos Regset regs;
178 1.10 christos return fetch_register_set (regcache, regnum, fetch_op, regset, regbase,
179 1.10 christos ®s, sizeof (regs));
180 1.10 christos }
181 1.10 christos
182 1.10 christos template <class Regset>
183 1.10 christos bool store_register_set (struct regcache *regcache, int regnum, int fetch_op,
184 1.10 christos int store_op, const struct regset *regset,
185 1.10 christos int regbase = 0)
186 1.10 christos {
187 1.10 christos Regset regs;
188 1.10 christos return store_register_set (regcache, regnum, fetch_op, store_op, regset,
189 1.10 christos regbase, ®s, sizeof (regs));
190 1.10 christos }
191 1.10 christos
192 1.10 christos /* Helper routine for use in read_description in subclasses. This
193 1.10 christos routine checks if the register set for the specified NOTE is
194 1.10 christos present for a given PTID. If the register set is present, the
195 1.10 christos the size of the register set is returned. If the register set is
196 1.10 christos not present, zero is returned. */
197 1.10 christos
198 1.10 christos size_t have_regset (ptid_t ptid, int note);
199 1.10 christos
200 1.10 christos /* Wrapper versions of the PT_GETREGSET and PT_REGSET helpers which
201 1.10 christos accept a register set type. */
202 1.10 christos
203 1.10 christos template <class Regset>
204 1.10 christos bool fetch_regset (struct regcache *regcache, int regnum, int note,
205 1.10 christos const struct regset *regset, int regbase = 0)
206 1.10 christos {
207 1.10 christos Regset regs;
208 1.10 christos return fetch_regset (regcache, regnum, note, regset, regbase, ®s,
209 1.10 christos sizeof (regs));
210 1.10 christos }
211 1.10 christos
212 1.10 christos template <class Regset>
213 1.10 christos bool store_regset (struct regcache *regcache, int regnum, int note,
214 1.10 christos const struct regset *regset, int regbase = 0)
215 1.10 christos {
216 1.10 christos Regset regs;
217 1.10 christos return store_regset (regcache, regnum, note, regset, regbase, ®s,
218 1.10 christos sizeof (regs));
219 1.10 christos }
220 1.8 christos };
221 1.1 christos
222 1.10 christos /* Fetch the signal information for PTID and store it in *SIGINFO.
223 1.10 christos Return true if successful. */
224 1.10 christos bool fbsd_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo);
225 1.10 christos
226 1.1 christos #endif /* fbsd-nat.h */
227