GDB (xrefs)

/tmp/gdb-8.1/gdb/amd64-darwin-tdep.c
Go to the documentation of this file.
1 /* Darwin support for GDB, the GNU debugger.
2 Copyright (C) 1997-2018 Free Software Foundation, Inc.
3
4 Contributed by Apple Computer, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #include "defs.h"
22 #include "frame.h"
23 #include "inferior.h"
24 #include "gdbcore.h"
25 #include "target.h"
26 #include "symtab.h"
27 #include "regcache.h"
28 #include "objfiles.h"
29
30 #include "i387-tdep.h"
31 #include "x86-xstate.h"
32 #include "amd64-tdep.h"
33 #include "osabi.h"
34 #include "ui-out.h"
35 #include "amd64-darwin-tdep.h"
36 #include "i386-darwin-tdep.h"
37 #include "solib.h"
38 #include "solib-darwin.h"
39 #include "dwarf2-frame.h"
40
41 /* Offsets into the struct x86_thread_state64 where we'll find the saved regs.
42 From <mach/i386/thread_status.h> and amd64-tdep.h. */
43 int amd64_darwin_thread_state_reg_offset[] =
44 {
45 0 * 8, /* %rax */
46 1 * 8, /* %rbx */
47 2 * 8, /* %rcx */
48 3 * 8, /* %rdx */
49 5 * 8, /* %rsi */
50 4 * 8, /* %rdi */
51 6 * 8, /* %rbp */
52 7 * 8, /* %rsp */
53 8 * 8, /* %r8 ... */
54 9 * 8,
55 10 * 8,
56 11 * 8,
57 12 * 8,
58 13 * 8,
59 14 * 8,
60 15 * 8, /* ... %r15 */
61 16 * 8, /* %rip */
62 17 * 8, /* %rflags */
63 18 * 8, /* %cs */
64 -1, /* %ss */
65 -1, /* %ds */
66 -1, /* %es */
67 19 * 8, /* %fs */
68 20 * 8 /* %gs */
69 };
70
71 const int amd64_darwin_thread_state_num_regs =
72 ARRAY_SIZE (amd64_darwin_thread_state_reg_offset);
73
74 /* Assuming THIS_FRAME is a Darwin sigtramp routine, return the
75 address of the associated sigcontext structure. */
76
77 static CORE_ADDR
78 amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
79 {
80 struct gdbarch *gdbarch = get_frame_arch (this_frame);
81 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
82 CORE_ADDR rbx;
83 gdb_byte buf[8];
84
85 /* A pointer to the ucontext is passed as the fourth argument
86 to the signal handler, which is saved in rbx. */
87 get_frame_register (this_frame, AMD64_RBX_REGNUM, buf);
88 rbx = extract_unsigned_integer (buf, 8, byte_order);
89
90 /* The pointer to mcontext is at offset 48. */
91 read_memory (rbx + 48, buf, 8);
92
93 /* First register (rax) is at offset 16. */
94 return extract_unsigned_integer (buf, 8, byte_order) + 16;
95 }
96
97 static void
98 x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
99 {
100 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
101
102 amd64_init_abi (info, gdbarch,
103 amd64_target_description (X86_XSTATE_SSE_MASK));
104
105 tdep->struct_return = reg_struct_return;
106
107 dwarf2_frame_set_signal_frame_p (gdbarch, darwin_dwarf_signal_frame_p);
108
109 tdep->sigtramp_p = i386_sigtramp_p;
110 tdep->sigcontext_addr = amd64_darwin_sigcontext_addr;
111 tdep->sc_reg_offset = amd64_darwin_thread_state_reg_offset;
112 tdep->sc_num_regs = amd64_darwin_thread_state_num_regs;
113
114 tdep->jb_pc_offset = 56;
115
116 set_solib_ops (gdbarch, &darwin_so_ops);
117 }
118
119 void
120 _initialize_amd64_darwin_tdep (void)
121 {
122 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
123 GDB_OSABI_DARWIN, x86_darwin_init_abi_64);
124 }
gdbarch
Definition: gdbarch.c:127
gdbarch_tdep::jb_pc_offset
int jb_pc_offset
Definition: i386-tdep.h:210
solib-darwin.h
X86_XSTATE_SSE_MASK
#define X86_XSTATE_SSE_MASK
Definition: x86-xstate.h:42
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
AMD64_RBX_REGNUM
Definition: amd64-tdep.h:35
gdbarch_tdep::sc_num_regs
int sc_num_regs
Definition: i386-tdep.h:227
amd64_init_abi
void amd64_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch, const target_desc *default_tdesc)
Definition: amd64-tdep.c:3037
set_solib_ops
void set_solib_ops(struct gdbarch *gdbarch, const struct target_so_ops *new_ops)
Definition: solib.c:77
gdbarch_tdep
Definition: aarch64-tdep.h:55
i386_sigtramp_p
int i386_sigtramp_p(struct frame_info *this_frame)
Definition: i386-tdep.c:3988
darwin_dwarf_signal_frame_p
int darwin_dwarf_signal_frame_p(struct gdbarch *gdbarch, struct frame_info *this_frame)
Definition: i386-darwin-tdep.c:101
amd64-darwin-tdep.h
gdbarch_tdep::sigcontext_addr
CORE_ADDR(* sigcontext_addr)(struct frame_info *)
Definition: alpha-tdep.h:82
frame_info
Definition: frame.c:85
x86-xstate.h
dwarf2_frame_set_signal_frame_p
void dwarf2_frame_set_signal_frame_p(struct gdbarch *gdbarch, int(*signal_frame_p)(struct gdbarch *, struct frame_info *))
Definition: dwarf2-frame.c:771
defs.h
gdbarch_tdep
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1491
objfiles.h
symtab.h
x86_darwin_init_abi_64
static void x86_darwin_init_abi_64(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: amd64-darwin-tdep.c:98
gdbarch_tdep::struct_return
enum struct_return struct_return
Definition: arm-tdep.h:137
extract_unsigned_integer
static ULONGEST extract_unsigned_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
Definition: defs.h:577
osabi.h
regcache.h
reg_struct_return
Definition: arm-tdep.h:91
frame.h
gdbarch_byte_order
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1509
inferior.h
darwin_so_ops
struct target_so_ops darwin_so_ops
Definition: solib-darwin.c:649
solib.h
_initialize_amd64_darwin_tdep
void _initialize_amd64_darwin_tdep(void)
Definition: amd64-darwin-tdep.c:120
amd64-tdep.h
read_memory
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:258
GDB_OSABI_DARWIN
Definition: defs.h:527
gdbarch_register_osabi
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:143
amd64_darwin_thread_state_num_regs
const int amd64_darwin_thread_state_num_regs
Definition: amd64-darwin-tdep.c:71
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
gdbarch_tdep::sigtramp_p
int(* sigtramp_p)(struct frame_info *)
Definition: i386-tdep.h:220
dwarf2-frame.h
gdbcore.h
i386-darwin-tdep.h
get_frame_register
void get_frame_register(struct frame_info *frame, int regnum, gdb_byte *buf)
Definition: frame.c:1165
amd64_darwin_thread_state_reg_offset
int amd64_darwin_thread_state_reg_offset[]
Definition: amd64-darwin-tdep.c:43
target.h
amd64_darwin_sigcontext_addr
static CORE_ADDR amd64_darwin_sigcontext_addr(struct frame_info *this_frame)
Definition: amd64-darwin-tdep.c:78
gdbarch_tdep::sc_reg_offset
int * sc_reg_offset
Definition: i386-tdep.h:226
gdbarch_info
Definition: gdbarch.h:1626
i387-tdep.h
amd64_target_description
const struct target_desc * amd64_target_description(uint64_t xcr0)
Definition: amd64-tdep.c:3246
gdbarch::byte_order
enum bfd_endian byte_order
Definition: gdbarch.c:137
get_frame_arch
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2691
ui-out.h