]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/i386nbsd-tdep.c
Change "set debug symtab-create" to take a verbosity level.
[thirdparty/binutils-gdb.git] / gdb / i386nbsd-tdep.c
1 /* Target-dependent code for NetBSD/i386.
2
3 Copyright (C) 1988-2013 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "arch-utils.h"
22 #include "frame.h"
23 #include "gdbcore.h"
24 #include "regcache.h"
25 #include "regset.h"
26 #include "osabi.h"
27 #include "symtab.h"
28 #include "trad-frame.h"
29 #include "tramp-frame.h"
30
31 #include "gdb_assert.h"
32 #include "gdb_string.h"
33
34 #include "i386-tdep.h"
35 #include "i387-tdep.h"
36 #include "nbsd-tdep.h"
37 #include "solib-svr4.h"
38
39 /* From <machine/reg.h>. */
40 static int i386nbsd_r_reg_offset[] =
41 {
42 0 * 4, /* %eax */
43 1 * 4, /* %ecx */
44 2 * 4, /* %edx */
45 3 * 4, /* %ebx */
46 4 * 4, /* %esp */
47 5 * 4, /* %ebp */
48 6 * 4, /* %esi */
49 7 * 4, /* %edi */
50 8 * 4, /* %eip */
51 9 * 4, /* %eflags */
52 10 * 4, /* %cs */
53 11 * 4, /* %ss */
54 12 * 4, /* %ds */
55 13 * 4, /* %es */
56 14 * 4, /* %fs */
57 15 * 4 /* %gs */
58 };
59
60 /* From <machine/signal.h>. */
61 int i386nbsd_sc_reg_offset[] =
62 {
63 10 * 4, /* %eax */
64 9 * 4, /* %ecx */
65 8 * 4, /* %edx */
66 7 * 4, /* %ebx */
67 14 * 4, /* %esp */
68 6 * 4, /* %ebp */
69 5 * 4, /* %esi */
70 4 * 4, /* %edi */
71 11 * 4, /* %eip */
72 13 * 4, /* %eflags */
73 12 * 4, /* %cs */
74 15 * 4, /* %ss */
75 3 * 4, /* %ds */
76 2 * 4, /* %es */
77 1 * 4, /* %fs */
78 0 * 4 /* %gs */
79 };
80
81 /* From <machine/mcontext.h>. */
82 int i386nbsd_mc_reg_offset[] =
83 {
84 11 * 4, /* %eax */
85 10 * 4, /* %ecx */
86 9 * 4, /* %edx */
87 8 * 4, /* %ebx */
88 7 * 4, /* %esp */
89 6 * 4, /* %ebp */
90 5 * 4, /* %esi */
91 4 * 4, /* %edi */
92 14 * 4, /* %eip */
93 16 * 4, /* %eflags */
94 15 * 4, /* %cs */
95 18 * 4, /* %ss */
96 3 * 4, /* %ds */
97 2 * 4, /* %es */
98 1 * 4, /* %fs */
99 0 * 4 /* %gs */
100 };
101
102 static void i386nbsd_sigtramp_cache_init (const struct tramp_frame *,
103 struct frame_info *,
104 struct trad_frame_cache *,
105 CORE_ADDR);
106
107 static const struct tramp_frame i386nbsd_sigtramp_sc16 =
108 {
109 SIGTRAMP_FRAME,
110 1,
111 {
112 { 0x8d, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x10, -1 },
113 /* leal 0x10(%esp), %eax */
114 { 0x50, -1 }, /* pushl %eax */
115 { 0x50, -1 }, /* pushl %eax */
116 { 0xb8, -1 }, { 0x27, -1 }, {0x01, -1 }, {0x00, -1 }, {0x00, -1 },
117 /* movl $0x127, %eax # __sigreturn14 */
118 { 0xcd, -1 }, { 0x80, -1},
119 /* int $0x80 */
120 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
121 /* movl $0x1, %eax # exit */
122 { 0xcd, -1 }, { 0x80, -1},
123 /* int $0x80 */
124 { TRAMP_SENTINEL_INSN, -1 }
125 },
126 i386nbsd_sigtramp_cache_init
127 };
128
129 static const struct tramp_frame i386nbsd_sigtramp_sc2 =
130 {
131 SIGTRAMP_FRAME,
132 1,
133 {
134 { 0x8d, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x0c, -1 },
135 /* leal 0x0c(%esp), %eax */
136 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
137 /* movl %eax, 0x4(%esp) */
138 { 0xb8, -1 }, { 0x27, -1 }, {0x01, -1 }, {0x00, -1 }, {0x00, -1 },
139 /* movl $0x127, %eax # __sigreturn14 */
140 { 0xcd, -1 }, { 0x80, -1},
141 /* int $0x80 */
142 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
143 /* movl %eax, 0x4(%esp) */
144 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
145 /* movl $0x1, %eax */
146 { 0xcd, -1 }, { 0x80, -1},
147 /* int $0x80 */
148 { TRAMP_SENTINEL_INSN, -1 }
149 },
150 i386nbsd_sigtramp_cache_init
151 };
152
153 static const struct tramp_frame i386nbsd_sigtramp_si2 =
154 {
155 SIGTRAMP_FRAME,
156 1,
157 {
158 { 0x8b, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x08, -1 },
159 /* movl 8(%esp),%eax */
160 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
161 /* movl %eax, 0x4(%esp) */
162 { 0xb8, -1 }, { 0x34, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 },
163 /* movl $0x134, %eax # setcontext */
164 { 0xcd, -1 }, { 0x80, -1 },
165 /* int $0x80 */
166 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
167 /* movl %eax, 0x4(%esp) */
168 { 0xb8, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 }, { 0x00, -1 },
169 /* movl $0x1, %eax */
170 { 0xcd, -1 }, { 0x80, -1 },
171 /* int $0x80 */
172 { TRAMP_SENTINEL_INSN, -1 }
173 },
174 i386nbsd_sigtramp_cache_init
175 };
176
177 static const struct tramp_frame i386nbsd_sigtramp_si31 =
178 {
179 SIGTRAMP_FRAME,
180 1,
181 {
182 { 0x8d, -1 }, { 0x84, -1 }, { 0x24, -1 },
183 { 0x8c, -1 }, { 0x00, -1 }, { 0x00, -1 }, { 0x00, -1 },
184 /* leal 0x8c(%esp), %eax */
185 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
186 /* movl %eax, 0x4(%esp) */
187 { 0xb8, -1 }, { 0x34, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 },
188 /* movl $0x134, %eax # setcontext */
189 { 0xcd, -1 }, { 0x80, -1},
190 /* int $0x80 */
191 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
192 /* movl %eax, 0x4(%esp) */
193 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
194 /* movl $0x1, %eax */
195 { 0xcd, -1 }, { 0x80, -1},
196 /* int $0x80 */
197 { TRAMP_SENTINEL_INSN, -1 }
198 },
199 i386nbsd_sigtramp_cache_init
200 };
201
202 static const struct tramp_frame i386nbsd_sigtramp_si4 =
203 {
204 SIGTRAMP_FRAME,
205 1,
206 {
207 { 0x8d, -1 }, { 0x84, -1 }, { 0x24, -1 },
208 { 0x8c, -1 }, { 0x00, -1 }, { 0x00, -1 }, { 0x00, -1 },
209 /* leal 0x8c(%esp), %eax */
210 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
211 /* movl %eax, 0x4(%esp) */
212 { 0xb8, -1 }, { 0x34, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 },
213 /* movl $0x134, %eax # setcontext */
214 { 0xcd, -1 }, { 0x80, -1},
215 /* int $0x80 */
216 { 0xc7, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
217 { 0xff, -1 }, { 0xff, -1 }, { 0xff, -1 }, { 0xff, -1 },
218 /* movl $0xffffffff,0x4(%esp) */
219 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
220 /* movl $0x1, %eax */
221 { 0xcd, -1 }, { 0x80, -1},
222 /* int $0x80 */
223 { TRAMP_SENTINEL_INSN, -1 }
224 },
225 i386nbsd_sigtramp_cache_init
226 };
227
228 static void
229 i386nbsd_sigtramp_cache_init (const struct tramp_frame *self,
230 struct frame_info *this_frame,
231 struct trad_frame_cache *this_cache,
232 CORE_ADDR func)
233 {
234 struct gdbarch *gdbarch = get_frame_arch (this_frame);
235 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
236 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
237 CORE_ADDR sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM);
238 CORE_ADDR base;
239 int *reg_offset;
240 int num_regs;
241 int i;
242
243 if (self == &i386nbsd_sigtramp_sc16 || self == &i386nbsd_sigtramp_sc2)
244 {
245 reg_offset = i386nbsd_sc_reg_offset;
246 num_regs = ARRAY_SIZE (i386nbsd_sc_reg_offset);
247
248 /* Read in the sigcontext address. */
249 base = read_memory_unsigned_integer (sp + 8, 4, byte_order);
250 }
251 else
252 {
253 reg_offset = i386nbsd_mc_reg_offset;
254 num_regs = ARRAY_SIZE (i386nbsd_mc_reg_offset);
255
256 /* Read in the ucontext address. */
257 base = read_memory_unsigned_integer (sp + 8, 4, byte_order);
258 /* offsetof(ucontext_t, uc_mcontext) == 36 */
259 base += 36;
260 }
261
262 for (i = 0; i < num_regs; i++)
263 if (reg_offset[i] != -1)
264 trad_frame_set_reg_addr (this_cache, i, base + reg_offset[i]);
265
266 /* Construct the frame ID using the function start. */
267 trad_frame_set_id (this_cache, frame_id_build (sp, func));
268 }
269 \f
270
271 static void
272 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
273 {
274 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
275
276 /* Obviously NetBSD is BSD-based. */
277 i386bsd_init_abi (info, gdbarch);
278
279 /* NetBSD has a different `struct reg'. */
280 tdep->gregset_reg_offset = i386nbsd_r_reg_offset;
281 tdep->gregset_num_regs = ARRAY_SIZE (i386nbsd_r_reg_offset);
282 tdep->sizeof_gregset = 16 * 4;
283
284 /* NetBSD uses -freg-struct-return by default. */
285 tdep->struct_return = reg_struct_return;
286
287 /* NetBSD uses tramp_frame sniffers for signal trampolines. */
288 tdep->sigcontext_addr= 0;
289 tdep->sigtramp_start = 0;
290 tdep->sigtramp_end = 0;
291 tdep->sigtramp_p = 0;
292 tdep->sc_reg_offset = 0;
293 tdep->sc_num_regs = 0;
294
295 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_sc16);
296 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_sc2);
297 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si2);
298 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si31);
299 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si4);
300 }
301
302 /* NetBSD ELF. */
303
304 static void
305 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
306 {
307 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
308
309 /* It's still NetBSD. */
310 i386nbsd_init_abi (info, gdbarch);
311
312 /* But ELF-based. */
313 i386_elf_init_abi (info, gdbarch);
314
315 /* NetBSD ELF uses SVR4-style shared libraries. */
316 set_solib_svr4_fetch_link_map_offsets
317 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
318
319 /* NetBSD ELF uses -fpcc-struct-return by default. */
320 tdep->struct_return = pcc_struct_return;
321 }
322
323 /* Provide a prototype to silence -Wmissing-prototypes. */
324 extern initialize_file_ftype _initialize_i386nbsd_tdep;
325
326 void
327 _initialize_i386nbsd_tdep (void)
328 {
329 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_ELF,
330 i386nbsdelf_init_abi);
331 }