2012-03-01 Pedro Alves <palves@redhat.com>
[deliverable/binutils-gdb.git] / gdb / amd64-darwin-tdep.c
CommitLineData
5cd226f2 1/* Darwin support for GDB, the GNU debugger.
0b302171 2 Copyright 1997-2002, 2005, 2008-2012 Free Software Foundation, Inc.
5cd226f2
TG
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 "floatformat.h"
27#include "symtab.h"
28#include "regcache.h"
29#include "libbfd.h"
30#include "objfiles.h"
31
32#include "i387-tdep.h"
33#include "amd64-tdep.h"
34#include "osabi.h"
35#include "ui-out.h"
36#include "symtab.h"
37#include "frame.h"
38#include "gdb_assert.h"
39#include "amd64-darwin-tdep.h"
40#include "i386-darwin-tdep.h"
41#include "solib.h"
42#include "solib-darwin.h"
43#include "dwarf2-frame.h"
44
45/* Offsets into the struct x86_thread_state64 where we'll find the saved regs.
46 From <mach/i386/thread_status.h> and amd64-tdep.h. */
47int amd64_darwin_thread_state_reg_offset[] =
48{
49 0 * 8, /* %rax */
50 1 * 8, /* %rbx */
51 2 * 8, /* %rcx */
52 3 * 8, /* %rdx */
53 5 * 8, /* %rsi */
54 4 * 8, /* %rdi */
55 6 * 8, /* %rbp */
56 7 * 8, /* %rsp */
0963b4bd 57 8 * 8, /* %r8 ... */
5cd226f2
TG
58 9 * 8,
59 10 * 8,
60 11 * 8,
61 12 * 8,
62 13 * 8,
63 14 * 8,
64 15 * 8, /* ... %r15 */
65 16 * 8, /* %rip */
66 17 * 8, /* %rflags */
67 18 * 8, /* %cs */
68 -1, /* %ss */
69 -1, /* %ds */
70 -1, /* %es */
71 19 * 8, /* %fs */
72 20 * 8 /* %gs */
73};
74
75const int amd64_darwin_thread_state_num_regs =
76 ARRAY_SIZE (amd64_darwin_thread_state_reg_offset);
77
78/* Assuming THIS_FRAME is a Darwin sigtramp routine, return the
79 address of the associated sigcontext structure. */
80
81static CORE_ADDR
82amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
83{
84 struct gdbarch *gdbarch = get_frame_arch (this_frame);
85 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
86 CORE_ADDR rbx;
87 CORE_ADDR si;
88 gdb_byte buf[8];
89
90 /* A pointer to the ucontext is passed as the fourth argument
91 to the signal handler, which is saved in rbx. */
92 get_frame_register (this_frame, AMD64_RBX_REGNUM, buf);
93 rbx = extract_unsigned_integer (buf, 8, byte_order);
94
95 /* The pointer to mcontext is at offset 48. */
96 read_memory (rbx + 48, buf, 8);
97
98 /* First register (rax) is at offset 16. */
99 return extract_unsigned_integer (buf, 8, byte_order) + 16;
100}
101
102static void
103x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
104{
105 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
106
107 amd64_init_abi (info, gdbarch);
108
109 tdep->struct_return = reg_struct_return;
110
111 dwarf2_frame_set_signal_frame_p (gdbarch, darwin_dwarf_signal_frame_p);
112
113 tdep->sigtramp_p = i386_sigtramp_p;
114 tdep->sigcontext_addr = amd64_darwin_sigcontext_addr;
115 tdep->sc_reg_offset = amd64_darwin_thread_state_reg_offset;
116 tdep->sc_num_regs = amd64_darwin_thread_state_num_regs;
117
6f124894 118 tdep->jb_pc_offset = 56;
5cd226f2
TG
119
120 set_solib_ops (gdbarch, &darwin_so_ops);
121}
122
123void
124_initialize_amd64_darwin_tdep (void)
125{
126 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
127 GDB_OSABI_DARWIN, x86_darwin_init_abi_64);
128}
This page took 0.410434 seconds and 4 git commands to generate.