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