1 /* Darwin support for GDB, the GNU debugger.
2 Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2005, 2008, 2009
3 Free Software Foundation, Inc.
5 Contributed by Apple Computer, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "floatformat.h"
33 #include "i387-tdep.h"
34 #include "amd64-tdep.h"
39 #include "gdb_assert.h"
40 #include "amd64-darwin-tdep.h"
41 #include "i386-darwin-tdep.h"
43 #include "solib-darwin.h"
44 #include "dwarf2-frame.h"
46 /* Offsets into the struct x86_thread_state64 where we'll find the saved regs.
47 From <mach/i386/thread_status.h> and amd64-tdep.h. */
48 int amd64_darwin_thread_state_reg_offset
[] =
65 15 * 8, /* ... %r15 */
76 const int amd64_darwin_thread_state_num_regs
=
77 ARRAY_SIZE (amd64_darwin_thread_state_reg_offset
);
79 /* Assuming THIS_FRAME is a Darwin sigtramp routine, return the
80 address of the associated sigcontext structure. */
83 amd64_darwin_sigcontext_addr (struct frame_info
*this_frame
)
85 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
86 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
91 /* A pointer to the ucontext is passed as the fourth argument
92 to the signal handler, which is saved in rbx. */
93 get_frame_register (this_frame
, AMD64_RBX_REGNUM
, buf
);
94 rbx
= extract_unsigned_integer (buf
, 8, byte_order
);
96 /* The pointer to mcontext is at offset 48. */
97 read_memory (rbx
+ 48, buf
, 8);
99 /* First register (rax) is at offset 16. */
100 return extract_unsigned_integer (buf
, 8, byte_order
) + 16;
104 x86_darwin_init_abi_64 (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
106 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
108 amd64_init_abi (info
, gdbarch
);
110 tdep
->struct_return
= reg_struct_return
;
112 dwarf2_frame_set_signal_frame_p (gdbarch
, darwin_dwarf_signal_frame_p
);
114 tdep
->sigtramp_p
= i386_sigtramp_p
;
115 tdep
->sigcontext_addr
= amd64_darwin_sigcontext_addr
;
116 tdep
->sc_reg_offset
= amd64_darwin_thread_state_reg_offset
;
117 tdep
->sc_num_regs
= amd64_darwin_thread_state_num_regs
;
119 tdep
->jb_pc_offset
= 148;
121 set_solib_ops (gdbarch
, &darwin_so_ops
);
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
);