]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/i386-darwin-tdep.c
PR 10474
[thirdparty/binutils-gdb.git] / gdb / i386-darwin-tdep.c
CommitLineData
a80b95ba 1/* Darwin support for GDB, the GNU debugger.
0fb0cc75 2 Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2005, 2008, 2009
a80b95ba
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 "i386-tdep.h"
a80b95ba
TG
35#include "osabi.h"
36#include "ui-out.h"
37#include "symtab.h"
38#include "frame.h"
39#include "gdb_assert.h"
40#include "i386-darwin-tdep.h"
cf1061c0
TG
41#include "solib.h"
42#include "solib-darwin.h"
9f08ae4f 43#include "dwarf2-frame.h"
a80b95ba
TG
44
45/* Offsets into the struct i386_thread_state where we'll find the saved regs.
46 From <mach/i386/thread_status.h> and i386-tdep.h. */
47int i386_darwin_thread_state_reg_offset[] =
48{
49 0 * 4, /* EAX */
50 2 * 4, /* ECX */
51 3 * 4, /* EDX */
52 1 * 4, /* EBX */
53 7 * 4, /* ESP */
54 6 * 4, /* EBP */
55 5 * 4, /* ESI */
56 4 * 4, /* EDI */
57 10 * 4, /* EIP */
58 9 * 4, /* EFLAGS */
59 11 * 4, /* CS */
60 8, /* SS */
61 12 * 4, /* DS */
62 13 * 4, /* ES */
63 14 * 4, /* FS */
64 15 * 4 /* GS */
65};
66
67const int i386_darwin_thread_state_num_regs =
68 ARRAY_SIZE (i386_darwin_thread_state_reg_offset);
69
9f08ae4f
TG
70/* Assuming THIS_FRAME is a Darwin sigtramp routine, return the
71 address of the associated sigcontext structure. */
72
73static CORE_ADDR
74i386_darwin_sigcontext_addr (struct frame_info *this_frame)
75{
e17a4113
UW
76 struct gdbarch *gdbarch = get_frame_arch (this_frame);
77 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
9f08ae4f
TG
78 CORE_ADDR bp;
79 CORE_ADDR si;
80 gdb_byte buf[4];
81
82 get_frame_register (this_frame, I386_EBP_REGNUM, buf);
e17a4113 83 bp = extract_unsigned_integer (buf, 4, byte_order);
9f08ae4f
TG
84
85 /* A pointer to the ucontext is passed as the fourth argument
86 to the signal handler. */
87 read_memory (bp + 24, buf, 4);
e17a4113 88 si = extract_unsigned_integer (buf, 4, byte_order);
9f08ae4f
TG
89
90 /* The pointer to mcontext is at offset 28. */
91 read_memory (si + 28, buf, 4);
92
93 /* First register (eax) is at offset 12. */
e17a4113 94 return extract_unsigned_integer (buf, 4, byte_order) + 12;
9f08ae4f
TG
95}
96
9f08ae4f
TG
97/* Return true if the PC of THIS_FRAME is in a signal trampoline which
98 may have DWARF-2 CFI.
99
100 On Darwin, signal trampolines have DWARF-2 CFI but it has only one FDE
101 that covers only the indirect call to the user handler.
102 Without this function, the frame is recognized as a normal frame which is
103 not expected. */
104
5cd226f2 105int
9f08ae4f
TG
106darwin_dwarf_signal_frame_p (struct gdbarch *gdbarch,
107 struct frame_info *this_frame)
108{
109 return i386_sigtramp_p (this_frame);
110}
111
a80b95ba
TG
112static void
113i386_darwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
114{
115 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
116
117 /* We support the SSE registers. */
118 tdep->num_xmm_regs = I386_NUM_XREGS - 1;
119 set_gdbarch_num_regs (gdbarch, I386_SSE_NUM_REGS);
120
9f08ae4f
TG
121 dwarf2_frame_set_signal_frame_p (gdbarch, darwin_dwarf_signal_frame_p);
122
a80b95ba
TG
123 tdep->struct_return = reg_struct_return;
124
9f08ae4f
TG
125 tdep->sigtramp_p = i386_sigtramp_p;
126 tdep->sigcontext_addr = i386_darwin_sigcontext_addr;
a80b95ba 127 tdep->sc_reg_offset = i386_darwin_thread_state_reg_offset;
9f08ae4f 128 tdep->sc_num_regs = i386_darwin_thread_state_num_regs;
a80b95ba
TG
129
130 tdep->jb_pc_offset = 20;
cf1061c0
TG
131
132 set_solib_ops (gdbarch, &darwin_so_ops);
a80b95ba
TG
133}
134
a80b95ba
TG
135static enum gdb_osabi
136i386_mach_o_osabi_sniffer (bfd *abfd)
137{
138 if (!bfd_check_format (abfd, bfd_object))
139 return GDB_OSABI_UNKNOWN;
140
141 if (bfd_get_arch (abfd) == bfd_arch_i386)
142 return GDB_OSABI_DARWIN;
143
144 return GDB_OSABI_UNKNOWN;
145}
146
147void
148_initialize_i386_darwin_tdep (void)
149{
150 gdbarch_register_osabi_sniffer (bfd_arch_unknown, bfd_target_mach_o_flavour,
151 i386_mach_o_osabi_sniffer);
152
153 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_i386_i386,
154 GDB_OSABI_DARWIN, i386_darwin_init_abi);
a80b95ba 155}