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 "i386-tdep.h"
39 #include "gdb_assert.h"
40 #include "i386-darwin-tdep.h"
42 #include "solib-darwin.h"
43 #include "dwarf2-frame.h"
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. */
47 int i386_darwin_thread_state_reg_offset
[] =
67 const int i386_darwin_thread_state_num_regs
=
68 ARRAY_SIZE (i386_darwin_thread_state_reg_offset
);
70 /* Assuming THIS_FRAME is a Darwin sigtramp routine, return the
71 address of the associated sigcontext structure. */
74 i386_darwin_sigcontext_addr (struct frame_info
*this_frame
)
76 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
77 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
82 get_frame_register (this_frame
, I386_EBP_REGNUM
, buf
);
83 bp
= extract_unsigned_integer (buf
, 4, byte_order
);
85 /* A pointer to the ucontext is passed as the fourth argument
86 to the signal handler. */
87 read_memory (bp
+ 24, buf
, 4);
88 si
= extract_unsigned_integer (buf
, 4, byte_order
);
90 /* The pointer to mcontext is at offset 28. */
91 read_memory (si
+ 28, buf
, 4);
93 /* First register (eax) is at offset 12. */
94 return extract_unsigned_integer (buf
, 4, byte_order
) + 12;
97 /* Return true if the PC of THIS_FRAME is in a signal trampoline which
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
106 darwin_dwarf_signal_frame_p (struct gdbarch
*gdbarch
,
107 struct frame_info
*this_frame
)
109 return i386_sigtramp_p (this_frame
);
113 i386_darwin_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
115 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
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
);
121 dwarf2_frame_set_signal_frame_p (gdbarch
, darwin_dwarf_signal_frame_p
);
123 tdep
->struct_return
= reg_struct_return
;
125 tdep
->sigtramp_p
= i386_sigtramp_p
;
126 tdep
->sigcontext_addr
= i386_darwin_sigcontext_addr
;
127 tdep
->sc_reg_offset
= i386_darwin_thread_state_reg_offset
;
128 tdep
->sc_num_regs
= i386_darwin_thread_state_num_regs
;
130 tdep
->jb_pc_offset
= 20;
132 set_solib_ops (gdbarch
, &darwin_so_ops
);
135 static enum gdb_osabi
136 i386_mach_o_osabi_sniffer (bfd
*abfd
)
138 if (!bfd_check_format (abfd
, bfd_object
))
139 return GDB_OSABI_UNKNOWN
;
141 if (bfd_get_arch (abfd
) == bfd_arch_i386
)
142 return GDB_OSABI_DARWIN
;
144 return GDB_OSABI_UNKNOWN
;
148 _initialize_i386_darwin_tdep (void)
150 gdbarch_register_osabi_sniffer (bfd_arch_unknown
, bfd_target_mach_o_flavour
,
151 i386_mach_o_osabi_sniffer
);
153 gdbarch_register_osabi (bfd_arch_i386
, bfd_mach_i386_i386
,
154 GDB_OSABI_DARWIN
, i386_darwin_init_abi
);