1 /* Darwin support for GDB, the GNU debugger.
2 Copyright (C) 1997-2014 Free Software Foundation, Inc.
4 Contributed by Apple Computer, Inc.
6 This file is part of GDB.
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.
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.
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/>. */
26 #include "floatformat.h"
32 #include "i387-tdep.h"
33 #include "amd64-tdep.h"
38 #include "amd64-darwin-tdep.h"
39 #include "i386-darwin-tdep.h"
41 #include "solib-darwin.h"
42 #include "dwarf2-frame.h"
44 /* Offsets into the struct x86_thread_state64 where we'll find the saved regs.
45 From <mach/i386/thread_status.h> and amd64-tdep.h. */
46 int amd64_darwin_thread_state_reg_offset[] =
63 15 * 8, /* ... %r15 */
74 const int amd64_darwin_thread_state_num_regs =
75 ARRAY_SIZE (amd64_darwin_thread_state_reg_offset);
77 /* Assuming THIS_FRAME is a Darwin sigtramp routine, return the
78 address of the associated sigcontext structure. */
81 amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
83 struct gdbarch *gdbarch = get_frame_arch (this_frame);
84 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
88 /* A pointer to the ucontext is passed as the fourth argument
89 to the signal handler, which is saved in rbx. */
90 get_frame_register (this_frame, AMD64_RBX_REGNUM, buf);
91 rbx = extract_unsigned_integer (buf, 8, byte_order);
93 /* The pointer to mcontext is at offset 48. */
94 read_memory (rbx + 48, buf, 8);
96 /* First register (rax) is at offset 16. */
97 return extract_unsigned_integer (buf, 8, byte_order) + 16;
101 x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
103 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
105 amd64_init_abi (info, gdbarch);
107 tdep->struct_return = reg_struct_return;
109 dwarf2_frame_set_signal_frame_p (gdbarch, darwin_dwarf_signal_frame_p);
111 tdep->sigtramp_p = i386_sigtramp_p;
112 tdep->sigcontext_addr = amd64_darwin_sigcontext_addr;
113 tdep->sc_reg_offset = amd64_darwin_thread_state_reg_offset;
114 tdep->sc_num_regs = amd64_darwin_thread_state_num_regs;
116 tdep->jb_pc_offset = 56;
118 set_solib_ops (gdbarch, &darwin_so_ops);
121 /* -Wmissing-prototypes */
122 extern initialize_file_ftype _initialize_amd64_darwin_tdep;
125 _initialize_amd64_darwin_tdep (void)
127 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
128 GDB_OSABI_DARWIN, x86_darwin_init_abi_64);