Enable XML target descriptions for x86.
[deliverable/binutils-gdb.git] / gdb / i386-linux-tdep.c
CommitLineData
871fbe6a 1/* Target-dependent code for GNU/Linux i386.
ca557f44 2
4c38e0a4 3 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
4252dc94 4 Free Software Foundation, Inc.
e7ee86a9
JB
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
e7ee86a9
JB
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
e7ee86a9
JB
20
21#include "defs.h"
22#include "gdbcore.h"
23#include "frame.h"
24#include "value.h"
4e052eda 25#include "regcache.h"
6441c4a0 26#include "inferior.h"
0670c0aa 27#include "osabi.h"
38c968cf 28#include "reggroups.h"
5cb2fe25 29#include "dwarf2-frame.h"
0670c0aa 30#include "gdb_string.h"
4be87837 31
8201327c
MK
32#include "i386-tdep.h"
33#include "i386-linux-tdep.h"
4aa995e1 34#include "linux-tdep.h"
0670c0aa 35#include "glibc-tdep.h"
871fbe6a 36#include "solib-svr4.h"
982e9687 37#include "symtab.h"
237fc4c9 38#include "arch-utils.h"
17ea7499 39#include "regset.h"
a96d9b2e
SDJ
40#include "xml-syscall.h"
41
42/* The syscall's XML filename for i386. */
43#define XML_SYSCALL_FILENAME_I386 "syscalls/i386-linux.xml"
17ea7499 44
77fcef51
HZ
45#include "record.h"
46#include "linux-record.h"
47#include <stdint.h>
48
90884b2b
L
49#include "features/i386/i386-linux.c"
50
17ea7499
CES
51/* Supported register note sections. */
52static struct core_regset_section i386_linux_regset_sections[] =
53{
1b1818e4
UW
54 { ".reg", 144, "general-purpose" },
55 { ".reg2", 108, "floating-point" },
56 { ".reg-xfp", 512, "extended floating-point" },
17ea7499
CES
57 { NULL, 0 }
58};
8201327c 59
38c968cf
AC
60/* Return non-zero, when the register is in the corresponding register
61 group. Put the LINUX_ORIG_EAX register in the system group. */
62static int
63i386_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
64 struct reggroup *group)
65{
66 if (regnum == I386_LINUX_ORIG_EAX_REGNUM)
67 return (group == system_reggroup
68 || group == save_reggroup
69 || group == restore_reggroup);
70 return i386_register_reggroup_p (gdbarch, regnum, group);
71}
72
e7ee86a9
JB
73\f
74/* Recognizing signal handler frames. */
75
ca557f44 76/* GNU/Linux has two flavors of signals. Normal signal handlers, and
e7ee86a9
JB
77 "realtime" (RT) signals. The RT signals can provide additional
78 information to the signal handler if the SA_SIGINFO flag is set
79 when establishing a signal handler using `sigaction'. It is not
ca557f44
AC
80 unlikely that future versions of GNU/Linux will support SA_SIGINFO
81 for normal signals too. */
e7ee86a9
JB
82
83/* When the i386 Linux kernel calls a signal handler and the
84 SA_RESTORER flag isn't set, the return address points to a bit of
85 code on the stack. This function returns whether the PC appears to
86 be within this bit of code.
87
88 The instruction sequence for normal signals is
89 pop %eax
acd5c798 90 mov $0x77, %eax
e7ee86a9
JB
91 int $0x80
92 or 0x58 0xb8 0x77 0x00 0x00 0x00 0xcd 0x80.
93
94 Checking for the code sequence should be somewhat reliable, because
95 the effect is to call the system call sigreturn. This is unlikely
911bc6ee 96 to occur anywhere other than in a signal trampoline.
e7ee86a9
JB
97
98 It kind of sucks that we have to read memory from the process in
99 order to identify a signal trampoline, but there doesn't seem to be
911bc6ee
MK
100 any other way. Therefore we only do the memory reads if no
101 function name could be identified, which should be the case since
102 the code is on the stack.
e7ee86a9
JB
103
104 Detection of signal trampolines for handlers that set the
105 SA_RESTORER flag is in general not possible. Unfortunately this is
106 what the GNU C Library has been doing for quite some time now.
107 However, as of version 2.1.2, the GNU C Library uses signal
108 trampolines (named __restore and __restore_rt) that are identical
109 to the ones used by the kernel. Therefore, these trampolines are
110 supported too. */
111
acd5c798
MK
112#define LINUX_SIGTRAMP_INSN0 0x58 /* pop %eax */
113#define LINUX_SIGTRAMP_OFFSET0 0
114#define LINUX_SIGTRAMP_INSN1 0xb8 /* mov $NNNN, %eax */
115#define LINUX_SIGTRAMP_OFFSET1 1
116#define LINUX_SIGTRAMP_INSN2 0xcd /* int */
117#define LINUX_SIGTRAMP_OFFSET2 6
e7ee86a9 118
4252dc94 119static const gdb_byte linux_sigtramp_code[] =
e7ee86a9
JB
120{
121 LINUX_SIGTRAMP_INSN0, /* pop %eax */
acd5c798 122 LINUX_SIGTRAMP_INSN1, 0x77, 0x00, 0x00, 0x00, /* mov $0x77, %eax */
e7ee86a9
JB
123 LINUX_SIGTRAMP_INSN2, 0x80 /* int $0x80 */
124};
125
126#define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
127
10458914
DJ
128/* If THIS_FRAME is a sigtramp routine, return the address of the
129 start of the routine. Otherwise, return 0. */
e7ee86a9
JB
130
131static CORE_ADDR
10458914 132i386_linux_sigtramp_start (struct frame_info *this_frame)
e7ee86a9 133{
10458914 134 CORE_ADDR pc = get_frame_pc (this_frame);
4252dc94 135 gdb_byte buf[LINUX_SIGTRAMP_LEN];
e7ee86a9
JB
136
137 /* We only recognize a signal trampoline if PC is at the start of
138 one of the three instructions. We optimize for finding the PC at
139 the start, as will be the case when the trampoline is not the
140 first frame on the stack. We assume that in the case where the
141 PC is not at the start of the instruction sequence, there will be
142 a few trailing readable bytes on the stack. */
143
10458914 144 if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
e7ee86a9
JB
145 return 0;
146
147 if (buf[0] != LINUX_SIGTRAMP_INSN0)
148 {
149 int adjust;
150
151 switch (buf[0])
152 {
153 case LINUX_SIGTRAMP_INSN1:
154 adjust = LINUX_SIGTRAMP_OFFSET1;
155 break;
156 case LINUX_SIGTRAMP_INSN2:
157 adjust = LINUX_SIGTRAMP_OFFSET2;
158 break;
159 default:
160 return 0;
161 }
162
163 pc -= adjust;
164
10458914 165 if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
e7ee86a9
JB
166 return 0;
167 }
168
169 if (memcmp (buf, linux_sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
170 return 0;
171
172 return pc;
173}
174
175/* This function does the same for RT signals. Here the instruction
176 sequence is
acd5c798 177 mov $0xad, %eax
e7ee86a9
JB
178 int $0x80
179 or 0xb8 0xad 0x00 0x00 0x00 0xcd 0x80.
180
181 The effect is to call the system call rt_sigreturn. */
182
acd5c798
MK
183#define LINUX_RT_SIGTRAMP_INSN0 0xb8 /* mov $NNNN, %eax */
184#define LINUX_RT_SIGTRAMP_OFFSET0 0
185#define LINUX_RT_SIGTRAMP_INSN1 0xcd /* int */
186#define LINUX_RT_SIGTRAMP_OFFSET1 5
e7ee86a9 187
4252dc94 188static const gdb_byte linux_rt_sigtramp_code[] =
e7ee86a9 189{
acd5c798 190 LINUX_RT_SIGTRAMP_INSN0, 0xad, 0x00, 0x00, 0x00, /* mov $0xad, %eax */
e7ee86a9
JB
191 LINUX_RT_SIGTRAMP_INSN1, 0x80 /* int $0x80 */
192};
193
194#define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code)
195
10458914
DJ
196/* If THIS_FRAME is an RT sigtramp routine, return the address of the
197 start of the routine. Otherwise, return 0. */
e7ee86a9
JB
198
199static CORE_ADDR
10458914 200i386_linux_rt_sigtramp_start (struct frame_info *this_frame)
e7ee86a9 201{
10458914 202 CORE_ADDR pc = get_frame_pc (this_frame);
4252dc94 203 gdb_byte buf[LINUX_RT_SIGTRAMP_LEN];
e7ee86a9
JB
204
205 /* We only recognize a signal trampoline if PC is at the start of
206 one of the two instructions. We optimize for finding the PC at
207 the start, as will be the case when the trampoline is not the
208 first frame on the stack. We assume that in the case where the
209 PC is not at the start of the instruction sequence, there will be
210 a few trailing readable bytes on the stack. */
211
10458914 212 if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_RT_SIGTRAMP_LEN))
e7ee86a9
JB
213 return 0;
214
215 if (buf[0] != LINUX_RT_SIGTRAMP_INSN0)
216 {
217 if (buf[0] != LINUX_RT_SIGTRAMP_INSN1)
218 return 0;
219
220 pc -= LINUX_RT_SIGTRAMP_OFFSET1;
221
10458914 222 if (!safe_frame_unwind_memory (this_frame, pc, buf,
8e6bed05 223 LINUX_RT_SIGTRAMP_LEN))
e7ee86a9
JB
224 return 0;
225 }
226
227 if (memcmp (buf, linux_rt_sigtramp_code, LINUX_RT_SIGTRAMP_LEN) != 0)
228 return 0;
229
230 return pc;
231}
232
10458914
DJ
233/* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
234 routine. */
e7ee86a9 235
8201327c 236static int
10458914 237i386_linux_sigtramp_p (struct frame_info *this_frame)
e7ee86a9 238{
10458914 239 CORE_ADDR pc = get_frame_pc (this_frame);
911bc6ee
MK
240 char *name;
241
242 find_pc_partial_function (pc, &name, NULL, NULL);
243
ef17e74b
DJ
244 /* If we have NAME, we can optimize the search. The trampolines are
245 named __restore and __restore_rt. However, they aren't dynamically
246 exported from the shared C library, so the trampoline may appear to
247 be part of the preceding function. This should always be sigaction,
248 __sigaction, or __libc_sigaction (all aliases to the same function). */
249 if (name == NULL || strstr (name, "sigaction") != NULL)
10458914
DJ
250 return (i386_linux_sigtramp_start (this_frame) != 0
251 || i386_linux_rt_sigtramp_start (this_frame) != 0);
ef17e74b
DJ
252
253 return (strcmp ("__restore", name) == 0
254 || strcmp ("__restore_rt", name) == 0);
e7ee86a9
JB
255}
256
4a4e5149
DJ
257/* Return one if the PC of THIS_FRAME is in a signal trampoline which
258 may have DWARF-2 CFI. */
12b8a2cb
DJ
259
260static int
261i386_linux_dwarf_signal_frame_p (struct gdbarch *gdbarch,
4a4e5149 262 struct frame_info *this_frame)
12b8a2cb 263{
4a4e5149 264 CORE_ADDR pc = get_frame_pc (this_frame);
12b8a2cb
DJ
265 char *name;
266
267 find_pc_partial_function (pc, &name, NULL, NULL);
268
269 /* If a vsyscall DSO is in use, the signal trampolines may have these
270 names. */
271 if (name && (strcmp (name, "__kernel_sigreturn") == 0
272 || strcmp (name, "__kernel_rt_sigreturn") == 0))
273 return 1;
274
275 return 0;
276}
277
acd5c798
MK
278/* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
279#define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 20
280
10458914
DJ
281/* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
282 address of the associated sigcontext structure. */
e7ee86a9 283
b7d15bf7 284static CORE_ADDR
10458914 285i386_linux_sigcontext_addr (struct frame_info *this_frame)
e7ee86a9 286{
e17a4113
UW
287 struct gdbarch *gdbarch = get_frame_arch (this_frame);
288 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
e7ee86a9 289 CORE_ADDR pc;
acd5c798 290 CORE_ADDR sp;
4252dc94 291 gdb_byte buf[4];
acd5c798 292
10458914 293 get_frame_register (this_frame, I386_ESP_REGNUM, buf);
e17a4113 294 sp = extract_unsigned_integer (buf, 4, byte_order);
e7ee86a9 295
10458914 296 pc = i386_linux_sigtramp_start (this_frame);
e7ee86a9
JB
297 if (pc)
298 {
acd5c798
MK
299 /* The sigcontext structure lives on the stack, right after
300 the signum argument. We determine the address of the
301 sigcontext structure by looking at the frame's stack
302 pointer. Keep in mind that the first instruction of the
303 sigtramp code is "pop %eax". If the PC is after this
304 instruction, adjust the returned value accordingly. */
10458914 305 if (pc == get_frame_pc (this_frame))
e7ee86a9
JB
306 return sp + 4;
307 return sp;
308 }
309
10458914 310 pc = i386_linux_rt_sigtramp_start (this_frame);
e7ee86a9
JB
311 if (pc)
312 {
acd5c798
MK
313 CORE_ADDR ucontext_addr;
314
315 /* The sigcontext structure is part of the user context. A
316 pointer to the user context is passed as the third argument
317 to the signal handler. */
318 read_memory (sp + 8, buf, 4);
e17a4113 319 ucontext_addr = extract_unsigned_integer (buf, 4, byte_order);
acd5c798 320 return ucontext_addr + I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET;
e7ee86a9
JB
321 }
322
8a3fe4f8 323 error (_("Couldn't recognize signal trampoline."));
e7ee86a9
JB
324 return 0;
325}
326
6441c4a0
MK
327/* Set the program counter for process PTID to PC. */
328
8201327c 329static void
61a1198a 330i386_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
6441c4a0 331{
61a1198a 332 regcache_cooked_write_unsigned (regcache, I386_EIP_REGNUM, pc);
6441c4a0
MK
333
334 /* We must be careful with modifying the program counter. If we
335 just interrupted a system call, the kernel might try to restart
336 it when we resume the inferior. On restarting the system call,
337 the kernel will try backing up the program counter even though it
338 no longer points at the system call. This typically results in a
339 SIGSEGV or SIGILL. We can prevent this by writing `-1' in the
340 "orig_eax" pseudo-register.
341
342 Note that "orig_eax" is saved when setting up a dummy call frame.
343 This means that it is properly restored when that frame is
344 popped, and that the interrupted system call will be restarted
345 when we resume the inferior on return from a function call from
346 within GDB. In all other cases the system call will not be
347 restarted. */
61a1198a 348 regcache_cooked_write_unsigned (regcache, I386_LINUX_ORIG_EAX_REGNUM, -1);
6441c4a0 349}
77fcef51 350
8a2e0e28
HZ
351/* Record all registers but IP register for process-record. */
352
353static int
354i386_all_but_ip_registers_record (struct regcache *regcache)
355{
356 if (record_arch_list_add_reg (regcache, I386_EAX_REGNUM))
357 return -1;
358 if (record_arch_list_add_reg (regcache, I386_ECX_REGNUM))
359 return -1;
360 if (record_arch_list_add_reg (regcache, I386_EDX_REGNUM))
361 return -1;
362 if (record_arch_list_add_reg (regcache, I386_EBX_REGNUM))
363 return -1;
364 if (record_arch_list_add_reg (regcache, I386_ESP_REGNUM))
365 return -1;
366 if (record_arch_list_add_reg (regcache, I386_EBP_REGNUM))
367 return -1;
368 if (record_arch_list_add_reg (regcache, I386_ESI_REGNUM))
369 return -1;
370 if (record_arch_list_add_reg (regcache, I386_EDI_REGNUM))
371 return -1;
372 if (record_arch_list_add_reg (regcache, I386_EFLAGS_REGNUM))
373 return -1;
374
375 return 0;
376}
13b6d1d4
MS
377
378/* i386_canonicalize_syscall maps from the native i386 Linux set
379 of syscall ids into a canonical set of syscall ids used by
380 process record (a mostly trivial mapping, since the canonical
381 set was originally taken from the i386 set). */
382
383static enum gdb_syscall
384i386_canonicalize_syscall (int syscall)
385{
386 enum { i386_syscall_max = 499 };
387
388 if (syscall <= i386_syscall_max)
389 return syscall;
390 else
391 return -1;
392}
393
77fcef51
HZ
394/* Parse the arguments of current system call instruction and record
395 the values of the registers and memory that will be changed into
396 "record_arch_list". This instruction is "int 0x80" (Linux
397 Kernel2.4) or "sysenter" (Linux Kernel 2.6).
398
399 Return -1 if something wrong. */
400
8a2e0e28
HZ
401static struct linux_record_tdep i386_linux_record_tdep;
402
77fcef51
HZ
403static int
404i386_linux_intx80_sysenter_record (struct regcache *regcache)
405{
406 int ret;
13b6d1d4
MS
407 LONGEST syscall_native;
408 enum gdb_syscall syscall_gdb;
409
410 regcache_raw_read_signed (regcache, I386_EAX_REGNUM, &syscall_native);
77fcef51 411
13b6d1d4 412 syscall_gdb = i386_canonicalize_syscall (syscall_native);
2c543fc4 413
13b6d1d4 414 if (syscall_gdb < 0)
2c543fc4
HZ
415 {
416 printf_unfiltered (_("Process record and replay target doesn't "
13b6d1d4
MS
417 "support syscall number %s\n"),
418 plongest (syscall_native));
2c543fc4
HZ
419 return -1;
420 }
77fcef51 421
8a2e0e28
HZ
422 if (syscall_gdb == gdb_sys_sigreturn
423 || syscall_gdb == gdb_sys_rt_sigreturn)
424 {
425 if (i386_all_but_ip_registers_record (regcache))
426 return -1;
427 return 0;
428 }
429
13b6d1d4 430 ret = record_linux_system_call (syscall_gdb, regcache,
77fcef51
HZ
431 &i386_linux_record_tdep);
432 if (ret)
433 return ret;
434
435 /* Record the return value of the system call. */
436 if (record_arch_list_add_reg (regcache, I386_EAX_REGNUM))
437 return -1;
438
439 return 0;
440}
8a2e0e28
HZ
441
442#define I386_LINUX_xstate 270
443#define I386_LINUX_frame_size 732
444
445int
446i386_linux_record_signal (struct gdbarch *gdbarch,
447 struct regcache *regcache,
448 enum target_signal signal)
449{
450 ULONGEST esp;
451
452 if (i386_all_but_ip_registers_record (regcache))
453 return -1;
454
455 if (record_arch_list_add_reg (regcache, I386_EIP_REGNUM))
456 return -1;
457
458 /* Record the change in the stack. */
459 regcache_raw_read_unsigned (regcache, I386_ESP_REGNUM, &esp);
460 /* This is for xstate.
461 sp -= sizeof (struct _fpstate); */
462 esp -= I386_LINUX_xstate;
463 /* This is for frame_size.
464 sp -= sizeof (struct rt_sigframe); */
465 esp -= I386_LINUX_frame_size;
466 if (record_arch_list_add_mem (esp,
467 I386_LINUX_xstate + I386_LINUX_frame_size))
468 return -1;
469
470 if (record_arch_list_add_end ())
471 return -1;
472
473 return 0;
474}
6441c4a0 475\f
8201327c 476
a96d9b2e
SDJ
477static LONGEST
478i386_linux_get_syscall_number (struct gdbarch *gdbarch,
479 ptid_t ptid)
480{
481 struct regcache *regcache = get_thread_regcache (ptid);
482 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
483 /* The content of a register. */
484 gdb_byte buf[4];
485 /* The result. */
486 LONGEST ret;
487
488 /* Getting the system call number from the register.
489 When dealing with x86 architecture, this information
490 is stored at %eax register. */
491 regcache_cooked_read (regcache, I386_LINUX_ORIG_EAX_REGNUM, buf);
492
493 ret = extract_signed_integer (buf, 4, byte_order);
494
495 return ret;
496}
497
e9f1aad5
MK
498/* The register sets used in GNU/Linux ELF core-dumps are identical to
499 the register sets in `struct user' that are used for a.out
500 core-dumps. These are also used by ptrace(2). The corresponding
501 types are `elf_gregset_t' for the general-purpose registers (with
502 `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
503 for the floating-point registers.
504
505 Those types used to be available under the names `gregset_t' and
506 `fpregset_t' too, and GDB used those names in the past. But those
507 names are now used for the register sets used in the `mcontext_t'
508 type, which have a different size and layout. */
509
510/* Mapping between the general-purpose registers in `struct user'
511 format and GDB's register cache layout. */
512
513/* From <sys/reg.h>. */
514static int i386_linux_gregset_reg_offset[] =
515{
516 6 * 4, /* %eax */
517 1 * 4, /* %ecx */
518 2 * 4, /* %edx */
519 0 * 4, /* %ebx */
520 15 * 4, /* %esp */
521 5 * 4, /* %ebp */
522 3 * 4, /* %esi */
523 4 * 4, /* %edi */
524 12 * 4, /* %eip */
525 14 * 4, /* %eflags */
526 13 * 4, /* %cs */
527 16 * 4, /* %ss */
528 7 * 4, /* %ds */
529 8 * 4, /* %es */
530 9 * 4, /* %fs */
531 10 * 4, /* %gs */
532 -1, -1, -1, -1, -1, -1, -1, -1,
533 -1, -1, -1, -1, -1, -1, -1, -1,
534 -1, -1, -1, -1, -1, -1, -1, -1,
535 -1,
536 11 * 4 /* "orig_eax" */
537};
538
539/* Mapping between the general-purpose registers in `struct
540 sigcontext' format and GDB's register cache layout. */
541
a3386186 542/* From <asm/sigcontext.h>. */
bb489b3c 543static int i386_linux_sc_reg_offset[] =
a3386186
MK
544{
545 11 * 4, /* %eax */
546 10 * 4, /* %ecx */
547 9 * 4, /* %edx */
548 8 * 4, /* %ebx */
549 7 * 4, /* %esp */
550 6 * 4, /* %ebp */
551 5 * 4, /* %esi */
552 4 * 4, /* %edi */
553 14 * 4, /* %eip */
554 16 * 4, /* %eflags */
555 15 * 4, /* %cs */
556 18 * 4, /* %ss */
557 3 * 4, /* %ds */
558 2 * 4, /* %es */
559 1 * 4, /* %fs */
560 0 * 4 /* %gs */
561};
562
90884b2b
L
563/* Get Linux/x86 target description from core dump. */
564
565static const struct target_desc *
566i386_linux_core_read_description (struct gdbarch *gdbarch,
567 struct target_ops *target,
568 bfd *abfd)
569{
570 asection *section = bfd_get_section_by_name (abfd, ".reg2");
571
572 if (section == NULL)
573 return NULL;
574
575 /* Linux/i386. */
576 return tdesc_i386_linux;
577}
578
8201327c
MK
579static void
580i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
581{
582 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
90884b2b
L
583 const struct target_desc *tdesc = info.target_desc;
584 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
585 const struct tdesc_feature *feature;
586 int valid_p;
587
588 gdb_assert (tdesc_data);
8201327c
MK
589
590 /* GNU/Linux uses ELF. */
591 i386_elf_init_abi (info, gdbarch);
592
90884b2b
L
593 /* Reserve a number for orig_eax. */
594 set_gdbarch_num_regs (gdbarch, I386_LINUX_NUM_REGS);
595
596 if (! tdesc_has_registers (tdesc))
597 tdesc = tdesc_i386_linux;
598 tdep->tdesc = tdesc;
599
600 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
601 if (feature == NULL)
602 return;
8201327c 603
90884b2b
L
604 valid_p = tdesc_numbered_register (feature, tdesc_data,
605 I386_LINUX_ORIG_EAX_REGNUM,
606 "orig_eax");
607 if (!valid_p)
608 return;
609
610 /* Add the %orig_eax register used for syscall restarting. */
8201327c 611 set_gdbarch_write_pc (gdbarch, i386_linux_write_pc);
90884b2b
L
612
613 tdep->register_reggroup_p = i386_linux_register_reggroup_p;
8201327c 614
e9f1aad5
MK
615 tdep->gregset_reg_offset = i386_linux_gregset_reg_offset;
616 tdep->gregset_num_regs = ARRAY_SIZE (i386_linux_gregset_reg_offset);
617 tdep->sizeof_gregset = 17 * 4;
618
8201327c
MK
619 tdep->jb_pc_offset = 20; /* From <bits/setjmp.h>. */
620
911bc6ee 621 tdep->sigtramp_p = i386_linux_sigtramp_p;
b7d15bf7 622 tdep->sigcontext_addr = i386_linux_sigcontext_addr;
a3386186 623 tdep->sc_reg_offset = i386_linux_sc_reg_offset;
bb489b3c 624 tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset);
8201327c 625
a6b808b4 626 set_gdbarch_process_record (gdbarch, i386_process_record);
8a2e0e28 627 set_gdbarch_process_record_signal (gdbarch, i386_linux_record_signal);
a6b808b4 628
77fcef51 629 /* Initialize the i386_linux_record_tdep. */
5e31abdf
HZ
630 /* These values are the size of the type that will be used in a system
631 call. They are obtained from Linux Kernel source. */
2c543fc4
HZ
632 i386_linux_record_tdep.size_pointer
633 = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
5e31abdf
HZ
634 i386_linux_record_tdep.size__old_kernel_stat = 32;
635 i386_linux_record_tdep.size_tms = 16;
636 i386_linux_record_tdep.size_loff_t = 8;
637 i386_linux_record_tdep.size_flock = 16;
638 i386_linux_record_tdep.size_oldold_utsname = 45;
639 i386_linux_record_tdep.size_ustat = 20;
640 i386_linux_record_tdep.size_old_sigaction = 140;
641 i386_linux_record_tdep.size_old_sigset_t = 128;
642 i386_linux_record_tdep.size_rlimit = 8;
643 i386_linux_record_tdep.size_rusage = 72;
644 i386_linux_record_tdep.size_timeval = 8;
645 i386_linux_record_tdep.size_timezone = 8;
646 i386_linux_record_tdep.size_old_gid_t = 2;
647 i386_linux_record_tdep.size_old_uid_t = 2;
648 i386_linux_record_tdep.size_fd_set = 128;
649 i386_linux_record_tdep.size_dirent = 268;
650 i386_linux_record_tdep.size_dirent64 = 276;
651 i386_linux_record_tdep.size_statfs = 64;
652 i386_linux_record_tdep.size_statfs64 = 84;
653 i386_linux_record_tdep.size_sockaddr = 16;
2c543fc4
HZ
654 i386_linux_record_tdep.size_int
655 = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
656 i386_linux_record_tdep.size_long
657 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
658 i386_linux_record_tdep.size_ulong
659 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
5e31abdf
HZ
660 i386_linux_record_tdep.size_msghdr = 28;
661 i386_linux_record_tdep.size_itimerval = 16;
662 i386_linux_record_tdep.size_stat = 88;
663 i386_linux_record_tdep.size_old_utsname = 325;
664 i386_linux_record_tdep.size_sysinfo = 64;
665 i386_linux_record_tdep.size_msqid_ds = 88;
666 i386_linux_record_tdep.size_shmid_ds = 84;
667 i386_linux_record_tdep.size_new_utsname = 390;
668 i386_linux_record_tdep.size_timex = 128;
669 i386_linux_record_tdep.size_mem_dqinfo = 24;
670 i386_linux_record_tdep.size_if_dqblk = 68;
671 i386_linux_record_tdep.size_fs_quota_stat = 68;
672 i386_linux_record_tdep.size_timespec = 8;
673 i386_linux_record_tdep.size_pollfd = 8;
674 i386_linux_record_tdep.size_NFS_FHSIZE = 32;
675 i386_linux_record_tdep.size_knfsd_fh = 132;
676 i386_linux_record_tdep.size_TASK_COMM_LEN = 16;
677 i386_linux_record_tdep.size_sigaction = 140;
678 i386_linux_record_tdep.size_sigset_t = 8;
679 i386_linux_record_tdep.size_siginfo_t = 128;
680 i386_linux_record_tdep.size_cap_user_data_t = 12;
681 i386_linux_record_tdep.size_stack_t = 12;
682 i386_linux_record_tdep.size_off_t = i386_linux_record_tdep.size_long;
683 i386_linux_record_tdep.size_stat64 = 96;
684 i386_linux_record_tdep.size_gid_t = 2;
685 i386_linux_record_tdep.size_uid_t = 2;
686 i386_linux_record_tdep.size_PAGE_SIZE = 4096;
687 i386_linux_record_tdep.size_flock64 = 24;
688 i386_linux_record_tdep.size_user_desc = 16;
689 i386_linux_record_tdep.size_io_event = 32;
690 i386_linux_record_tdep.size_iocb = 64;
691 i386_linux_record_tdep.size_epoll_event = 12;
2c543fc4
HZ
692 i386_linux_record_tdep.size_itimerspec
693 = i386_linux_record_tdep.size_timespec * 2;
5e31abdf
HZ
694 i386_linux_record_tdep.size_mq_attr = 32;
695 i386_linux_record_tdep.size_siginfo = 128;
696 i386_linux_record_tdep.size_termios = 36;
697 i386_linux_record_tdep.size_termios2 = 44;
698 i386_linux_record_tdep.size_pid_t = 4;
699 i386_linux_record_tdep.size_winsize = 8;
700 i386_linux_record_tdep.size_serial_struct = 60;
701 i386_linux_record_tdep.size_serial_icounter_struct = 80;
702 i386_linux_record_tdep.size_hayes_esp_config = 12;
2c543fc4
HZ
703 i386_linux_record_tdep.size_size_t = 4;
704 i386_linux_record_tdep.size_iovec = 8;
5e31abdf
HZ
705
706 /* These values are the second argument of system call "sys_ioctl".
707 They are obtained from Linux Kernel source. */
708 i386_linux_record_tdep.ioctl_TCGETS = 0x5401;
709 i386_linux_record_tdep.ioctl_TCSETS = 0x5402;
710 i386_linux_record_tdep.ioctl_TCSETSW = 0x5403;
711 i386_linux_record_tdep.ioctl_TCSETSF = 0x5404;
712 i386_linux_record_tdep.ioctl_TCGETA = 0x5405;
713 i386_linux_record_tdep.ioctl_TCSETA = 0x5406;
714 i386_linux_record_tdep.ioctl_TCSETAW = 0x5407;
715 i386_linux_record_tdep.ioctl_TCSETAF = 0x5408;
716 i386_linux_record_tdep.ioctl_TCSBRK = 0x5409;
717 i386_linux_record_tdep.ioctl_TCXONC = 0x540A;
718 i386_linux_record_tdep.ioctl_TCFLSH = 0x540B;
719 i386_linux_record_tdep.ioctl_TIOCEXCL = 0x540C;
720 i386_linux_record_tdep.ioctl_TIOCNXCL = 0x540D;
721 i386_linux_record_tdep.ioctl_TIOCSCTTY = 0x540E;
722 i386_linux_record_tdep.ioctl_TIOCGPGRP = 0x540F;
723 i386_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
724 i386_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
725 i386_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
726 i386_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
727 i386_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
728 i386_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
729 i386_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
730 i386_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
731 i386_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
732 i386_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
733 i386_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541A;
734 i386_linux_record_tdep.ioctl_FIONREAD = 0x541B;
735 i386_linux_record_tdep.ioctl_TIOCINQ = i386_linux_record_tdep.ioctl_FIONREAD;
736 i386_linux_record_tdep.ioctl_TIOCLINUX = 0x541C;
737 i386_linux_record_tdep.ioctl_TIOCCONS = 0x541D;
738 i386_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541E;
739 i386_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541F;
740 i386_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
741 i386_linux_record_tdep.ioctl_FIONBIO = 0x5421;
742 i386_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
743 i386_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
744 i386_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
745 i386_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
746 i386_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
747 i386_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
748 i386_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
749 i386_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
750 i386_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
751 i386_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
752 i386_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
753 i386_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
754 i386_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
755 i386_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
756 i386_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
757 i386_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
758 i386_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
759 i386_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
760 i386_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
761 i386_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
762 i386_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
763 i386_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
764 i386_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
765 i386_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
766 i386_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545A;
767 i386_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545B;
768 i386_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545C;
769 i386_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545D;
770 i386_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545E;
771 i386_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545F;
772 i386_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;
773
774 /* These values are the second argument of system call "sys_fcntl"
775 and "sys_fcntl64". They are obtained from Linux Kernel source. */
776 i386_linux_record_tdep.fcntl_F_GETLK = 5;
777 i386_linux_record_tdep.fcntl_F_GETLK64 = 12;
778 i386_linux_record_tdep.fcntl_F_SETLK64 = 13;
779 i386_linux_record_tdep.fcntl_F_SETLKW64 = 14;
50ef67b3 780
77fcef51
HZ
781 i386_linux_record_tdep.arg1 = I386_EBX_REGNUM;
782 i386_linux_record_tdep.arg2 = I386_ECX_REGNUM;
783 i386_linux_record_tdep.arg3 = I386_EDX_REGNUM;
784 i386_linux_record_tdep.arg4 = I386_ESI_REGNUM;
785 i386_linux_record_tdep.arg5 = I386_EDI_REGNUM;
2c543fc4 786 i386_linux_record_tdep.arg6 = I386_EBP_REGNUM;
77fcef51
HZ
787
788 tdep->i386_intx80_record = i386_linux_intx80_sysenter_record;
789 tdep->i386_sysenter_record = i386_linux_intx80_sysenter_record;
790
203c3895
UW
791 /* N_FUN symbols in shared libaries have 0 for their values and need
792 to be relocated. */
793 set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
794
871fbe6a 795 /* GNU/Linux uses SVR4-style shared libraries. */
982e9687 796 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
871fbe6a
MK
797 set_solib_svr4_fetch_link_map_offsets
798 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
799
800 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
bb41a796 801 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
12b8a2cb
DJ
802
803 dwarf2_frame_set_signal_frame_p (gdbarch, i386_linux_dwarf_signal_frame_p);
b2756930
KB
804
805 /* Enable TLS support. */
806 set_gdbarch_fetch_tls_load_module_address (gdbarch,
807 svr4_fetch_objfile_link_map);
237fc4c9 808
17ea7499
CES
809 /* Install supported register note sections. */
810 set_gdbarch_core_regset_sections (gdbarch, i386_linux_regset_sections);
811
90884b2b
L
812 set_gdbarch_core_read_description (gdbarch,
813 i386_linux_core_read_description);
814
237fc4c9
PA
815 /* Displaced stepping. */
816 set_gdbarch_displaced_step_copy_insn (gdbarch,
817 simple_displaced_step_copy_insn);
818 set_gdbarch_displaced_step_fixup (gdbarch, i386_displaced_step_fixup);
819 set_gdbarch_displaced_step_free_closure (gdbarch,
820 simple_displaced_step_free_closure);
821 set_gdbarch_displaced_step_location (gdbarch,
822 displaced_step_at_entry_point);
4aa995e1 823
a96d9b2e
SDJ
824 /* Functions for 'catch syscall'. */
825 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_I386);
826 set_gdbarch_get_syscall_number (gdbarch,
827 i386_linux_get_syscall_number);
828
4aa995e1 829 set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
8201327c
MK
830}
831
832/* Provide a prototype to silence -Wmissing-prototypes. */
833extern void _initialize_i386_linux_tdep (void);
834
835void
836_initialize_i386_linux_tdep (void)
837{
05816f70 838 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LINUX,
8201327c 839 i386_linux_init_abi);
90884b2b
L
840
841 /* Initialize the Linux target description */
842 initialize_tdesc_i386_linux ();
8201327c 843}
This page took 0.755666 seconds and 4 git commands to generate.