1 /* Target-dependent code for GNU/Linux i386.
3 Copyright (C) 2000-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
28 #include "reggroups.h"
29 #include "dwarf2-frame.h"
30 #include "i386-tdep.h"
31 #include "i386-linux-tdep.h"
32 #include "linux-tdep.h"
34 #include "glibc-tdep.h"
35 #include "solib-svr4.h"
37 #include "arch-utils.h"
38 #include "xml-syscall.h"
40 #include "i387-tdep.h"
41 #include "x86-xstate.h"
43 /* The syscall's XML filename for i386. */
44 #define XML_SYSCALL_FILENAME_I386 "syscalls/i386-linux.xml"
46 #include "record-full.h"
47 #include "linux-record.h"
48 #include "features/i386/i386-linux.c"
49 #include "features/i386/i386-mmx-linux.c"
50 #include "features/i386/i386-mpx-linux.c"
51 #include "features/i386/i386-avx-mpx-linux.c"
52 #include "features/i386/i386-avx-linux.c"
53 #include "features/i386/i386-avx-avx512-linux.c"
54 #include "features/i386/i386-avx-mpx-avx512-pku-linux.c"
56 /* Return non-zero, when the register is in the corresponding register
57 group. Put the LINUX_ORIG_EAX register in the system group. */
59 i386_linux_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
60 struct reggroup
*group
)
62 if (regnum
== I386_LINUX_ORIG_EAX_REGNUM
)
63 return (group
== system_reggroup
64 || group
== save_reggroup
65 || group
== restore_reggroup
);
66 return i386_register_reggroup_p (gdbarch
, regnum
, group
);
70 /* Recognizing signal handler frames. */
72 /* GNU/Linux has two flavors of signals. Normal signal handlers, and
73 "realtime" (RT) signals. The RT signals can provide additional
74 information to the signal handler if the SA_SIGINFO flag is set
75 when establishing a signal handler using `sigaction'. It is not
76 unlikely that future versions of GNU/Linux will support SA_SIGINFO
77 for normal signals too. */
79 /* When the i386 Linux kernel calls a signal handler and the
80 SA_RESTORER flag isn't set, the return address points to a bit of
81 code on the stack. This function returns whether the PC appears to
82 be within this bit of code.
84 The instruction sequence for normal signals is
88 or 0x58 0xb8 0x77 0x00 0x00 0x00 0xcd 0x80.
90 Checking for the code sequence should be somewhat reliable, because
91 the effect is to call the system call sigreturn. This is unlikely
92 to occur anywhere other than in a signal trampoline.
94 It kind of sucks that we have to read memory from the process in
95 order to identify a signal trampoline, but there doesn't seem to be
96 any other way. Therefore we only do the memory reads if no
97 function name could be identified, which should be the case since
98 the code is on the stack.
100 Detection of signal trampolines for handlers that set the
101 SA_RESTORER flag is in general not possible. Unfortunately this is
102 what the GNU C Library has been doing for quite some time now.
103 However, as of version 2.1.2, the GNU C Library uses signal
104 trampolines (named __restore and __restore_rt) that are identical
105 to the ones used by the kernel. Therefore, these trampolines are
108 #define LINUX_SIGTRAMP_INSN0 0x58 /* pop %eax */
109 #define LINUX_SIGTRAMP_OFFSET0 0
110 #define LINUX_SIGTRAMP_INSN1 0xb8 /* mov $NNNN, %eax */
111 #define LINUX_SIGTRAMP_OFFSET1 1
112 #define LINUX_SIGTRAMP_INSN2 0xcd /* int */
113 #define LINUX_SIGTRAMP_OFFSET2 6
115 static const gdb_byte linux_sigtramp_code
[] =
117 LINUX_SIGTRAMP_INSN0
, /* pop %eax */
118 LINUX_SIGTRAMP_INSN1
, 0x77, 0x00, 0x00, 0x00, /* mov $0x77, %eax */
119 LINUX_SIGTRAMP_INSN2
, 0x80 /* int $0x80 */
122 #define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
124 /* If THIS_FRAME is a sigtramp routine, return the address of the
125 start of the routine. Otherwise, return 0. */
128 i386_linux_sigtramp_start (struct frame_info
*this_frame
)
130 CORE_ADDR pc
= get_frame_pc (this_frame
);
131 gdb_byte buf
[LINUX_SIGTRAMP_LEN
];
133 /* We only recognize a signal trampoline if PC is at the start of
134 one of the three instructions. We optimize for finding the PC at
135 the start, as will be the case when the trampoline is not the
136 first frame on the stack. We assume that in the case where the
137 PC is not at the start of the instruction sequence, there will be
138 a few trailing readable bytes on the stack. */
140 if (!safe_frame_unwind_memory (this_frame
, pc
, buf
, LINUX_SIGTRAMP_LEN
))
143 if (buf
[0] != LINUX_SIGTRAMP_INSN0
)
149 case LINUX_SIGTRAMP_INSN1
:
150 adjust
= LINUX_SIGTRAMP_OFFSET1
;
152 case LINUX_SIGTRAMP_INSN2
:
153 adjust
= LINUX_SIGTRAMP_OFFSET2
;
161 if (!safe_frame_unwind_memory (this_frame
, pc
, buf
, LINUX_SIGTRAMP_LEN
))
165 if (memcmp (buf
, linux_sigtramp_code
, LINUX_SIGTRAMP_LEN
) != 0)
171 /* This function does the same for RT signals. Here the instruction
175 or 0xb8 0xad 0x00 0x00 0x00 0xcd 0x80.
177 The effect is to call the system call rt_sigreturn. */
179 #define LINUX_RT_SIGTRAMP_INSN0 0xb8 /* mov $NNNN, %eax */
180 #define LINUX_RT_SIGTRAMP_OFFSET0 0
181 #define LINUX_RT_SIGTRAMP_INSN1 0xcd /* int */
182 #define LINUX_RT_SIGTRAMP_OFFSET1 5
184 static const gdb_byte linux_rt_sigtramp_code
[] =
186 LINUX_RT_SIGTRAMP_INSN0
, 0xad, 0x00, 0x00, 0x00, /* mov $0xad, %eax */
187 LINUX_RT_SIGTRAMP_INSN1
, 0x80 /* int $0x80 */
190 #define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code)
192 /* If THIS_FRAME is an RT sigtramp routine, return the address of the
193 start of the routine. Otherwise, return 0. */
196 i386_linux_rt_sigtramp_start (struct frame_info
*this_frame
)
198 CORE_ADDR pc
= get_frame_pc (this_frame
);
199 gdb_byte buf
[LINUX_RT_SIGTRAMP_LEN
];
201 /* We only recognize a signal trampoline if PC is at the start of
202 one of the two instructions. We optimize for finding the PC at
203 the start, as will be the case when the trampoline is not the
204 first frame on the stack. We assume that in the case where the
205 PC is not at the start of the instruction sequence, there will be
206 a few trailing readable bytes on the stack. */
208 if (!safe_frame_unwind_memory (this_frame
, pc
, buf
, LINUX_RT_SIGTRAMP_LEN
))
211 if (buf
[0] != LINUX_RT_SIGTRAMP_INSN0
)
213 if (buf
[0] != LINUX_RT_SIGTRAMP_INSN1
)
216 pc
-= LINUX_RT_SIGTRAMP_OFFSET1
;
218 if (!safe_frame_unwind_memory (this_frame
, pc
, buf
,
219 LINUX_RT_SIGTRAMP_LEN
))
223 if (memcmp (buf
, linux_rt_sigtramp_code
, LINUX_RT_SIGTRAMP_LEN
) != 0)
229 /* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
233 i386_linux_sigtramp_p (struct frame_info
*this_frame
)
235 CORE_ADDR pc
= get_frame_pc (this_frame
);
238 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
240 /* If we have NAME, we can optimize the search. The trampolines are
241 named __restore and __restore_rt. However, they aren't dynamically
242 exported from the shared C library, so the trampoline may appear to
243 be part of the preceding function. This should always be sigaction,
244 __sigaction, or __libc_sigaction (all aliases to the same function). */
245 if (name
== NULL
|| strstr (name
, "sigaction") != NULL
)
246 return (i386_linux_sigtramp_start (this_frame
) != 0
247 || i386_linux_rt_sigtramp_start (this_frame
) != 0);
249 return (strcmp ("__restore", name
) == 0
250 || strcmp ("__restore_rt", name
) == 0);
253 /* Return one if the PC of THIS_FRAME is in a signal trampoline which
254 may have DWARF-2 CFI. */
257 i386_linux_dwarf_signal_frame_p (struct gdbarch
*gdbarch
,
258 struct frame_info
*this_frame
)
260 CORE_ADDR pc
= get_frame_pc (this_frame
);
263 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
265 /* If a vsyscall DSO is in use, the signal trampolines may have these
267 if (name
&& (strcmp (name
, "__kernel_sigreturn") == 0
268 || strcmp (name
, "__kernel_rt_sigreturn") == 0))
274 /* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
275 #define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 20
277 /* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
278 address of the associated sigcontext structure. */
281 i386_linux_sigcontext_addr (struct frame_info
*this_frame
)
283 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
284 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
289 get_frame_register (this_frame
, I386_ESP_REGNUM
, buf
);
290 sp
= extract_unsigned_integer (buf
, 4, byte_order
);
292 pc
= i386_linux_sigtramp_start (this_frame
);
295 /* The sigcontext structure lives on the stack, right after
296 the signum argument. We determine the address of the
297 sigcontext structure by looking at the frame's stack
298 pointer. Keep in mind that the first instruction of the
299 sigtramp code is "pop %eax". If the PC is after this
300 instruction, adjust the returned value accordingly. */
301 if (pc
== get_frame_pc (this_frame
))
306 pc
= i386_linux_rt_sigtramp_start (this_frame
);
309 CORE_ADDR ucontext_addr
;
311 /* The sigcontext structure is part of the user context. A
312 pointer to the user context is passed as the third argument
313 to the signal handler. */
314 read_memory (sp
+ 8, buf
, 4);
315 ucontext_addr
= extract_unsigned_integer (buf
, 4, byte_order
);
316 return ucontext_addr
+ I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET
;
319 error (_("Couldn't recognize signal trampoline."));
323 /* Set the program counter for process PTID to PC. */
326 i386_linux_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
328 regcache_cooked_write_unsigned (regcache
, I386_EIP_REGNUM
, pc
);
330 /* We must be careful with modifying the program counter. If we
331 just interrupted a system call, the kernel might try to restart
332 it when we resume the inferior. On restarting the system call,
333 the kernel will try backing up the program counter even though it
334 no longer points at the system call. This typically results in a
335 SIGSEGV or SIGILL. We can prevent this by writing `-1' in the
336 "orig_eax" pseudo-register.
338 Note that "orig_eax" is saved when setting up a dummy call frame.
339 This means that it is properly restored when that frame is
340 popped, and that the interrupted system call will be restarted
341 when we resume the inferior on return from a function call from
342 within GDB. In all other cases the system call will not be
344 regcache_cooked_write_unsigned (regcache
, I386_LINUX_ORIG_EAX_REGNUM
, -1);
347 /* Record all registers but IP register for process-record. */
350 i386_all_but_ip_registers_record (struct regcache
*regcache
)
352 if (record_full_arch_list_add_reg (regcache
, I386_EAX_REGNUM
))
354 if (record_full_arch_list_add_reg (regcache
, I386_ECX_REGNUM
))
356 if (record_full_arch_list_add_reg (regcache
, I386_EDX_REGNUM
))
358 if (record_full_arch_list_add_reg (regcache
, I386_EBX_REGNUM
))
360 if (record_full_arch_list_add_reg (regcache
, I386_ESP_REGNUM
))
362 if (record_full_arch_list_add_reg (regcache
, I386_EBP_REGNUM
))
364 if (record_full_arch_list_add_reg (regcache
, I386_ESI_REGNUM
))
366 if (record_full_arch_list_add_reg (regcache
, I386_EDI_REGNUM
))
368 if (record_full_arch_list_add_reg (regcache
, I386_EFLAGS_REGNUM
))
374 /* i386_canonicalize_syscall maps from the native i386 Linux set
375 of syscall ids into a canonical set of syscall ids used by
376 process record (a mostly trivial mapping, since the canonical
377 set was originally taken from the i386 set). */
379 static enum gdb_syscall
380 i386_canonicalize_syscall (int syscall
)
382 enum { i386_syscall_max
= 499 };
384 if (syscall
<= i386_syscall_max
)
385 return (enum gdb_syscall
) syscall
;
387 return gdb_sys_no_syscall
;
390 /* Value of the sigcode in case of a boundary fault. */
392 #define SIG_CODE_BONDARY_FAULT 3
394 /* i386 GNU/Linux implementation of the handle_segmentation_fault
395 gdbarch hook. Displays information related to MPX bound
398 i386_linux_handle_segmentation_fault (struct gdbarch
*gdbarch
,
399 struct ui_out
*uiout
)
401 /* -Wmaybe-uninitialized */
402 CORE_ADDR lower_bound
= 0, upper_bound
= 0, access
= 0;
406 if (!i386_mpx_enabled ())
411 /* Sigcode evaluates if the actual segfault is a boundary violation. */
412 sig_code
= parse_and_eval_long ("$_siginfo.si_code\n");
415 = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._lower");
417 = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._upper");
419 = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
421 CATCH (exception
, RETURN_MASK_ALL
)
427 /* If this is not a boundary violation just return. */
428 if (sig_code
!= SIG_CODE_BONDARY_FAULT
)
431 is_upper
= (access
> upper_bound
? 1 : 0);
435 uiout
->field_string ("sigcode-meaning", _("Upper bound violation"));
437 uiout
->field_string ("sigcode-meaning", _("Lower bound violation"));
439 uiout
->text (_(" while accessing address "));
440 uiout
->field_fmt ("bound-access", "%s", paddress (gdbarch
, access
));
442 uiout
->text (_("\nBounds: [lower = "));
443 uiout
->field_fmt ("lower-bound", "%s", paddress (gdbarch
, lower_bound
));
445 uiout
->text (_(", upper = "));
446 uiout
->field_fmt ("upper-bound", "%s", paddress (gdbarch
, upper_bound
));
448 uiout
->text (_("]"));
451 /* Parse the arguments of current system call instruction and record
452 the values of the registers and memory that will be changed into
453 "record_arch_list". This instruction is "int 0x80" (Linux
454 Kernel2.4) or "sysenter" (Linux Kernel 2.6).
456 Return -1 if something wrong. */
458 static struct linux_record_tdep i386_linux_record_tdep
;
461 i386_linux_intx80_sysenter_syscall_record (struct regcache
*regcache
)
464 LONGEST syscall_native
;
465 enum gdb_syscall syscall_gdb
;
467 regcache_raw_read_signed (regcache
, I386_EAX_REGNUM
, &syscall_native
);
469 syscall_gdb
= i386_canonicalize_syscall (syscall_native
);
473 printf_unfiltered (_("Process record and replay target doesn't "
474 "support syscall number %s\n"),
475 plongest (syscall_native
));
479 if (syscall_gdb
== gdb_sys_sigreturn
480 || syscall_gdb
== gdb_sys_rt_sigreturn
)
482 if (i386_all_but_ip_registers_record (regcache
))
487 ret
= record_linux_system_call (syscall_gdb
, regcache
,
488 &i386_linux_record_tdep
);
492 /* Record the return value of the system call. */
493 if (record_full_arch_list_add_reg (regcache
, I386_EAX_REGNUM
))
499 #define I386_LINUX_xstate 270
500 #define I386_LINUX_frame_size 732
503 i386_linux_record_signal (struct gdbarch
*gdbarch
,
504 struct regcache
*regcache
,
505 enum gdb_signal signal
)
509 if (i386_all_but_ip_registers_record (regcache
))
512 if (record_full_arch_list_add_reg (regcache
, I386_EIP_REGNUM
))
515 /* Record the change in the stack. */
516 regcache_raw_read_unsigned (regcache
, I386_ESP_REGNUM
, &esp
);
517 /* This is for xstate.
518 sp -= sizeof (struct _fpstate); */
519 esp
-= I386_LINUX_xstate
;
520 /* This is for frame_size.
521 sp -= sizeof (struct rt_sigframe); */
522 esp
-= I386_LINUX_frame_size
;
523 if (record_full_arch_list_add_mem (esp
,
524 I386_LINUX_xstate
+ I386_LINUX_frame_size
))
527 if (record_full_arch_list_add_end ())
534 /* Core of the implementation for gdbarch get_syscall_number. Get pending
535 syscall number from REGCACHE. If there is no pending syscall -1 will be
536 returned. Pending syscall means ptrace has stepped into the syscall but
537 another ptrace call will step out. PC is right after the int $0x80
538 / syscall / sysenter instruction in both cases, PC does not change during
539 the second ptrace step. */
542 i386_linux_get_syscall_number_from_regcache (struct regcache
*regcache
)
544 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
545 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
546 /* The content of a register. */
551 /* Getting the system call number from the register.
552 When dealing with x86 architecture, this information
553 is stored at %eax register. */
554 regcache_cooked_read (regcache
, I386_LINUX_ORIG_EAX_REGNUM
, buf
);
556 ret
= extract_signed_integer (buf
, 4, byte_order
);
561 /* Wrapper for i386_linux_get_syscall_number_from_regcache to make it
562 compatible with gdbarch get_syscall_number method prototype. */
565 i386_linux_get_syscall_number (struct gdbarch
*gdbarch
,
568 struct regcache
*regcache
= get_thread_regcache (ptid
);
570 return i386_linux_get_syscall_number_from_regcache (regcache
);
573 /* The register sets used in GNU/Linux ELF core-dumps are identical to
574 the register sets in `struct user' that are used for a.out
575 core-dumps. These are also used by ptrace(2). The corresponding
576 types are `elf_gregset_t' for the general-purpose registers (with
577 `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
578 for the floating-point registers.
580 Those types used to be available under the names `gregset_t' and
581 `fpregset_t' too, and GDB used those names in the past. But those
582 names are now used for the register sets used in the `mcontext_t'
583 type, which have a different size and layout. */
585 /* Mapping between the general-purpose registers in `struct user'
586 format and GDB's register cache layout. */
588 /* From <sys/reg.h>. */
589 int i386_linux_gregset_reg_offset
[] =
600 14 * 4, /* %eflags */
607 -1, -1, -1, -1, -1, -1, -1, -1,
608 -1, -1, -1, -1, -1, -1, -1, -1,
609 -1, -1, -1, -1, -1, -1, -1, -1,
611 -1, -1, -1, -1, -1, -1, -1, -1,
612 -1, -1, -1, -1, /* MPX registers BND0 ... BND3. */
613 -1, -1, /* MPX registers BNDCFGU, BNDSTATUS. */
614 -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512) */
615 -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm7 (AVX512) */
616 -1, /* PKRU register */
617 11 * 4, /* "orig_eax" */
620 /* Mapping between the general-purpose registers in `struct
621 sigcontext' format and GDB's register cache layout. */
623 /* From <asm/sigcontext.h>. */
624 static int i386_linux_sc_reg_offset
[] =
635 16 * 4, /* %eflags */
644 /* Get XSAVE extended state xcr0 from core dump. */
647 i386_linux_core_read_xcr0 (bfd
*abfd
)
649 asection
*xstate
= bfd_get_section_by_name (abfd
, ".reg-xstate");
654 size_t size
= bfd_section_size (abfd
, xstate
);
656 /* Check extended state size. */
657 if (size
< X86_XSTATE_AVX_SIZE
)
658 xcr0
= X86_XSTATE_SSE_MASK
;
663 if (! bfd_get_section_contents (abfd
, xstate
, contents
,
664 I386_LINUX_XSAVE_XCR0_OFFSET
,
667 warning (_("Couldn't read `xcr0' bytes from "
668 "`.reg-xstate' section in core file."));
672 xcr0
= bfd_get_64 (abfd
, contents
);
681 /* Get Linux/x86 target description from core dump. */
683 static const struct target_desc
*
684 i386_linux_core_read_description (struct gdbarch
*gdbarch
,
685 struct target_ops
*target
,
689 uint64_t xcr0
= i386_linux_core_read_xcr0 (abfd
);
691 switch ((xcr0
& X86_XSTATE_ALL_MASK
))
693 case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK
:
694 return tdesc_i386_avx_mpx_avx512_pku_linux
;
695 case X86_XSTATE_AVX_AVX512_MASK
:
696 return tdesc_i386_avx_avx512_linux
;
697 case X86_XSTATE_MPX_MASK
:
698 return tdesc_i386_mpx_linux
;
699 case X86_XSTATE_AVX_MPX_MASK
:
700 return tdesc_i386_avx_mpx_linux
;
701 case X86_XSTATE_AVX_MASK
:
702 return tdesc_i386_avx_linux
;
703 case X86_XSTATE_SSE_MASK
:
704 return tdesc_i386_linux
;
705 case X86_XSTATE_X87_MASK
:
706 return tdesc_i386_mmx_linux
;
711 if (bfd_get_section_by_name (abfd
, ".reg-xfp") != NULL
)
712 return tdesc_i386_linux
;
714 return tdesc_i386_mmx_linux
;
717 /* Similar to i386_supply_fpregset, but use XSAVE extended state. */
720 i386_linux_supply_xstateregset (const struct regset
*regset
,
721 struct regcache
*regcache
, int regnum
,
722 const void *xstateregs
, size_t len
)
724 i387_supply_xsave (regcache
, regnum
, xstateregs
);
728 x86_linux_get_siginfo_type (struct gdbarch
*gdbarch
)
730 return linux_get_siginfo_type_with_fields (gdbarch
, LINUX_SIGINFO_FIELD_ADDR_BND
);
733 /* Similar to i386_collect_fpregset, but use XSAVE extended state. */
736 i386_linux_collect_xstateregset (const struct regset
*regset
,
737 const struct regcache
*regcache
,
738 int regnum
, void *xstateregs
, size_t len
)
740 i387_collect_xsave (regcache
, regnum
, xstateregs
, 1);
743 /* Register set definitions. */
745 static const struct regset i386_linux_xstateregset
=
748 i386_linux_supply_xstateregset
,
749 i386_linux_collect_xstateregset
752 /* Iterate over core file register note sections. */
755 i386_linux_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
756 iterate_over_regset_sections_cb
*cb
,
758 const struct regcache
*regcache
)
760 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
762 cb (".reg", 68, &i386_gregset
, NULL
, cb_data
);
764 if (tdep
->xcr0
& X86_XSTATE_AVX
)
765 cb (".reg-xstate", X86_XSTATE_SIZE (tdep
->xcr0
),
766 &i386_linux_xstateregset
, "XSAVE extended state", cb_data
);
767 else if (tdep
->xcr0
& X86_XSTATE_SSE
)
768 cb (".reg-xfp", 512, &i386_fpregset
, "extended floating-point",
771 cb (".reg2", 108, &i386_fpregset
, NULL
, cb_data
);
774 /* Linux kernel shows PC value after the 'int $0x80' instruction even if
775 inferior is still inside the syscall. On next PTRACE_SINGLESTEP it will
776 finish the syscall but PC will not change.
778 Some vDSOs contain 'int $0x80; ret' and during stepping out of the syscall
779 i386_displaced_step_fixup would keep PC at the displaced pad location.
780 As PC is pointing to the 'ret' instruction before the step
781 i386_displaced_step_fixup would expect inferior has just executed that 'ret'
782 and PC should not be adjusted. In reality it finished syscall instead and
783 PC should get relocated back to its vDSO address. Hide the 'ret'
784 instruction by 'nop' so that i386_displaced_step_fixup is not confused.
786 It is not fully correct as the bytes in struct displaced_step_closure will
787 not match the inferior code. But we would need some new flag in
788 displaced_step_closure otherwise to keep the state that syscall is finishing
789 for the later i386_displaced_step_fixup execution as the syscall execution
790 is already no longer detectable there. The new flag field would mean
791 i386-linux-tdep.c needs to wrap all the displacement methods of i386-tdep.c
792 which does not seem worth it. The same effect is achieved by patching that
793 'nop' instruction there instead. */
795 static struct displaced_step_closure
*
796 i386_linux_displaced_step_copy_insn (struct gdbarch
*gdbarch
,
797 CORE_ADDR from
, CORE_ADDR to
,
798 struct regcache
*regs
)
800 struct displaced_step_closure
*closure
;
802 closure
= i386_displaced_step_copy_insn (gdbarch
, from
, to
, regs
);
804 if (i386_linux_get_syscall_number_from_regcache (regs
) != -1)
806 /* Since we use simple_displaced_step_copy_insn, our closure is a
807 copy of the instruction. */
808 gdb_byte
*insn
= (gdb_byte
*) closure
;
818 i386_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
820 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
821 const struct target_desc
*tdesc
= info
.target_desc
;
822 struct tdesc_arch_data
*tdesc_data
823 = (struct tdesc_arch_data
*) info
.tdep_info
;
824 const struct tdesc_feature
*feature
;
827 gdb_assert (tdesc_data
);
829 linux_init_abi (info
, gdbarch
);
831 /* GNU/Linux uses ELF. */
832 i386_elf_init_abi (info
, gdbarch
);
834 /* Reserve a number for orig_eax. */
835 set_gdbarch_num_regs (gdbarch
, I386_LINUX_NUM_REGS
);
837 if (! tdesc_has_registers (tdesc
))
838 tdesc
= tdesc_i386_linux
;
841 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.linux");
845 valid_p
= tdesc_numbered_register (feature
, tdesc_data
,
846 I386_LINUX_ORIG_EAX_REGNUM
,
851 /* Add the %orig_eax register used for syscall restarting. */
852 set_gdbarch_write_pc (gdbarch
, i386_linux_write_pc
);
854 tdep
->register_reggroup_p
= i386_linux_register_reggroup_p
;
856 tdep
->gregset_reg_offset
= i386_linux_gregset_reg_offset
;
857 tdep
->gregset_num_regs
= ARRAY_SIZE (i386_linux_gregset_reg_offset
);
858 tdep
->sizeof_gregset
= 17 * 4;
860 tdep
->jb_pc_offset
= 20; /* From <bits/setjmp.h>. */
862 tdep
->sigtramp_p
= i386_linux_sigtramp_p
;
863 tdep
->sigcontext_addr
= i386_linux_sigcontext_addr
;
864 tdep
->sc_reg_offset
= i386_linux_sc_reg_offset
;
865 tdep
->sc_num_regs
= ARRAY_SIZE (i386_linux_sc_reg_offset
);
867 tdep
->xsave_xcr0_offset
= I386_LINUX_XSAVE_XCR0_OFFSET
;
869 set_gdbarch_process_record (gdbarch
, i386_process_record
);
870 set_gdbarch_process_record_signal (gdbarch
, i386_linux_record_signal
);
872 /* Initialize the i386_linux_record_tdep. */
873 /* These values are the size of the type that will be used in a system
874 call. They are obtained from Linux Kernel source. */
875 i386_linux_record_tdep
.size_pointer
876 = gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
;
877 i386_linux_record_tdep
.size__old_kernel_stat
= 32;
878 i386_linux_record_tdep
.size_tms
= 16;
879 i386_linux_record_tdep
.size_loff_t
= 8;
880 i386_linux_record_tdep
.size_flock
= 16;
881 i386_linux_record_tdep
.size_oldold_utsname
= 45;
882 i386_linux_record_tdep
.size_ustat
= 20;
883 i386_linux_record_tdep
.size_old_sigaction
= 16;
884 i386_linux_record_tdep
.size_old_sigset_t
= 4;
885 i386_linux_record_tdep
.size_rlimit
= 8;
886 i386_linux_record_tdep
.size_rusage
= 72;
887 i386_linux_record_tdep
.size_timeval
= 8;
888 i386_linux_record_tdep
.size_timezone
= 8;
889 i386_linux_record_tdep
.size_old_gid_t
= 2;
890 i386_linux_record_tdep
.size_old_uid_t
= 2;
891 i386_linux_record_tdep
.size_fd_set
= 128;
892 i386_linux_record_tdep
.size_old_dirent
= 268;
893 i386_linux_record_tdep
.size_statfs
= 64;
894 i386_linux_record_tdep
.size_statfs64
= 84;
895 i386_linux_record_tdep
.size_sockaddr
= 16;
896 i386_linux_record_tdep
.size_int
897 = gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
;
898 i386_linux_record_tdep
.size_long
899 = gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
;
900 i386_linux_record_tdep
.size_ulong
901 = gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
;
902 i386_linux_record_tdep
.size_msghdr
= 28;
903 i386_linux_record_tdep
.size_itimerval
= 16;
904 i386_linux_record_tdep
.size_stat
= 88;
905 i386_linux_record_tdep
.size_old_utsname
= 325;
906 i386_linux_record_tdep
.size_sysinfo
= 64;
907 i386_linux_record_tdep
.size_msqid_ds
= 88;
908 i386_linux_record_tdep
.size_shmid_ds
= 84;
909 i386_linux_record_tdep
.size_new_utsname
= 390;
910 i386_linux_record_tdep
.size_timex
= 128;
911 i386_linux_record_tdep
.size_mem_dqinfo
= 24;
912 i386_linux_record_tdep
.size_if_dqblk
= 68;
913 i386_linux_record_tdep
.size_fs_quota_stat
= 68;
914 i386_linux_record_tdep
.size_timespec
= 8;
915 i386_linux_record_tdep
.size_pollfd
= 8;
916 i386_linux_record_tdep
.size_NFS_FHSIZE
= 32;
917 i386_linux_record_tdep
.size_knfsd_fh
= 132;
918 i386_linux_record_tdep
.size_TASK_COMM_LEN
= 16;
919 i386_linux_record_tdep
.size_sigaction
= 20;
920 i386_linux_record_tdep
.size_sigset_t
= 8;
921 i386_linux_record_tdep
.size_siginfo_t
= 128;
922 i386_linux_record_tdep
.size_cap_user_data_t
= 12;
923 i386_linux_record_tdep
.size_stack_t
= 12;
924 i386_linux_record_tdep
.size_off_t
= i386_linux_record_tdep
.size_long
;
925 i386_linux_record_tdep
.size_stat64
= 96;
926 i386_linux_record_tdep
.size_gid_t
= 4;
927 i386_linux_record_tdep
.size_uid_t
= 4;
928 i386_linux_record_tdep
.size_PAGE_SIZE
= 4096;
929 i386_linux_record_tdep
.size_flock64
= 24;
930 i386_linux_record_tdep
.size_user_desc
= 16;
931 i386_linux_record_tdep
.size_io_event
= 32;
932 i386_linux_record_tdep
.size_iocb
= 64;
933 i386_linux_record_tdep
.size_epoll_event
= 12;
934 i386_linux_record_tdep
.size_itimerspec
935 = i386_linux_record_tdep
.size_timespec
* 2;
936 i386_linux_record_tdep
.size_mq_attr
= 32;
937 i386_linux_record_tdep
.size_termios
= 36;
938 i386_linux_record_tdep
.size_termios2
= 44;
939 i386_linux_record_tdep
.size_pid_t
= 4;
940 i386_linux_record_tdep
.size_winsize
= 8;
941 i386_linux_record_tdep
.size_serial_struct
= 60;
942 i386_linux_record_tdep
.size_serial_icounter_struct
= 80;
943 i386_linux_record_tdep
.size_hayes_esp_config
= 12;
944 i386_linux_record_tdep
.size_size_t
= 4;
945 i386_linux_record_tdep
.size_iovec
= 8;
946 i386_linux_record_tdep
.size_time_t
= 4;
948 /* These values are the second argument of system call "sys_ioctl".
949 They are obtained from Linux Kernel source. */
950 i386_linux_record_tdep
.ioctl_TCGETS
= 0x5401;
951 i386_linux_record_tdep
.ioctl_TCSETS
= 0x5402;
952 i386_linux_record_tdep
.ioctl_TCSETSW
= 0x5403;
953 i386_linux_record_tdep
.ioctl_TCSETSF
= 0x5404;
954 i386_linux_record_tdep
.ioctl_TCGETA
= 0x5405;
955 i386_linux_record_tdep
.ioctl_TCSETA
= 0x5406;
956 i386_linux_record_tdep
.ioctl_TCSETAW
= 0x5407;
957 i386_linux_record_tdep
.ioctl_TCSETAF
= 0x5408;
958 i386_linux_record_tdep
.ioctl_TCSBRK
= 0x5409;
959 i386_linux_record_tdep
.ioctl_TCXONC
= 0x540A;
960 i386_linux_record_tdep
.ioctl_TCFLSH
= 0x540B;
961 i386_linux_record_tdep
.ioctl_TIOCEXCL
= 0x540C;
962 i386_linux_record_tdep
.ioctl_TIOCNXCL
= 0x540D;
963 i386_linux_record_tdep
.ioctl_TIOCSCTTY
= 0x540E;
964 i386_linux_record_tdep
.ioctl_TIOCGPGRP
= 0x540F;
965 i386_linux_record_tdep
.ioctl_TIOCSPGRP
= 0x5410;
966 i386_linux_record_tdep
.ioctl_TIOCOUTQ
= 0x5411;
967 i386_linux_record_tdep
.ioctl_TIOCSTI
= 0x5412;
968 i386_linux_record_tdep
.ioctl_TIOCGWINSZ
= 0x5413;
969 i386_linux_record_tdep
.ioctl_TIOCSWINSZ
= 0x5414;
970 i386_linux_record_tdep
.ioctl_TIOCMGET
= 0x5415;
971 i386_linux_record_tdep
.ioctl_TIOCMBIS
= 0x5416;
972 i386_linux_record_tdep
.ioctl_TIOCMBIC
= 0x5417;
973 i386_linux_record_tdep
.ioctl_TIOCMSET
= 0x5418;
974 i386_linux_record_tdep
.ioctl_TIOCGSOFTCAR
= 0x5419;
975 i386_linux_record_tdep
.ioctl_TIOCSSOFTCAR
= 0x541A;
976 i386_linux_record_tdep
.ioctl_FIONREAD
= 0x541B;
977 i386_linux_record_tdep
.ioctl_TIOCINQ
= i386_linux_record_tdep
.ioctl_FIONREAD
;
978 i386_linux_record_tdep
.ioctl_TIOCLINUX
= 0x541C;
979 i386_linux_record_tdep
.ioctl_TIOCCONS
= 0x541D;
980 i386_linux_record_tdep
.ioctl_TIOCGSERIAL
= 0x541E;
981 i386_linux_record_tdep
.ioctl_TIOCSSERIAL
= 0x541F;
982 i386_linux_record_tdep
.ioctl_TIOCPKT
= 0x5420;
983 i386_linux_record_tdep
.ioctl_FIONBIO
= 0x5421;
984 i386_linux_record_tdep
.ioctl_TIOCNOTTY
= 0x5422;
985 i386_linux_record_tdep
.ioctl_TIOCSETD
= 0x5423;
986 i386_linux_record_tdep
.ioctl_TIOCGETD
= 0x5424;
987 i386_linux_record_tdep
.ioctl_TCSBRKP
= 0x5425;
988 i386_linux_record_tdep
.ioctl_TIOCTTYGSTRUCT
= 0x5426;
989 i386_linux_record_tdep
.ioctl_TIOCSBRK
= 0x5427;
990 i386_linux_record_tdep
.ioctl_TIOCCBRK
= 0x5428;
991 i386_linux_record_tdep
.ioctl_TIOCGSID
= 0x5429;
992 i386_linux_record_tdep
.ioctl_TCGETS2
= 0x802c542a;
993 i386_linux_record_tdep
.ioctl_TCSETS2
= 0x402c542b;
994 i386_linux_record_tdep
.ioctl_TCSETSW2
= 0x402c542c;
995 i386_linux_record_tdep
.ioctl_TCSETSF2
= 0x402c542d;
996 i386_linux_record_tdep
.ioctl_TIOCGPTN
= 0x80045430;
997 i386_linux_record_tdep
.ioctl_TIOCSPTLCK
= 0x40045431;
998 i386_linux_record_tdep
.ioctl_FIONCLEX
= 0x5450;
999 i386_linux_record_tdep
.ioctl_FIOCLEX
= 0x5451;
1000 i386_linux_record_tdep
.ioctl_FIOASYNC
= 0x5452;
1001 i386_linux_record_tdep
.ioctl_TIOCSERCONFIG
= 0x5453;
1002 i386_linux_record_tdep
.ioctl_TIOCSERGWILD
= 0x5454;
1003 i386_linux_record_tdep
.ioctl_TIOCSERSWILD
= 0x5455;
1004 i386_linux_record_tdep
.ioctl_TIOCGLCKTRMIOS
= 0x5456;
1005 i386_linux_record_tdep
.ioctl_TIOCSLCKTRMIOS
= 0x5457;
1006 i386_linux_record_tdep
.ioctl_TIOCSERGSTRUCT
= 0x5458;
1007 i386_linux_record_tdep
.ioctl_TIOCSERGETLSR
= 0x5459;
1008 i386_linux_record_tdep
.ioctl_TIOCSERGETMULTI
= 0x545A;
1009 i386_linux_record_tdep
.ioctl_TIOCSERSETMULTI
= 0x545B;
1010 i386_linux_record_tdep
.ioctl_TIOCMIWAIT
= 0x545C;
1011 i386_linux_record_tdep
.ioctl_TIOCGICOUNT
= 0x545D;
1012 i386_linux_record_tdep
.ioctl_TIOCGHAYESESP
= 0x545E;
1013 i386_linux_record_tdep
.ioctl_TIOCSHAYESESP
= 0x545F;
1014 i386_linux_record_tdep
.ioctl_FIOQSIZE
= 0x5460;
1016 /* These values are the second argument of system call "sys_fcntl"
1017 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1018 i386_linux_record_tdep
.fcntl_F_GETLK
= 5;
1019 i386_linux_record_tdep
.fcntl_F_GETLK64
= 12;
1020 i386_linux_record_tdep
.fcntl_F_SETLK64
= 13;
1021 i386_linux_record_tdep
.fcntl_F_SETLKW64
= 14;
1023 i386_linux_record_tdep
.arg1
= I386_EBX_REGNUM
;
1024 i386_linux_record_tdep
.arg2
= I386_ECX_REGNUM
;
1025 i386_linux_record_tdep
.arg3
= I386_EDX_REGNUM
;
1026 i386_linux_record_tdep
.arg4
= I386_ESI_REGNUM
;
1027 i386_linux_record_tdep
.arg5
= I386_EDI_REGNUM
;
1028 i386_linux_record_tdep
.arg6
= I386_EBP_REGNUM
;
1030 tdep
->i386_intx80_record
= i386_linux_intx80_sysenter_syscall_record
;
1031 tdep
->i386_sysenter_record
= i386_linux_intx80_sysenter_syscall_record
;
1032 tdep
->i386_syscall_record
= i386_linux_intx80_sysenter_syscall_record
;
1034 /* N_FUN symbols in shared libaries have 0 for their values and need
1036 set_gdbarch_sofun_address_maybe_missing (gdbarch
, 1);
1038 /* GNU/Linux uses SVR4-style shared libraries. */
1039 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
1040 set_solib_svr4_fetch_link_map_offsets
1041 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
1043 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
1044 set_gdbarch_skip_solib_resolver (gdbarch
, glibc_skip_solib_resolver
);
1046 dwarf2_frame_set_signal_frame_p (gdbarch
, i386_linux_dwarf_signal_frame_p
);
1048 /* Enable TLS support. */
1049 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
1050 svr4_fetch_objfile_link_map
);
1052 /* Core file support. */
1053 set_gdbarch_iterate_over_regset_sections
1054 (gdbarch
, i386_linux_iterate_over_regset_sections
);
1055 set_gdbarch_core_read_description (gdbarch
,
1056 i386_linux_core_read_description
);
1058 /* Displaced stepping. */
1059 set_gdbarch_displaced_step_copy_insn (gdbarch
,
1060 i386_linux_displaced_step_copy_insn
);
1061 set_gdbarch_displaced_step_fixup (gdbarch
, i386_displaced_step_fixup
);
1062 set_gdbarch_displaced_step_free_closure (gdbarch
,
1063 simple_displaced_step_free_closure
);
1064 set_gdbarch_displaced_step_location (gdbarch
,
1065 linux_displaced_step_location
);
1067 /* Functions for 'catch syscall'. */
1068 set_xml_syscall_file_name (gdbarch
, XML_SYSCALL_FILENAME_I386
);
1069 set_gdbarch_get_syscall_number (gdbarch
,
1070 i386_linux_get_syscall_number
);
1072 set_gdbarch_get_siginfo_type (gdbarch
, x86_linux_get_siginfo_type
);
1073 set_gdbarch_handle_segmentation_fault (gdbarch
,
1074 i386_linux_handle_segmentation_fault
);
1077 /* Provide a prototype to silence -Wmissing-prototypes. */
1078 extern void _initialize_i386_linux_tdep (void);
1081 _initialize_i386_linux_tdep (void)
1083 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_LINUX
,
1084 i386_linux_init_abi
);
1086 /* Initialize the Linux target description. */
1087 initialize_tdesc_i386_linux ();
1088 initialize_tdesc_i386_mmx_linux ();
1089 initialize_tdesc_i386_avx_linux ();
1090 initialize_tdesc_i386_mpx_linux ();
1091 initialize_tdesc_i386_avx_mpx_linux ();
1092 initialize_tdesc_i386_avx_avx512_linux ();
1093 initialize_tdesc_i386_avx_mpx_avx512_pku_linux ();