OSDN Git Service

2009-02-04 Tristan Gingold <gingold@adacore.com>
[pf3gnuchains/pf3gnuchains4x.git] / gdb / i386-darwin-tdep.c
1 /* Darwin support for GDB, the GNU debugger.
2    Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2005, 2008, 2009
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"
35 #include "amd64-tdep.h"
36 #include "osabi.h"
37 #include "ui-out.h"
38 #include "symtab.h"
39 #include "frame.h"
40 #include "gdb_assert.h"
41 #include "i386-darwin-tdep.h"
42 #include "solib.h"
43 #include "solib-darwin.h"
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.  */
47 int 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
67 const int i386_darwin_thread_state_num_regs = 
68   ARRAY_SIZE (i386_darwin_thread_state_reg_offset);
69
70 /* Offsets into the struct x86_thread_state64 where we'll find the saved regs.
71    From <mach/i386/thread_status.h> and amd64-tdep.h.  */
72 int amd64_darwin_thread_state_reg_offset[] =
73 {
74   0 * 8,                        /* %rax */
75   1 * 8,                        /* %rbx */
76   2 * 8,                        /* %rcx */
77   3 * 8,                        /* %rdx */
78   5 * 8,                        /* %rsi */
79   4 * 8,                        /* %rdi */
80   6 * 8,                        /* %rbp */
81   7 * 8,                        /* %rsp */
82   8 * 8,                        /* %r8 ... */
83   9 * 8,
84   10 * 8,
85   11 * 8,
86   12 * 8,
87   13 * 8,
88   14 * 8,
89   15 * 8,                       /* ... %r15 */
90   16 * 8,                       /* %rip */
91   17 * 8,                       /* %rflags */
92   18 * 8,                       /* %cs */
93   -1,                           /* %ss */
94   -1,                           /* %ds */
95   -1,                           /* %es */
96   19 * 8,                       /* %fs */
97   20 * 8                        /* %gs */
98 };
99
100 const int amd64_darwin_thread_state_num_regs = 
101   ARRAY_SIZE (amd64_darwin_thread_state_reg_offset);
102
103 static void
104 i386_darwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
105 {
106   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
107
108   /* We support the SSE registers.  */
109   tdep->num_xmm_regs = I386_NUM_XREGS - 1;
110   set_gdbarch_num_regs (gdbarch, I386_SSE_NUM_REGS);
111
112   tdep->struct_return = reg_struct_return;
113
114   tdep->sigcontext_addr = NULL;
115   tdep->sc_reg_offset = i386_darwin_thread_state_reg_offset;
116   tdep->sc_num_regs = 16;
117
118   tdep->jb_pc_offset = 20;
119
120   set_solib_ops (gdbarch, &darwin_so_ops);
121 }
122
123 static void
124 x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
125 {
126   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
127
128   amd64_init_abi (info, gdbarch);
129
130   tdep->struct_return = reg_struct_return;
131
132   /* We don't do signals yet.  */
133   tdep->sigcontext_addr = NULL;
134   tdep->sc_reg_offset = amd64_darwin_thread_state_reg_offset;
135   tdep->sc_num_regs = ARRAY_SIZE (amd64_darwin_thread_state_reg_offset);
136
137   tdep->jb_pc_offset = 148;
138
139   set_solib_ops (gdbarch, &darwin_so_ops);
140 }
141
142 static enum gdb_osabi
143 i386_mach_o_osabi_sniffer (bfd *abfd)
144 {
145   if (!bfd_check_format (abfd, bfd_object))
146     return GDB_OSABI_UNKNOWN;
147   
148   if (bfd_get_arch (abfd) == bfd_arch_i386)
149     return GDB_OSABI_DARWIN;
150
151   return GDB_OSABI_UNKNOWN;
152 }
153
154 void
155 _initialize_i386_darwin_tdep (void)
156 {
157   gdbarch_register_osabi_sniffer (bfd_arch_unknown, bfd_target_mach_o_flavour,
158                                   i386_mach_o_osabi_sniffer);
159
160   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_i386_i386,
161                           GDB_OSABI_DARWIN, i386_darwin_init_abi);
162
163   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
164                           GDB_OSABI_DARWIN, x86_darwin_init_abi_64);
165 }