GDB (xrefs)
Loading...
Searching...
No Matches
/tmp/gdb-13.1/gdb/amd64-fbsd-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for FreeBSD/amd64.
2
3 Copyright (C) 2003-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#include "defs.h"
21#include "osabi.h"
22#include "regset.h"
23#include "target.h"
24#include "trad-frame.h"
25#include "tramp-frame.h"
26#include "i386-fbsd-tdep.h"
27#include "gdbsupport/x86-xstate.h"
28
29#include "amd64-tdep.h"
30#include "amd64-fbsd-tdep.h"
31#include "fbsd-tdep.h"
32#include "solib-svr4.h"
33#include "inferior.h"
34
35/* The general-purpose regset consists of 22 64-bit slots, most of
36 which contain individual registers, but a few contain multiple
37 16-bit segment registers. */
38#define AMD64_FBSD_SIZEOF_GREGSET (22 * 8)
39
40/* The segment base register set consists of 2 64-bit registers. */
41#define AMD64_FBSD_SIZEOF_SEGBASES_REGSET (2 * 8)
42
43/* Register maps. */
44
46{
47 { 1, AMD64_R15_REGNUM, 0 },
48 { 1, AMD64_R14_REGNUM, 0 },
49 { 1, AMD64_R13_REGNUM, 0 },
50 { 1, AMD64_R12_REGNUM, 0 },
51 { 1, AMD64_R11_REGNUM, 0 },
52 { 1, AMD64_R10_REGNUM, 0 },
53 { 1, AMD64_R9_REGNUM, 0 },
54 { 1, AMD64_R8_REGNUM, 0 },
55 { 1, AMD64_RDI_REGNUM, 0 },
56 { 1, AMD64_RSI_REGNUM, 0 },
57 { 1, AMD64_RBP_REGNUM, 0 },
58 { 1, AMD64_RBX_REGNUM, 0 },
59 { 1, AMD64_RDX_REGNUM, 0 },
60 { 1, AMD64_RCX_REGNUM, 0 },
61 { 1, AMD64_RAX_REGNUM, 0 },
62 { 1, REGCACHE_MAP_SKIP, 4 }, /* trapno */
63 { 1, AMD64_FS_REGNUM, 2 },
64 { 1, AMD64_GS_REGNUM, 2 },
65 { 1, REGCACHE_MAP_SKIP, 4 }, /* err */
66 { 1, AMD64_ES_REGNUM, 2 },
67 { 1, AMD64_DS_REGNUM, 2 },
68 { 1, AMD64_RIP_REGNUM, 0 },
69 { 1, AMD64_CS_REGNUM, 8 },
70 { 1, AMD64_EFLAGS_REGNUM, 8 },
71 { 1, AMD64_RSP_REGNUM, 0 },
72 { 1, AMD64_SS_REGNUM, 8 },
73 { 0 }
74};
75
77{
78 { 1, AMD64_FSBASE_REGNUM, 0 },
79 { 1, AMD64_GSBASE_REGNUM, 0 },
80 { 0 }
81};
82
83/* This layout including fsbase and gsbase was adopted in FreeBSD
84 8.0. */
85
87{
88 { 1, REGCACHE_MAP_SKIP, 8 }, /* mc_onstack */
89 { 1, AMD64_RDI_REGNUM, 0 },
90 { 1, AMD64_RSI_REGNUM, 0 },
91 { 1, AMD64_RDX_REGNUM, 0 },
92 { 1, AMD64_RCX_REGNUM, 0 },
93 { 1, AMD64_R8_REGNUM, 0 },
94 { 1, AMD64_R9_REGNUM, 0 },
95 { 1, AMD64_RAX_REGNUM, 0 },
96 { 1, AMD64_RBX_REGNUM, 0 },
97 { 1, AMD64_RBP_REGNUM, 0 },
98 { 1, AMD64_R10_REGNUM, 0 },
99 { 1, AMD64_R11_REGNUM, 0 },
100 { 1, AMD64_R12_REGNUM, 0 },
101 { 1, AMD64_R13_REGNUM, 0 },
102 { 1, AMD64_R14_REGNUM, 0 },
103 { 1, AMD64_R15_REGNUM, 0 },
104 { 1, REGCACHE_MAP_SKIP, 4 }, /* mc_trapno */
105 { 1, AMD64_FS_REGNUM, 2 },
106 { 1, AMD64_GS_REGNUM, 2 },
107 { 1, REGCACHE_MAP_SKIP, 8 }, /* mc_addr */
108 { 1, REGCACHE_MAP_SKIP, 4 }, /* mc_flags */
109 { 1, AMD64_ES_REGNUM, 2 },
110 { 1, AMD64_DS_REGNUM, 2 },
111 { 1, REGCACHE_MAP_SKIP, 8 }, /* mc_err */
112 { 1, AMD64_RIP_REGNUM, 0 },
113 { 1, AMD64_CS_REGNUM, 8 },
114 { 1, AMD64_EFLAGS_REGNUM, 8 },
115 { 1, AMD64_RSP_REGNUM, 0 },
116 { 1, AMD64_SS_REGNUM, 8 },
117 { 1, REGCACHE_MAP_SKIP, 8 }, /* mc_len */
118 { 1, REGCACHE_MAP_SKIP, 8 }, /* mc_fpformat */
119 { 1, REGCACHE_MAP_SKIP, 8 }, /* mc_ownedfp */
120 { 64, REGCACHE_MAP_SKIP, 8 }, /* mc_fpstate */
121 { 1, AMD64_FSBASE_REGNUM, 0 },
122 { 1, AMD64_GSBASE_REGNUM, 0 },
123 { 0 }
124};
125
126/* Register set definitions. */
127
129{
131};
132
134{
136};
137
138/* Support for signal handlers. */
139
140/* In a signal frame, rsp points to a 'struct sigframe' which is
141 defined as:
142
143 struct sigframe {
144 union {
145 __siginfohandler_t *sf_action;
146 __sighandler_t *sf_handler;
147 } sf_ahu;
148 ucontext_t sf_uc;
149 ...
150 }
151
152 ucontext_t is defined as:
153
154 struct __ucontext {
155 sigset_t uc_sigmask;
156 mcontext_t uc_mcontext;
157 ...
158 };
159
160 The mcontext_t contains the general purpose register set as well
161 as the floating point or XSAVE state. */
162
163/* NB: There is an 8 byte padding hole between sf_ahu and sf_uc. */
164#define AMD64_SIGFRAME_UCONTEXT_OFFSET 16
165#define AMD64_UCONTEXT_MCONTEXT_OFFSET 16
166#define AMD64_SIZEOF_MCONTEXT_T 800
167
168/* Implement the "init" method of struct tramp_frame. */
169
170static void
172 frame_info_ptr this_frame,
173 struct trad_frame_cache *this_cache,
174 CORE_ADDR func)
175{
176 CORE_ADDR sp = get_frame_register_unsigned (this_frame, AMD64_RSP_REGNUM);
177 CORE_ADDR mcontext_addr
178 = (sp
181
182 trad_frame_set_reg_regmap (this_cache, amd64_fbsd_mcregmap, mcontext_addr,
184
185 /* Don't bother with floating point or XSAVE state for now. The
186 current helper routines for parsing FXSAVE and XSAVE state only
187 work with regcaches. This could perhaps create a temporary
188 regcache, collect the register values from mc_fpstate and
189 mc_xfpustate, and then set register values in the trad_frame. */
190
191 trad_frame_set_id (this_cache, frame_id_build (sp, func));
192}
193
194static const struct tramp_frame amd64_fbsd_sigframe =
195{
197 1,
198 {
199 {0x48, ULONGEST_MAX}, /* lea SIGF_UC(%rsp),%rdi */
200 {0x8d, ULONGEST_MAX},
201 {0x7c, ULONGEST_MAX},
202 {0x24, ULONGEST_MAX},
203 {0x10, ULONGEST_MAX},
204 {0x6a, ULONGEST_MAX}, /* pushq $0 */
205 {0x00, ULONGEST_MAX},
206 {0x48, ULONGEST_MAX}, /* movq $SYS_sigreturn,%rax */
207 {0xc7, ULONGEST_MAX},
208 {0xc0, ULONGEST_MAX},
209 {0xa1, ULONGEST_MAX},
210 {0x01, ULONGEST_MAX},
211 {0x00, ULONGEST_MAX},
212 {0x00, ULONGEST_MAX},
213 {0x0f, ULONGEST_MAX}, /* syscall */
214 {0x05, ULONGEST_MAX},
216 },
218};
219
220/* Implement the core_read_description gdbarch method. */
221
222static const struct target_desc *
224 struct target_ops *target,
225 bfd *abfd)
226{
228}
229
230/* Similar to amd64_supply_fpregset, but use XSAVE extended state. */
231
232static void
234 struct regcache *regcache, int regnum,
235 const void *xstateregs, size_t len)
236{
237 amd64_supply_xsave (regcache, regnum, xstateregs);
238}
239
240/* Similar to amd64_collect_fpregset, but use XSAVE extended state. */
241
242static void
244 const struct regcache *regcache,
245 int regnum, void *xstateregs, size_t len)
246{
247 amd64_collect_xsave (regcache, regnum, xstateregs, 1);
248}
249
250static const struct regset amd64fbsd_xstateregset =
251 {
252 NULL,
255 };
256
257/* Iterate over core file register note sections. */
258
259static void
262 void *cb_data,
263 const struct regcache *regcache)
264{
265 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
266
268 &amd64_fbsd_gregset, NULL, cb_data);
269 cb (".reg2", tdep->sizeof_fpregset, tdep->sizeof_fpregset, &amd64_fpregset,
270 NULL, cb_data);
271 cb (".reg-x86-segbases", AMD64_FBSD_SIZEOF_SEGBASES_REGSET,
273 "segment bases", cb_data);
274 cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0), X86_XSTATE_SIZE (tdep->xcr0),
275 &amd64fbsd_xstateregset, "XSAVE extended state", cb_data);
276}
277
278/* Implement the get_thread_local_address gdbarch method. */
279
280static CORE_ADDR
282 CORE_ADDR lm_addr, CORE_ADDR offset)
283{
284 struct regcache *regcache;
285
286 regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
287 ptid, gdbarch);
288
290
291 ULONGEST fsbase;
292 if (regcache->cooked_read (AMD64_FSBASE_REGNUM, &fsbase) != REG_VALID)
293 error (_("Unable to fetch %%fsbase"));
294
295 CORE_ADDR dtv_addr = fsbase + gdbarch_ptr_bit (gdbarch) / 8;
296 return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset);
297}
298
299static void
301{
302 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
303
304 /* Generic FreeBSD support. */
305 fbsd_init_abi (info, gdbarch);
306
307 /* Obviously FreeBSD is BSD-based. */
309
310 amd64_init_abi (info, gdbarch,
311 amd64_target_description (X86_XSTATE_SSE_MASK, true));
312
314
316
317 /* Iterate over core file register note sections. */
320
323
324 /* FreeBSD uses SVR4-style shared libraries. */
327
332}
333
335void
337{
338 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
340}
int regnum
Definition: aarch64-tdep.c:68
static const struct regset amd64fbsd_xstateregset
#define AMD64_SIGFRAME_UCONTEXT_OFFSET
#define AMD64_SIZEOF_MCONTEXT_T
static const struct tramp_frame amd64_fbsd_sigframe
static const struct regcache_map_entry amd64_fbsd_segbases_regmap[]
static const struct regcache_map_entry amd64_fbsd_gregmap[]
const struct regset amd64_fbsd_segbases_regset
#define AMD64_UCONTEXT_MCONTEXT_OFFSET
static void amd64fbsd_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
static void amd64fbsd_supply_xstateregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *xstateregs, size_t len)
static void amd64fbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
void _initialize_amd64fbsd_tdep()
static void amd64fbsd_collect_xstateregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *xstateregs, size_t len)
static CORE_ADDR amd64fbsd_get_thread_local_address(struct gdbarch *gdbarch, ptid_t ptid, CORE_ADDR lm_addr, CORE_ADDR offset)
#define AMD64_FBSD_SIZEOF_SEGBASES_REGSET
const struct regset amd64_fbsd_gregset
#define AMD64_FBSD_SIZEOF_GREGSET
static void amd64_fbsd_sigframe_init(const struct tramp_frame *self, frame_info_ptr this_frame, struct trad_frame_cache *this_cache, CORE_ADDR func)
static const struct regcache_map_entry amd64_fbsd_mcregmap[]
static const struct target_desc * amd64fbsd_core_read_description(struct gdbarch *gdbarch, struct target_ops *target, bfd *abfd)
void amd64_collect_xsave(const struct regcache *regcache, int regnum, void *xsave, int gcore)
Definition: amd64-tdep.c:3458
const struct target_desc * amd64_target_description(uint64_t xcr0, bool segments)
Definition: amd64-tdep.c:3336
void amd64_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch, const target_desc *default_tdesc)
Definition: amd64-tdep.c:3113
void amd64_supply_xsave(struct regcache *regcache, int regnum, const void *xsave)
Definition: amd64-tdep.c:3402
const struct regset amd64_fpregset
Definition: amd64-tdep.c:3054
@ AMD64_RAX_REGNUM
Definition: amd64-tdep.h:35
@ AMD64_FS_REGNUM
Definition: amd64-tdep.h:57
@ AMD64_R11_REGNUM
Definition: amd64-tdep.h:46
@ AMD64_R12_REGNUM
Definition: amd64-tdep.h:47
@ AMD64_EFLAGS_REGNUM
Definition: amd64-tdep.h:52
@ AMD64_R8_REGNUM
Definition: amd64-tdep.h:43
@ AMD64_R9_REGNUM
Definition: amd64-tdep.h:44
@ AMD64_GSBASE_REGNUM
Definition: amd64-tdep.h:83
@ AMD64_RCX_REGNUM
Definition: amd64-tdep.h:37
@ AMD64_RBX_REGNUM
Definition: amd64-tdep.h:36
@ AMD64_RBP_REGNUM
Definition: amd64-tdep.h:41
@ AMD64_RSI_REGNUM
Definition: amd64-tdep.h:39
@ AMD64_FSBASE_REGNUM
Definition: amd64-tdep.h:82
@ AMD64_R14_REGNUM
Definition: amd64-tdep.h:49
@ AMD64_ES_REGNUM
Definition: amd64-tdep.h:56
@ AMD64_RIP_REGNUM
Definition: amd64-tdep.h:51
@ AMD64_RDI_REGNUM
Definition: amd64-tdep.h:40
@ AMD64_CS_REGNUM
Definition: amd64-tdep.h:53
@ AMD64_DS_REGNUM
Definition: amd64-tdep.h:55
@ AMD64_GS_REGNUM
Definition: amd64-tdep.h:58
@ AMD64_RDX_REGNUM
Definition: amd64-tdep.h:38
@ AMD64_R13_REGNUM
Definition: amd64-tdep.h:48
@ AMD64_SS_REGNUM
Definition: amd64-tdep.h:54
@ AMD64_R10_REGNUM
Definition: amd64-tdep.h:45
@ AMD64_R15_REGNUM
Definition: amd64-tdep.h:50
@ AMD64_RSP_REGNUM
Definition: amd64-tdep.h:42
enum register_status cooked_read(int regnum, gdb_byte *buf)
Definition: regcache.c:692
ptid_t ptid() const
Definition: regcache.h:407
#define ULONGEST_MAX
Definition: defs.h:473
CORE_ADDR fbsd_get_thread_local_address(struct gdbarch *gdbarch, CORE_ADDR dtv_addr, CORE_ADDR lm_addr, CORE_ADDR offset)
Definition: fbsd-tdep.c:2021
void fbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: fbsd-tdep.c:2374
ULONGEST get_frame_register_unsigned(frame_info_ptr frame, int regnum)
Definition: frame.c:1351
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition: frame.c:713
@ SIGTRAMP_FRAME
Definition: frame.h:190
void set_gdbarch_get_thread_local_address(struct gdbarch *gdbarch, gdbarch_get_thread_local_address_ftype *get_thread_local_address)
void set_gdbarch_core_read_description(struct gdbarch *gdbarch, gdbarch_core_read_description_ftype *core_read_description)
void set_gdbarch_fetch_tls_load_module_address(struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype *fetch_tls_load_module_address)
int gdbarch_ptr_bit(struct gdbarch *gdbarch)
Definition: gdbarch.c:1691
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections)
void() iterate_over_regset_sections_cb(const char *sect_name, int supply_size, int collect_size, const struct regset *regset, const char *human_name, void *cb_data)
Definition: gdbarch.h:102
void i386bsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: i386-bsd-tdep.c:75
uint64_t i386fbsd_core_read_xcr0(bfd *abfd)
#define I386_FBSD_XSAVE_XCR0_OFFSET
struct inferior * current_inferior(void)
Definition: inferior.c:54
static CORE_ADDR lm_addr(struct so_list *so)
Definition: nto-tdep.c:246
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition: osabi.c:146
@ GDB_OSABI_FREEBSD
Definition: osabi.h:33
void regcache_collect_regset(const struct regset *regset, const struct regcache *regcache, int regnum, void *buf, size_t size)
Definition: regcache.c:1264
struct regcache * get_thread_arch_regcache(process_stratum_target *target, ptid_t ptid, struct gdbarch *gdbarch)
Definition: regcache.c:382
void regcache_supply_regset(const struct regset *regset, struct regcache *regcache, int regnum, const void *buf, size_t size)
Definition: regcache.c:1242
@ REGCACHE_MAP_SKIP
Definition: regcache.h:120
void(* func)(remote_target *remote, char *)
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
Definition: solib-svr4.c:3243
struct link_map_offsets * svr4_lp64_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3318
CORE_ADDR svr4_fetch_objfile_link_map(struct objfile *objfile)
Definition: solib-svr4.c:1591
size_t sizeof_fpregset
Definition: i386-tdep.h:68
Definition: regcache.h:110
Definition: regset.h:35
void target_fetch_registers(struct regcache *regcache, int regno)
Definition: target.c:3921
void trad_frame_set_reg_regmap(struct trad_frame_cache *this_trad_cache, const struct regcache_map_entry *regmap, CORE_ADDR addr, size_t size)
Definition: trad-frame.c:117
void trad_frame_set_id(struct trad_frame_cache *this_trad_cache, struct frame_id this_id)
Definition: trad-frame.c:220
void tramp_frame_prepend_unwinder(struct gdbarch *gdbarch, const struct tramp_frame *tramp_frame)
Definition: tramp-frame.c:147
#define TRAMP_SENTINEL_INSN
Definition: tramp-frame.h:44