GDB (xrefs)
/tmp/gdb-7.10/gdb/i386nbsd-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for NetBSD/i386.
2 
3  Copyright (C) 1988-2015 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 "i386-tdep.h"
32 #include "i387-tdep.h"
33 #include "nbsd-tdep.h"
34 #include "solib-svr4.h"
35 
36 /* From <machine/reg.h>. */
37 static int i386nbsd_r_reg_offset[] =
38 {
39  0 * 4, /* %eax */
40  1 * 4, /* %ecx */
41  2 * 4, /* %edx */
42  3 * 4, /* %ebx */
43  4 * 4, /* %esp */
44  5 * 4, /* %ebp */
45  6 * 4, /* %esi */
46  7 * 4, /* %edi */
47  8 * 4, /* %eip */
48  9 * 4, /* %eflags */
49  10 * 4, /* %cs */
50  11 * 4, /* %ss */
51  12 * 4, /* %ds */
52  13 * 4, /* %es */
53  14 * 4, /* %fs */
54  15 * 4 /* %gs */
55 };
56 
57 /* From <machine/signal.h>. */
59 {
60  10 * 4, /* %eax */
61  9 * 4, /* %ecx */
62  8 * 4, /* %edx */
63  7 * 4, /* %ebx */
64  14 * 4, /* %esp */
65  6 * 4, /* %ebp */
66  5 * 4, /* %esi */
67  4 * 4, /* %edi */
68  11 * 4, /* %eip */
69  13 * 4, /* %eflags */
70  12 * 4, /* %cs */
71  15 * 4, /* %ss */
72  3 * 4, /* %ds */
73  2 * 4, /* %es */
74  1 * 4, /* %fs */
75  0 * 4 /* %gs */
76 };
77 
78 /* From <machine/mcontext.h>. */
80 {
81  11 * 4, /* %eax */
82  10 * 4, /* %ecx */
83  9 * 4, /* %edx */
84  8 * 4, /* %ebx */
85  7 * 4, /* %esp */
86  6 * 4, /* %ebp */
87  5 * 4, /* %esi */
88  4 * 4, /* %edi */
89  14 * 4, /* %eip */
90  16 * 4, /* %eflags */
91  15 * 4, /* %cs */
92  18 * 4, /* %ss */
93  3 * 4, /* %ds */
94  2 * 4, /* %es */
95  1 * 4, /* %fs */
96  0 * 4 /* %gs */
97 };
98 
99 static void i386nbsd_sigtramp_cache_init (const struct tramp_frame *,
100  struct frame_info *,
101  struct trad_frame_cache *,
102  CORE_ADDR);
103 
104 static const struct tramp_frame i386nbsd_sigtramp_sc16 =
105 {
107  1,
108  {
109  { 0x8d, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x10, -1 },
110  /* leal 0x10(%esp), %eax */
111  { 0x50, -1 }, /* pushl %eax */
112  { 0x50, -1 }, /* pushl %eax */
113  { 0xb8, -1 }, { 0x27, -1 }, {0x01, -1 }, {0x00, -1 }, {0x00, -1 },
114  /* movl $0x127, %eax # __sigreturn14 */
115  { 0xcd, -1 }, { 0x80, -1},
116  /* int $0x80 */
117  { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
118  /* movl $0x1, %eax # exit */
119  { 0xcd, -1 }, { 0x80, -1},
120  /* int $0x80 */
121  { TRAMP_SENTINEL_INSN, -1 }
122  },
124 };
125 
126 static const struct tramp_frame i386nbsd_sigtramp_sc2 =
127 {
129  1,
130  {
131  { 0x8d, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x0c, -1 },
132  /* leal 0x0c(%esp), %eax */
133  { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
134  /* movl %eax, 0x4(%esp) */
135  { 0xb8, -1 }, { 0x27, -1 }, {0x01, -1 }, {0x00, -1 }, {0x00, -1 },
136  /* movl $0x127, %eax # __sigreturn14 */
137  { 0xcd, -1 }, { 0x80, -1},
138  /* int $0x80 */
139  { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
140  /* movl %eax, 0x4(%esp) */
141  { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
142  /* movl $0x1, %eax */
143  { 0xcd, -1 }, { 0x80, -1},
144  /* int $0x80 */
145  { TRAMP_SENTINEL_INSN, -1 }
146  },
148 };
149 
150 static const struct tramp_frame i386nbsd_sigtramp_si2 =
151 {
153  1,
154  {
155  { 0x8b, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x08, -1 },
156  /* movl 8(%esp),%eax */
157  { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
158  /* movl %eax, 0x4(%esp) */
159  { 0xb8, -1 }, { 0x34, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 },
160  /* movl $0x134, %eax # setcontext */
161  { 0xcd, -1 }, { 0x80, -1 },
162  /* int $0x80 */
163  { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
164  /* movl %eax, 0x4(%esp) */
165  { 0xb8, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 }, { 0x00, -1 },
166  /* movl $0x1, %eax */
167  { 0xcd, -1 }, { 0x80, -1 },
168  /* int $0x80 */
169  { TRAMP_SENTINEL_INSN, -1 }
170  },
172 };
173 
174 static const struct tramp_frame i386nbsd_sigtramp_si31 =
175 {
177  1,
178  {
179  { 0x8d, -1 }, { 0x84, -1 }, { 0x24, -1 },
180  { 0x8c, -1 }, { 0x00, -1 }, { 0x00, -1 }, { 0x00, -1 },
181  /* leal 0x8c(%esp), %eax */
182  { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
183  /* movl %eax, 0x4(%esp) */
184  { 0xb8, -1 }, { 0x34, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 },
185  /* movl $0x134, %eax # setcontext */
186  { 0xcd, -1 }, { 0x80, -1},
187  /* int $0x80 */
188  { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
189  /* movl %eax, 0x4(%esp) */
190  { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
191  /* movl $0x1, %eax */
192  { 0xcd, -1 }, { 0x80, -1},
193  /* int $0x80 */
194  { TRAMP_SENTINEL_INSN, -1 }
195  },
197 };
198 
199 static const struct tramp_frame i386nbsd_sigtramp_si4 =
200 {
202  1,
203  {
204  { 0x8d, -1 }, { 0x84, -1 }, { 0x24, -1 },
205  { 0x8c, -1 }, { 0x00, -1 }, { 0x00, -1 }, { 0x00, -1 },
206  /* leal 0x8c(%esp), %eax */
207  { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
208  /* movl %eax, 0x4(%esp) */
209  { 0xb8, -1 }, { 0x34, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 },
210  /* movl $0x134, %eax # setcontext */
211  { 0xcd, -1 }, { 0x80, -1},
212  /* int $0x80 */
213  { 0xc7, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
214  { 0xff, -1 }, { 0xff, -1 }, { 0xff, -1 }, { 0xff, -1 },
215  /* movl $0xffffffff,0x4(%esp) */
216  { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
217  /* movl $0x1, %eax */
218  { 0xcd, -1 }, { 0x80, -1},
219  /* int $0x80 */
220  { TRAMP_SENTINEL_INSN, -1 }
221  },
223 };
224 
225 static void
227  struct frame_info *this_frame,
228  struct trad_frame_cache *this_cache,
229  CORE_ADDR func)
230 {
231  struct gdbarch *gdbarch = get_frame_arch (this_frame);
232  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
233  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
235  CORE_ADDR base;
236  int *reg_offset;
237  int num_regs;
238  int i;
239 
240  if (self == &i386nbsd_sigtramp_sc16 || self == &i386nbsd_sigtramp_sc2)
241  {
242  reg_offset = i386nbsd_sc_reg_offset;
243  num_regs = ARRAY_SIZE (i386nbsd_sc_reg_offset);
244 
245  /* Read in the sigcontext address. */
246  base = read_memory_unsigned_integer (sp + 8, 4, byte_order);
247  }
248  else
249  {
250  reg_offset = i386nbsd_mc_reg_offset;
251  num_regs = ARRAY_SIZE (i386nbsd_mc_reg_offset);
252 
253  /* Read in the ucontext address. */
254  base = read_memory_unsigned_integer (sp + 8, 4, byte_order);
255  /* offsetof(ucontext_t, uc_mcontext) == 36 */
256  base += 36;
257  }
258 
259  for (i = 0; i < num_regs; i++)
260  if (reg_offset[i] != -1)
261  trad_frame_set_reg_addr (this_cache, i, base + reg_offset[i]);
262 
263  /* Construct the frame ID using the function start. */
264  trad_frame_set_id (this_cache, frame_id_build (sp, func));
265 }
266 
267 
268 static void
270 {
271  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
272 
273  /* Obviously NetBSD is BSD-based. */
274  i386bsd_init_abi (info, gdbarch);
275 
276  /* NetBSD has a different `struct reg'. */
278  tdep->gregset_num_regs = ARRAY_SIZE (i386nbsd_r_reg_offset);
279  tdep->sizeof_gregset = 16 * 4;
280 
281  /* NetBSD uses -freg-struct-return by default. */
283 
284  /* NetBSD uses tramp_frame sniffers for signal trampolines. */
285  tdep->sigcontext_addr= 0;
286  tdep->sigtramp_start = 0;
287  tdep->sigtramp_end = 0;
288  tdep->sigtramp_p = 0;
289  tdep->sc_reg_offset = 0;
290  tdep->sc_num_regs = 0;
291 
292  tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_sc16);
293  tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_sc2);
294  tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si2);
295  tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si31);
296  tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si4);
297 }
298 
299 /* NetBSD ELF. */
300 
301 static void
303 {
304  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
305 
306  /* It's still NetBSD. */
307  i386nbsd_init_abi (info, gdbarch);
308 
309  /* But ELF-based. */
310  i386_elf_init_abi (info, gdbarch);
311 
312  /* NetBSD ELF uses SVR4-style shared libraries. */
315 
316  /* NetBSD ELF uses -fpcc-struct-return by default. */
318 }
319 
320 /* Provide a prototype to silence -Wmissing-prototypes. */
322 
323 void
325 {
326  gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_ELF,
328 }
int i386nbsd_mc_reg_offset[]
Definition: i386nbsd-tdep.c:79
void trad_frame_set_reg_addr(struct trad_frame_cache *this_trad_cache, int regnum, CORE_ADDR addr)
Definition: trad-frame.c:119
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition: frame.c:554
void i386bsd_init_abi(struct gdbarch_info, struct gdbarch *)
Definition: i386bsd-tdep.c:75
bfd_vma CORE_ADDR
Definition: common-types.h:41
#define TRAMP_SENTINEL_INSN
Definition: tramp-frame.h:44
int sc_num_regs
Definition: i386-tdep.h:216
void(* func)(char *)
CORE_ADDR sigtramp_start
Definition: i386-tdep.h:205
void trad_frame_set_id(struct trad_frame_cache *this_trad_cache, struct frame_id this_id)
Definition: trad-frame.c:164
CORE_ADDR sigtramp_end
Definition: i386-tdep.h:206
static int reg_offset[]
Definition: i386gnu-nat.c:42
CORE_ADDR(* sigcontext_addr)(struct frame_info *)
Definition: alpha-tdep.h:82
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3149
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1402
enum struct_return struct_return
Definition: arm-tdep.h:197
void initialize_file_ftype(void)
Definition: defs.h:281
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1420
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
Definition: solib-svr4.c:3108
static void i386nbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
ULONGEST get_frame_register_unsigned(struct frame_info *frame, int regnum)
Definition: frame.c:1194
int * gregset_reg_offset
Definition: i386-tdep.h:59
static void i386nbsdelf_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
int i386nbsd_sc_reg_offset[]
Definition: i386nbsd-tdep.c:58
int(* sigtramp_p)(struct frame_info *)
Definition: i386-tdep.h:209
static int i386nbsd_r_reg_offset[]
Definition: i386nbsd-tdep.c:37
void i386_elf_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: i386-tdep.c:4332
void tramp_frame_prepend_unwinder(struct gdbarch *gdbarch, const struct tramp_frame *tramp_frame)
Definition: tramp-frame.c:145
size_t sizeof_gregset
Definition: i386-tdep.h:61
struct m32c_reg * sp
Definition: m32c-tdep.c:114
initialize_file_ftype _initialize_i386nbsd_tdep
int * sc_reg_offset
Definition: i386-tdep.h:215
ULONGEST read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition: corefile.c:321
int gregset_num_regs
Definition: i386-tdep.h:60
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition: osabi.c:148
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2535
static void i386nbsd_sigtramp_cache_init(const struct tramp_frame *, struct frame_info *, struct trad_frame_cache *, CORE_ADDR)