GDB (xrefs)
/tmp/gdb-7.10/gdb/amd64fbsd-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for FreeBSD/amd64.
2 
3  Copyright (C) 2003-2015 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 "arch-utils.h"
22 #include "frame.h"
23 #include "gdbcore.h"
24 #include "regcache.h"
25 #include "osabi.h"
26 #include "regset.h"
27 #include "i386fbsd-tdep.h"
28 #include "x86-xstate.h"
29 
30 #include "amd64-tdep.h"
31 #include "bsd-uthread.h"
32 #include "fbsd-tdep.h"
33 #include "solib-svr4.h"
34 
35 /* Support for signal handlers. */
36 
37 /* Return whether THIS_FRAME corresponds to a FreeBSD sigtramp
38  routine. */
39 
41 {
42  0x48, 0x8d, 0x7c, 0x24, 0x10, /* lea SIGF_UC(%rsp),%rdi */
43  0x6a, 0x00, /* pushq $0 */
44  0x48, 0xc7, 0xc0, 0xa1, 0x01, 0x00, 0x00,
45  /* movq $SYS_sigreturn,%rax */
46  0x0f, 0x05 /* syscall */
47 };
48 
49 static int
50 amd64fbsd_sigtramp_p (struct frame_info *this_frame)
51 {
52  CORE_ADDR pc = get_frame_pc (this_frame);
54 
55  if (!safe_frame_unwind_memory (this_frame, pc, buf, sizeof buf))
56  return 0;
57  if (memcmp (buf, amd64fbsd_sigtramp_code, sizeof amd64fbsd_sigtramp_code)
58  != 0)
59  return 0;
60 
61  return 1;
62 }
63 
64 /* Assuming THIS_FRAME is for a BSD sigtramp routine, return the
65  address of the associated sigcontext structure. */
66 
67 static CORE_ADDR
69 {
70  struct gdbarch *gdbarch = get_frame_arch (this_frame);
71  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
72  CORE_ADDR sp;
73  gdb_byte buf[8];
74 
75  /* The `struct sigcontext' (which really is an `ucontext_t' on
76  FreeBSD/amd64) lives at a fixed offset in the signal frame. See
77  <machine/sigframe.h>. */
78  get_frame_register (this_frame, AMD64_RSP_REGNUM, buf);
79  sp = extract_unsigned_integer (buf, 8, byte_order);
80  return sp + 16;
81 }
82 
83 /* FreeBSD 5.1-RELEASE or later. */
84 
85 /* Mapping between the general-purpose registers in `struct reg'
86  format and GDB's register cache layout.
87 
88  Note that some registers are 32-bit, but since we're little-endian
89  we get away with that. */
90 
91 /* From <machine/reg.h>. */
92 static int amd64fbsd_r_reg_offset[] =
93 {
94  14 * 8, /* %rax */
95  11 * 8, /* %rbx */
96  13 * 8, /* %rcx */
97  12 * 8, /* %rdx */
98  9 * 8, /* %rsi */
99  8 * 8, /* %rdi */
100  10 * 8, /* %rbp */
101  20 * 8, /* %rsp */
102  7 * 8, /* %r8 ... */
103  6 * 8,
104  5 * 8,
105  4 * 8,
106  3 * 8,
107  2 * 8,
108  1 * 8,
109  0 * 8, /* ... %r15 */
110  17 * 8, /* %rip */
111  19 * 8, /* %eflags */
112  18 * 8, /* %cs */
113  21 * 8, /* %ss */
114  -1, /* %ds */
115  -1, /* %es */
116  -1, /* %fs */
117  -1 /* %gs */
118 };
119 
120 /* Location of the signal trampoline. */
123 
124 /* From <machine/signal.h>. */
126 {
127  24 + 6 * 8, /* %rax */
128  24 + 7 * 8, /* %rbx */
129  24 + 3 * 8, /* %rcx */
130  24 + 2 * 8, /* %rdx */
131  24 + 1 * 8, /* %rsi */
132  24 + 0 * 8, /* %rdi */
133  24 + 8 * 8, /* %rbp */
134  24 + 22 * 8, /* %rsp */
135  24 + 4 * 8, /* %r8 ... */
136  24 + 5 * 8,
137  24 + 9 * 8,
138  24 + 10 * 8,
139  24 + 11 * 8,
140  24 + 12 * 8,
141  24 + 13 * 8,
142  24 + 14 * 8, /* ... %r15 */
143  24 + 19 * 8, /* %rip */
144  24 + 21 * 8, /* %eflags */
145  24 + 20 * 8, /* %cs */
146  24 + 23 * 8, /* %ss */
147  -1, /* %ds */
148  -1, /* %es */
149  -1, /* %fs */
150  -1 /* %gs */
151 };
152 
153 /* From /usr/src/lib/libc/amd64/gen/_setjmp.S. */
155 {
156  -1, /* %rax */
157  1 * 8, /* %rbx */
158  -1, /* %rcx */
159  -1, /* %rdx */
160  -1, /* %rsi */
161  -1, /* %rdi */
162  3 * 8, /* %rbp */
163  2 * 8, /* %rsp */
164  -1, /* %r8 ... */
165  -1,
166  -1,
167  -1, /* ... %r11 */
168  4 * 8, /* %r12 ... */
169  5 * 8,
170  6 * 8,
171  7 * 8, /* ... %r15 */
172  0 * 8 /* %rip */
173 };
174 
175 /* Implement the core_read_description gdbarch method. */
176 
177 static const struct target_desc *
179  struct target_ops *target,
180  bfd *abfd)
181 {
183 }
184 
185 /* Similar to amd64_supply_fpregset, but use XSAVE extended state. */
186 
187 static void
189  struct regcache *regcache, int regnum,
190  const void *xstateregs, size_t len)
191 {
192  amd64_supply_xsave (regcache, regnum, xstateregs);
193 }
194 
195 /* Similar to amd64_collect_fpregset, but use XSAVE extended state. */
196 
197 static void
199  const struct regcache *regcache,
200  int regnum, void *xstateregs, size_t len)
201 {
202  amd64_collect_xsave (regcache, regnum, xstateregs, 1);
203 }
204 
205 static const struct regset amd64fbsd_xstateregset =
206  {
207  NULL,
210  };
211 
212 /* Iterate over core file register note sections. */
213 
214 static void
217  void *cb_data,
218  const struct regcache *regcache)
219 {
220  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
221 
222  cb (".reg", tdep->sizeof_gregset, &i386_gregset, NULL, cb_data);
223  cb (".reg2", tdep->sizeof_fpregset, &amd64_fpregset, NULL, cb_data);
224  cb (".reg-xstate", X86_XSTATE_SIZE(tdep->xcr0),
225  &amd64fbsd_xstateregset, "XSAVE extended state", cb_data);
226 }
227 
228 static void
230  int regnum, CORE_ADDR addr)
231 {
232  gdb_byte buf[8];
233  int i;
234 
235  gdb_assert (regnum >= -1);
236 
237  for (i = 0; i < ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset); i++)
238  {
239  if (amd64fbsd_jmp_buf_reg_offset[i] != -1
240  && (regnum == -1 || regnum == i))
241  {
242  read_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8);
243  regcache_raw_supply (regcache, i, buf);
244  }
245  }
246 }
247 
248 static void
250  int regnum, CORE_ADDR addr)
251 {
252  gdb_byte buf[8];
253  int i;
254 
255  gdb_assert (regnum >= -1);
256 
257  for (i = 0; i < ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset); i++)
258  {
259  if (amd64fbsd_jmp_buf_reg_offset[i] != -1
260  && (regnum == -1 || regnum == i))
261  {
262  regcache_raw_collect (regcache, i, buf);
263  write_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8);
264  }
265  }
266 }
267 
268 static void
270 {
271  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
272 
273  /* Generic FreeBSD support. */
274  fbsd_init_abi (info, gdbarch);
275 
276  /* Obviously FreeBSD is BSD-based. */
277  i386bsd_init_abi (info, gdbarch);
278 
280  tdep->gregset_num_regs = ARRAY_SIZE (amd64fbsd_r_reg_offset);
281  tdep->sizeof_gregset = 22 * 8;
282 
283  amd64_init_abi (info, gdbarch);
284 
290  tdep->sc_num_regs = ARRAY_SIZE (amd64fbsd_sc_reg_offset);
291 
293 
294  /* Iterate over core file register note sections. */
297 
300 
301  /* FreeBSD provides a user-level threads implementation. */
304 
305  /* FreeBSD uses SVR4-style shared libraries. */
308 }
309 
310 
311 /* Provide a prototype to silence -Wmissing-prototypes. */
312 void _initialize_amd64fbsd_tdep (void);
313 
314 void
316 {
317  gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
319 }
void _initialize_amd64fbsd_tdep(void)
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
Definition: findvar.c:84
int xsave_xcr0_offset
Definition: i386-tdep.h:142
static void amd64fbsd_collect_xstateregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *xstateregs, size_t len)
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2217
void i386bsd_init_abi(struct gdbarch_info, struct gdbarch *)
Definition: i386bsd-tdep.c:75
bfd_vma CORE_ADDR
Definition: common-types.h:41
struct link_map_offsets * svr4_lp64_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3180
int sc_num_regs
Definition: i386-tdep.h:216
CORE_ADDR sigtramp_start
Definition: i386-tdep.h:205
static CORE_ADDR amd64fbsd_sigcontext_addr(struct frame_info *this_frame)
CORE_ADDR sigtramp_end
Definition: i386-tdep.h:206
struct m32c_reg * pc
Definition: m32c-tdep.c:111
static void amd64fbsd_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
CORE_ADDR(* sigcontext_addr)(struct frame_info *)
Definition: alpha-tdep.h:82
static const struct target_desc * amd64fbsd_core_read_description(struct gdbarch *gdbarch, struct target_ops *target, bfd *abfd)
void bsd_uthread_set_collect_uthread(struct gdbarch *gdbarch, void(*collect_uthread)(const struct regcache *, int, CORE_ADDR))
Definition: bsd-uthread.c:79
uint64_t i386fbsd_core_read_xcr0(bfd *abfd)
size_t sizeof_fpregset
Definition: i386-tdep.h:64
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1402
static void amd64fbsd_supply_xstateregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *xstateregs, size_t len)
#define X86_XSTATE_SIZE(XCR0)
Definition: x86-xstate.h:62
static const gdb_byte amd64fbsd_sigtramp_code[]
Definition: regset.h:34
static void amd64fbsd_collect_uthread(const struct regcache *regcache, int regnum, CORE_ADDR addr)
int safe_frame_unwind_memory(struct frame_info *this_frame, CORE_ADDR addr, gdb_byte *buf, int len)
Definition: frame.c:2525
void amd64_supply_xsave(struct regcache *regcache, int regnum, const void *xsave)
Definition: amd64-tdep.c:3196
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1420
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
Definition: solib-svr4.c:3108
void fbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: fbsd-tdep.c:132
#define gdb_assert(expr)
Definition: gdb_assert.h:33
const struct regset i386_gregset
Definition: i386-tdep.c:3819
int regnum
Definition: aarch64-tdep.c:69
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:244
void( iterate_over_regset_sections_cb)(const char *sect_name, int size, const struct regset *regset, const char *human_name, void *cb_data)
Definition: gdbarch.h:98
int * gregset_reg_offset
Definition: i386-tdep.h:59
const struct regset amd64_fpregset
Definition: amd64-tdep.c:2889
static int amd64fbsd_r_reg_offset[]
static int amd64fbsd_jmp_buf_reg_offset[]
int amd64fbsd_sc_reg_offset[]
bfd_byte gdb_byte
Definition: common-types.h:38
int(* sigtramp_p)(struct frame_info *)
Definition: i386-tdep.h:209
uint64_t xcr0
Definition: i386-tdep.h:139
CORE_ADDR amd64fbsd_sigtramp_start_addr
void amd64_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: amd64-tdep.c:2937
void get_frame_register(struct frame_info *frame, int regnum, gdb_byte *buf)
Definition: frame.c:1085
size_t sizeof_gregset
Definition: i386-tdep.h:61
#define I386_FBSD_XSAVE_XCR0_OFFSET
Definition: i386fbsd-tdep.h:29
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1041
int * sc_reg_offset
Definition: i386-tdep.h:215
void regcache_raw_collect(const struct regcache *regcache, int regnum, void *buf)
Definition: regcache.c:1071
void amd64_collect_xsave(const struct regcache *regcache, int regnum, void *xsave, int gcore)
Definition: amd64-tdep.c:3245
static void amd64fbsd_supply_uthread(struct regcache *regcache, int regnum, CORE_ADDR addr)
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype iterate_over_regset_sections)
Definition: gdbarch.c:3398
static void amd64fbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
void write_memory(CORE_ADDR memaddr, const bfd_byte *myaddr, ssize_t len)
Definition: corefile.c:389
CORE_ADDR amd64fbsd_sigtramp_end_addr
void bsd_uthread_set_supply_uthread(struct gdbarch *gdbarch, void(*supply_uthread)(struct regcache *, int, CORE_ADDR))
Definition: bsd-uthread.c:67
int gregset_num_regs
Definition: i386-tdep.h:60
const struct target_desc * amd64_target_description(uint64_t xcr0)
Definition: amd64-tdep.c:3127
enum bfd_endian byte_order
Definition: gdbarch.c:128
void set_gdbarch_core_read_description(struct gdbarch *gdbarch, gdbarch_core_read_description_ftype core_read_description)
Definition: gdbarch.c:3816
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:148
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2535
static int amd64fbsd_sigtramp_p(struct frame_info *this_frame)
const ULONGEST const LONGEST len
Definition: target.h:309