Commit | Line | Data |
---|---|---|
5cd226f2 | 1 | /* Darwin support for GDB, the GNU debugger. |
4c38e0a4 | 2 | Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2005, 2008, 2009, 2010 |
5cd226f2 TG |
3 | Free Software Foundation, Inc. |
4 | ||
5 | Contributed by Apple Computer, Inc. | |
6 | ||
7 | This file is part of GDB. | |
8 | ||
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. | |
13 | ||
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. | |
18 | ||
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/>. */ | |
21 | ||
22 | #include "defs.h" | |
23 | #include "frame.h" | |
24 | #include "inferior.h" | |
25 | #include "gdbcore.h" | |
26 | #include "target.h" | |
27 | #include "floatformat.h" | |
28 | #include "symtab.h" | |
29 | #include "regcache.h" | |
30 | #include "libbfd.h" | |
31 | #include "objfiles.h" | |
32 | ||
33 | #include "i387-tdep.h" | |
34 | #include "amd64-tdep.h" | |
35 | #include "osabi.h" | |
36 | #include "ui-out.h" | |
37 | #include "symtab.h" | |
38 | #include "frame.h" | |
39 | #include "gdb_assert.h" | |
40 | #include "amd64-darwin-tdep.h" | |
41 | #include "i386-darwin-tdep.h" | |
42 | #include "solib.h" | |
43 | #include "solib-darwin.h" | |
44 | #include "dwarf2-frame.h" | |
45 | ||
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[] = | |
49 | { | |
50 | 0 * 8, /* %rax */ | |
51 | 1 * 8, /* %rbx */ | |
52 | 2 * 8, /* %rcx */ | |
53 | 3 * 8, /* %rdx */ | |
54 | 5 * 8, /* %rsi */ | |
55 | 4 * 8, /* %rdi */ | |
56 | 6 * 8, /* %rbp */ | |
57 | 7 * 8, /* %rsp */ | |
58 | 8 * 8, /* %r8 ... */ | |
59 | 9 * 8, | |
60 | 10 * 8, | |
61 | 11 * 8, | |
62 | 12 * 8, | |
63 | 13 * 8, | |
64 | 14 * 8, | |
65 | 15 * 8, /* ... %r15 */ | |
66 | 16 * 8, /* %rip */ | |
67 | 17 * 8, /* %rflags */ | |
68 | 18 * 8, /* %cs */ | |
69 | -1, /* %ss */ | |
70 | -1, /* %ds */ | |
71 | -1, /* %es */ | |
72 | 19 * 8, /* %fs */ | |
73 | 20 * 8 /* %gs */ | |
74 | }; | |
75 | ||
76 | const int amd64_darwin_thread_state_num_regs = | |
77 | ARRAY_SIZE (amd64_darwin_thread_state_reg_offset); | |
78 | ||
79 | /* Assuming THIS_FRAME is a Darwin sigtramp routine, return the | |
80 | address of the associated sigcontext structure. */ | |
81 | ||
82 | static CORE_ADDR | |
83 | amd64_darwin_sigcontext_addr (struct frame_info *this_frame) | |
84 | { | |
85 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
86 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
87 | CORE_ADDR rbx; | |
88 | CORE_ADDR si; | |
89 | gdb_byte buf[8]; | |
90 | ||
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); | |
95 | ||
96 | /* The pointer to mcontext is at offset 48. */ | |
97 | read_memory (rbx + 48, buf, 8); | |
98 | ||
99 | /* First register (rax) is at offset 16. */ | |
100 | return extract_unsigned_integer (buf, 8, byte_order) + 16; | |
101 | } | |
102 | ||
103 | static void | |
104 | x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch) | |
105 | { | |
106 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
107 | ||
108 | amd64_init_abi (info, gdbarch); | |
109 | ||
110 | tdep->struct_return = reg_struct_return; | |
111 | ||
112 | dwarf2_frame_set_signal_frame_p (gdbarch, darwin_dwarf_signal_frame_p); | |
113 | ||
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; | |
118 | ||
119 | tdep->jb_pc_offset = 148; | |
120 | ||
121 | set_solib_ops (gdbarch, &darwin_so_ops); | |
122 | } | |
123 | ||
124 | void | |
125 | _initialize_amd64_darwin_tdep (void) | |
126 | { | |
127 | gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, | |
128 | GDB_OSABI_DARWIN, x86_darwin_init_abi_64); | |
129 | } |