[GDBserver] Centralize tdesc for i386-linux
[external/binutils.git] / gdb / i386-linux-tdep.c
1 /* Target-dependent code for GNU/Linux i386.
2
3    Copyright (C) 2000-2017 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include "defs.h"
21 #include "gdbcore.h"
22 #include "frame.h"
23 #include "value.h"
24 #include "regcache.h"
25 #include "regset.h"
26 #include "inferior.h"
27 #include "osabi.h"
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"
33 #include "utils.h"
34 #include "glibc-tdep.h"
35 #include "solib-svr4.h"
36 #include "symtab.h"
37 #include "arch-utils.h"
38 #include "xml-syscall.h"
39
40 #include "i387-tdep.h"
41 #include "x86-xstate.h"
42
43 /* The syscall's XML filename for i386.  */
44 #define XML_SYSCALL_FILENAME_I386 "syscalls/i386-linux.xml"
45
46 #include "record-full.h"
47 #include "linux-record.h"
48
49 #include "features/i386/32bit-core.c"
50 #include "features/i386/32bit-sse.c"
51 #include "features/i386/32bit-linux.c"
52 #include "features/i386/32bit-avx.c"
53 #include "features/i386/32bit-mpx.c"
54 #include "features/i386/32bit-avx512.c"
55 #include "features/i386/32bit-pkeys.c"
56 #include "target-descriptions.h"
57
58 /* Return non-zero, when the register is in the corresponding register
59    group.  Put the LINUX_ORIG_EAX register in the system group.  */
60 static int
61 i386_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
62                                 struct reggroup *group)
63 {
64   if (regnum == I386_LINUX_ORIG_EAX_REGNUM)
65     return (group == system_reggroup
66             || group == save_reggroup
67             || group == restore_reggroup);
68   return i386_register_reggroup_p (gdbarch, regnum, group);
69 }
70
71 \f
72 /* Recognizing signal handler frames.  */
73
74 /* GNU/Linux has two flavors of signals.  Normal signal handlers, and
75    "realtime" (RT) signals.  The RT signals can provide additional
76    information to the signal handler if the SA_SIGINFO flag is set
77    when establishing a signal handler using `sigaction'.  It is not
78    unlikely that future versions of GNU/Linux will support SA_SIGINFO
79    for normal signals too.  */
80
81 /* When the i386 Linux kernel calls a signal handler and the
82    SA_RESTORER flag isn't set, the return address points to a bit of
83    code on the stack.  This function returns whether the PC appears to
84    be within this bit of code.
85
86    The instruction sequence for normal signals is
87        pop    %eax
88        mov    $0x77, %eax
89        int    $0x80
90    or 0x58 0xb8 0x77 0x00 0x00 0x00 0xcd 0x80.
91
92    Checking for the code sequence should be somewhat reliable, because
93    the effect is to call the system call sigreturn.  This is unlikely
94    to occur anywhere other than in a signal trampoline.
95
96    It kind of sucks that we have to read memory from the process in
97    order to identify a signal trampoline, but there doesn't seem to be
98    any other way.  Therefore we only do the memory reads if no
99    function name could be identified, which should be the case since
100    the code is on the stack.
101
102    Detection of signal trampolines for handlers that set the
103    SA_RESTORER flag is in general not possible.  Unfortunately this is
104    what the GNU C Library has been doing for quite some time now.
105    However, as of version 2.1.2, the GNU C Library uses signal
106    trampolines (named __restore and __restore_rt) that are identical
107    to the ones used by the kernel.  Therefore, these trampolines are
108    supported too.  */
109
110 #define LINUX_SIGTRAMP_INSN0    0x58    /* pop %eax */
111 #define LINUX_SIGTRAMP_OFFSET0  0
112 #define LINUX_SIGTRAMP_INSN1    0xb8    /* mov $NNNN, %eax */
113 #define LINUX_SIGTRAMP_OFFSET1  1
114 #define LINUX_SIGTRAMP_INSN2    0xcd    /* int */
115 #define LINUX_SIGTRAMP_OFFSET2  6
116
117 static const gdb_byte linux_sigtramp_code[] =
118 {
119   LINUX_SIGTRAMP_INSN0,                                 /* pop %eax */
120   LINUX_SIGTRAMP_INSN1, 0x77, 0x00, 0x00, 0x00,         /* mov $0x77, %eax */
121   LINUX_SIGTRAMP_INSN2, 0x80                            /* int $0x80 */
122 };
123
124 #define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
125
126 /* If THIS_FRAME is a sigtramp routine, return the address of the
127    start of the routine.  Otherwise, return 0.  */
128
129 static CORE_ADDR
130 i386_linux_sigtramp_start (struct frame_info *this_frame)
131 {
132   CORE_ADDR pc = get_frame_pc (this_frame);
133   gdb_byte buf[LINUX_SIGTRAMP_LEN];
134
135   /* We only recognize a signal trampoline if PC is at the start of
136      one of the three instructions.  We optimize for finding the PC at
137      the start, as will be the case when the trampoline is not the
138      first frame on the stack.  We assume that in the case where the
139      PC is not at the start of the instruction sequence, there will be
140      a few trailing readable bytes on the stack.  */
141
142   if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
143     return 0;
144
145   if (buf[0] != LINUX_SIGTRAMP_INSN0)
146     {
147       int adjust;
148
149       switch (buf[0])
150         {
151         case LINUX_SIGTRAMP_INSN1:
152           adjust = LINUX_SIGTRAMP_OFFSET1;
153           break;
154         case LINUX_SIGTRAMP_INSN2:
155           adjust = LINUX_SIGTRAMP_OFFSET2;
156           break;
157         default:
158           return 0;
159         }
160
161       pc -= adjust;
162
163       if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
164         return 0;
165     }
166
167   if (memcmp (buf, linux_sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
168     return 0;
169
170   return pc;
171 }
172
173 /* This function does the same for RT signals.  Here the instruction
174    sequence is
175        mov    $0xad, %eax
176        int    $0x80
177    or 0xb8 0xad 0x00 0x00 0x00 0xcd 0x80.
178
179    The effect is to call the system call rt_sigreturn.  */
180
181 #define LINUX_RT_SIGTRAMP_INSN0         0xb8 /* mov $NNNN, %eax */
182 #define LINUX_RT_SIGTRAMP_OFFSET0       0
183 #define LINUX_RT_SIGTRAMP_INSN1         0xcd /* int */
184 #define LINUX_RT_SIGTRAMP_OFFSET1       5
185
186 static const gdb_byte linux_rt_sigtramp_code[] =
187 {
188   LINUX_RT_SIGTRAMP_INSN0, 0xad, 0x00, 0x00, 0x00,      /* mov $0xad, %eax */
189   LINUX_RT_SIGTRAMP_INSN1, 0x80                         /* int $0x80 */
190 };
191
192 #define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code)
193
194 /* If THIS_FRAME is an RT sigtramp routine, return the address of the
195    start of the routine.  Otherwise, return 0.  */
196
197 static CORE_ADDR
198 i386_linux_rt_sigtramp_start (struct frame_info *this_frame)
199 {
200   CORE_ADDR pc = get_frame_pc (this_frame);
201   gdb_byte buf[LINUX_RT_SIGTRAMP_LEN];
202
203   /* We only recognize a signal trampoline if PC is at the start of
204      one of the two instructions.  We optimize for finding the PC at
205      the start, as will be the case when the trampoline is not the
206      first frame on the stack.  We assume that in the case where the
207      PC is not at the start of the instruction sequence, there will be
208      a few trailing readable bytes on the stack.  */
209
210   if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_RT_SIGTRAMP_LEN))
211     return 0;
212
213   if (buf[0] != LINUX_RT_SIGTRAMP_INSN0)
214     {
215       if (buf[0] != LINUX_RT_SIGTRAMP_INSN1)
216         return 0;
217
218       pc -= LINUX_RT_SIGTRAMP_OFFSET1;
219
220       if (!safe_frame_unwind_memory (this_frame, pc, buf,
221                                      LINUX_RT_SIGTRAMP_LEN))
222         return 0;
223     }
224
225   if (memcmp (buf, linux_rt_sigtramp_code, LINUX_RT_SIGTRAMP_LEN) != 0)
226     return 0;
227
228   return pc;
229 }
230
231 /* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
232    routine.  */
233
234 static int
235 i386_linux_sigtramp_p (struct frame_info *this_frame)
236 {
237   CORE_ADDR pc = get_frame_pc (this_frame);
238   const char *name;
239
240   find_pc_partial_function (pc, &name, NULL, NULL);
241
242   /* If we have NAME, we can optimize the search.  The trampolines are
243      named __restore and __restore_rt.  However, they aren't dynamically
244      exported from the shared C library, so the trampoline may appear to
245      be part of the preceding function.  This should always be sigaction,
246      __sigaction, or __libc_sigaction (all aliases to the same function).  */
247   if (name == NULL || strstr (name, "sigaction") != NULL)
248     return (i386_linux_sigtramp_start (this_frame) != 0
249             || i386_linux_rt_sigtramp_start (this_frame) != 0);
250
251   return (strcmp ("__restore", name) == 0
252           || strcmp ("__restore_rt", name) == 0);
253 }
254
255 /* Return one if the PC of THIS_FRAME is in a signal trampoline which
256    may have DWARF-2 CFI.  */
257
258 static int
259 i386_linux_dwarf_signal_frame_p (struct gdbarch *gdbarch,
260                                  struct frame_info *this_frame)
261 {
262   CORE_ADDR pc = get_frame_pc (this_frame);
263   const char *name;
264
265   find_pc_partial_function (pc, &name, NULL, NULL);
266
267   /* If a vsyscall DSO is in use, the signal trampolines may have these
268      names.  */
269   if (name && (strcmp (name, "__kernel_sigreturn") == 0
270                || strcmp (name, "__kernel_rt_sigreturn") == 0))
271     return 1;
272
273   return 0;
274 }
275
276 /* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>.  */
277 #define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 20
278
279 /* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
280    address of the associated sigcontext structure.  */
281
282 static CORE_ADDR
283 i386_linux_sigcontext_addr (struct frame_info *this_frame)
284 {
285   struct gdbarch *gdbarch = get_frame_arch (this_frame);
286   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
287   CORE_ADDR pc;
288   CORE_ADDR sp;
289   gdb_byte buf[4];
290
291   get_frame_register (this_frame, I386_ESP_REGNUM, buf);
292   sp = extract_unsigned_integer (buf, 4, byte_order);
293
294   pc = i386_linux_sigtramp_start (this_frame);
295   if (pc)
296     {
297       /* The sigcontext structure lives on the stack, right after
298          the signum argument.  We determine the address of the
299          sigcontext structure by looking at the frame's stack
300          pointer.  Keep in mind that the first instruction of the
301          sigtramp code is "pop %eax".  If the PC is after this
302          instruction, adjust the returned value accordingly.  */
303       if (pc == get_frame_pc (this_frame))
304         return sp + 4;
305       return sp;
306     }
307
308   pc = i386_linux_rt_sigtramp_start (this_frame);
309   if (pc)
310     {
311       CORE_ADDR ucontext_addr;
312
313       /* The sigcontext structure is part of the user context.  A
314          pointer to the user context is passed as the third argument
315          to the signal handler.  */
316       read_memory (sp + 8, buf, 4);
317       ucontext_addr = extract_unsigned_integer (buf, 4, byte_order);
318       return ucontext_addr + I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET;
319     }
320
321   error (_("Couldn't recognize signal trampoline."));
322   return 0;
323 }
324
325 /* Set the program counter for process PTID to PC.  */
326
327 static void
328 i386_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
329 {
330   regcache_cooked_write_unsigned (regcache, I386_EIP_REGNUM, pc);
331
332   /* We must be careful with modifying the program counter.  If we
333      just interrupted a system call, the kernel might try to restart
334      it when we resume the inferior.  On restarting the system call,
335      the kernel will try backing up the program counter even though it
336      no longer points at the system call.  This typically results in a
337      SIGSEGV or SIGILL.  We can prevent this by writing `-1' in the
338      "orig_eax" pseudo-register.
339
340      Note that "orig_eax" is saved when setting up a dummy call frame.
341      This means that it is properly restored when that frame is
342      popped, and that the interrupted system call will be restarted
343      when we resume the inferior on return from a function call from
344      within GDB.  In all other cases the system call will not be
345      restarted.  */
346   regcache_cooked_write_unsigned (regcache, I386_LINUX_ORIG_EAX_REGNUM, -1);
347 }
348
349 /* Record all registers but IP register for process-record.  */
350
351 static int
352 i386_all_but_ip_registers_record (struct regcache *regcache)
353 {
354   if (record_full_arch_list_add_reg (regcache, I386_EAX_REGNUM))
355     return -1;
356   if (record_full_arch_list_add_reg (regcache, I386_ECX_REGNUM))
357     return -1;
358   if (record_full_arch_list_add_reg (regcache, I386_EDX_REGNUM))
359     return -1;
360   if (record_full_arch_list_add_reg (regcache, I386_EBX_REGNUM))
361     return -1;
362   if (record_full_arch_list_add_reg (regcache, I386_ESP_REGNUM))
363     return -1;
364   if (record_full_arch_list_add_reg (regcache, I386_EBP_REGNUM))
365     return -1;
366   if (record_full_arch_list_add_reg (regcache, I386_ESI_REGNUM))
367     return -1;
368   if (record_full_arch_list_add_reg (regcache, I386_EDI_REGNUM))
369     return -1;
370   if (record_full_arch_list_add_reg (regcache, I386_EFLAGS_REGNUM))
371     return -1;
372
373   return 0;
374 }
375
376 /* i386_canonicalize_syscall maps from the native i386 Linux set
377    of syscall ids into a canonical set of syscall ids used by
378    process record (a mostly trivial mapping, since the canonical
379    set was originally taken from the i386 set).  */
380
381 static enum gdb_syscall
382 i386_canonicalize_syscall (int syscall)
383 {
384   enum { i386_syscall_max = 499 };
385
386   if (syscall <= i386_syscall_max)
387     return (enum gdb_syscall) syscall;
388   else
389     return gdb_sys_no_syscall;
390 }
391
392 /* Value of the sigcode in case of a boundary fault.  */
393
394 #define SIG_CODE_BONDARY_FAULT 3
395
396 /* i386 GNU/Linux implementation of the handle_segmentation_fault
397    gdbarch hook.  Displays information related to MPX bound
398    violations.  */
399 void
400 i386_linux_handle_segmentation_fault (struct gdbarch *gdbarch,
401                                       struct ui_out *uiout)
402 {
403   /* -Wmaybe-uninitialized  */
404   CORE_ADDR lower_bound = 0, upper_bound = 0, access = 0;
405   int is_upper;
406   long sig_code = 0;
407
408   if (!i386_mpx_enabled ())
409     return;
410
411   TRY
412     {
413       /* Sigcode evaluates if the actual segfault is a boundary violation.  */
414       sig_code = parse_and_eval_long ("$_siginfo.si_code\n");
415
416       lower_bound
417         = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._lower");
418       upper_bound
419         = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._upper");
420       access
421         = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
422     }
423   CATCH (exception, RETURN_MASK_ALL)
424     {
425       return;
426     }
427   END_CATCH
428
429   /* If this is not a boundary violation just return.  */
430   if (sig_code != SIG_CODE_BONDARY_FAULT)
431     return;
432
433   is_upper = (access > upper_bound ? 1 : 0);
434
435   uiout->text ("\n");
436   if (is_upper)
437     uiout->field_string ("sigcode-meaning", _("Upper bound violation"));
438   else
439     uiout->field_string ("sigcode-meaning", _("Lower bound violation"));
440
441   uiout->text (_(" while accessing address "));
442   uiout->field_fmt ("bound-access", "%s", paddress (gdbarch, access));
443
444   uiout->text (_("\nBounds: [lower = "));
445   uiout->field_fmt ("lower-bound", "%s", paddress (gdbarch, lower_bound));
446
447   uiout->text (_(", upper = "));
448   uiout->field_fmt ("upper-bound", "%s", paddress (gdbarch, upper_bound));
449
450   uiout->text (_("]"));
451 }
452
453 /* Parse the arguments of current system call instruction and record
454    the values of the registers and memory that will be changed into
455    "record_arch_list".  This instruction is "int 0x80" (Linux
456    Kernel2.4) or "sysenter" (Linux Kernel 2.6).
457
458    Return -1 if something wrong.  */
459
460 static struct linux_record_tdep i386_linux_record_tdep;
461
462 static int
463 i386_linux_intx80_sysenter_syscall_record (struct regcache *regcache)
464 {
465   int ret;
466   LONGEST syscall_native;
467   enum gdb_syscall syscall_gdb;
468
469   regcache_raw_read_signed (regcache, I386_EAX_REGNUM, &syscall_native);
470
471   syscall_gdb = i386_canonicalize_syscall (syscall_native);
472
473   if (syscall_gdb < 0)
474     {
475       printf_unfiltered (_("Process record and replay target doesn't "
476                            "support syscall number %s\n"), 
477                          plongest (syscall_native));
478       return -1;
479     }
480
481   if (syscall_gdb == gdb_sys_sigreturn
482       || syscall_gdb == gdb_sys_rt_sigreturn)
483    {
484      if (i386_all_but_ip_registers_record (regcache))
485        return -1;
486      return 0;
487    }
488
489   ret = record_linux_system_call (syscall_gdb, regcache,
490                                   &i386_linux_record_tdep);
491   if (ret)
492     return ret;
493
494   /* Record the return value of the system call.  */
495   if (record_full_arch_list_add_reg (regcache, I386_EAX_REGNUM))
496     return -1;
497
498   return 0;
499 }
500
501 #define I386_LINUX_xstate       270
502 #define I386_LINUX_frame_size   732
503
504 static int
505 i386_linux_record_signal (struct gdbarch *gdbarch,
506                           struct regcache *regcache,
507                           enum gdb_signal signal)
508 {
509   ULONGEST esp;
510
511   if (i386_all_but_ip_registers_record (regcache))
512     return -1;
513
514   if (record_full_arch_list_add_reg (regcache, I386_EIP_REGNUM))
515     return -1;
516
517   /* Record the change in the stack.  */
518   regcache_raw_read_unsigned (regcache, I386_ESP_REGNUM, &esp);
519   /* This is for xstate.
520      sp -= sizeof (struct _fpstate);  */
521   esp -= I386_LINUX_xstate;
522   /* This is for frame_size.
523      sp -= sizeof (struct rt_sigframe);  */
524   esp -= I386_LINUX_frame_size;
525   if (record_full_arch_list_add_mem (esp,
526                                      I386_LINUX_xstate + I386_LINUX_frame_size))
527     return -1;
528
529   if (record_full_arch_list_add_end ())
530     return -1;
531
532   return 0;
533 }
534 \f
535
536 /* Core of the implementation for gdbarch get_syscall_number.  Get pending
537    syscall number from REGCACHE.  If there is no pending syscall -1 will be
538    returned.  Pending syscall means ptrace has stepped into the syscall but
539    another ptrace call will step out.  PC is right after the int $0x80
540    / syscall / sysenter instruction in both cases, PC does not change during
541    the second ptrace step.  */
542
543 static LONGEST
544 i386_linux_get_syscall_number_from_regcache (struct regcache *regcache)
545 {
546   struct gdbarch *gdbarch = get_regcache_arch (regcache);
547   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
548   /* The content of a register.  */
549   gdb_byte buf[4];
550   /* The result.  */
551   LONGEST ret;
552
553   /* Getting the system call number from the register.
554      When dealing with x86 architecture, this information
555      is stored at %eax register.  */
556   regcache_cooked_read (regcache, I386_LINUX_ORIG_EAX_REGNUM, buf);
557
558   ret = extract_signed_integer (buf, 4, byte_order);
559
560   return ret;
561 }
562
563 /* Wrapper for i386_linux_get_syscall_number_from_regcache to make it
564    compatible with gdbarch get_syscall_number method prototype.  */
565
566 static LONGEST
567 i386_linux_get_syscall_number (struct gdbarch *gdbarch,
568                                ptid_t ptid)
569 {
570   struct regcache *regcache = get_thread_regcache (ptid);
571
572   return i386_linux_get_syscall_number_from_regcache (regcache);
573 }
574
575 /* The register sets used in GNU/Linux ELF core-dumps are identical to
576    the register sets in `struct user' that are used for a.out
577    core-dumps.  These are also used by ptrace(2).  The corresponding
578    types are `elf_gregset_t' for the general-purpose registers (with
579    `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
580    for the floating-point registers.
581
582    Those types used to be available under the names `gregset_t' and
583    `fpregset_t' too, and GDB used those names in the past.  But those
584    names are now used for the register sets used in the `mcontext_t'
585    type, which have a different size and layout.  */
586
587 /* Mapping between the general-purpose registers in `struct user'
588    format and GDB's register cache layout.  */
589
590 /* From <sys/reg.h>.  */
591 int i386_linux_gregset_reg_offset[] =
592 {
593   6 * 4,                        /* %eax */
594   1 * 4,                        /* %ecx */
595   2 * 4,                        /* %edx */
596   0 * 4,                        /* %ebx */
597   15 * 4,                       /* %esp */
598   5 * 4,                        /* %ebp */
599   3 * 4,                        /* %esi */
600   4 * 4,                        /* %edi */
601   12 * 4,                       /* %eip */
602   14 * 4,                       /* %eflags */
603   13 * 4,                       /* %cs */
604   16 * 4,                       /* %ss */
605   7 * 4,                        /* %ds */
606   8 * 4,                        /* %es */
607   9 * 4,                        /* %fs */
608   10 * 4,                       /* %gs */
609   -1, -1, -1, -1, -1, -1, -1, -1,
610   -1, -1, -1, -1, -1, -1, -1, -1,
611   -1, -1, -1, -1, -1, -1, -1, -1,
612   -1,
613   -1, -1, -1, -1, -1, -1, -1, -1,
614   -1, -1, -1, -1,                 /* MPX registers BND0 ... BND3.  */
615   -1, -1,                         /* MPX registers BNDCFGU, BNDSTATUS.  */
616   -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512)  */
617   -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm7 (AVX512)  */
618   -1,                             /* PKRU register  */
619   11 * 4,                         /* "orig_eax"  */
620 };
621
622 /* Mapping between the general-purpose registers in `struct
623    sigcontext' format and GDB's register cache layout.  */
624
625 /* From <asm/sigcontext.h>.  */
626 static int i386_linux_sc_reg_offset[] =
627 {
628   11 * 4,                       /* %eax */
629   10 * 4,                       /* %ecx */
630   9 * 4,                        /* %edx */
631   8 * 4,                        /* %ebx */
632   7 * 4,                        /* %esp */
633   6 * 4,                        /* %ebp */
634   5 * 4,                        /* %esi */
635   4 * 4,                        /* %edi */
636   14 * 4,                       /* %eip */
637   16 * 4,                       /* %eflags */
638   15 * 4,                       /* %cs */
639   18 * 4,                       /* %ss */
640   3 * 4,                        /* %ds */
641   2 * 4,                        /* %es */
642   1 * 4,                        /* %fs */
643   0 * 4                         /* %gs */
644 };
645
646 /* Get XSAVE extended state xcr0 from core dump.  */
647
648 uint64_t
649 i386_linux_core_read_xcr0 (bfd *abfd)
650 {
651   asection *xstate = bfd_get_section_by_name (abfd, ".reg-xstate");
652   uint64_t xcr0;
653
654   if (xstate)
655     {
656       size_t size = bfd_section_size (abfd, xstate);
657
658       /* Check extended state size.  */
659       if (size < X86_XSTATE_AVX_SIZE)
660         xcr0 = X86_XSTATE_SSE_MASK;
661       else
662         {
663           char contents[8];
664
665           if (! bfd_get_section_contents (abfd, xstate, contents,
666                                           I386_LINUX_XSAVE_XCR0_OFFSET,
667                                           8))
668             {
669               warning (_("Couldn't read `xcr0' bytes from "
670                          "`.reg-xstate' section in core file."));
671               return 0;
672             }
673
674           xcr0 = bfd_get_64 (abfd, contents);
675         }
676     }
677   else
678     xcr0 = 0;
679
680   return xcr0;
681 }
682
683 /* See i386-linux-tdep.h.  */
684
685 const struct target_desc *
686 i386_linux_read_description (uint64_t xcr0)
687 {
688   if (xcr0 == 0)
689     return NULL;
690
691   static struct target_desc *i386_linux_tdescs \
692     [2/*X87*/][2/*SSE*/][2/*AVX*/][2/*MPX*/][2/*AVX512*/][2/*PKRU*/] = {};
693   struct target_desc **tdesc;
694
695   tdesc = &i386_linux_tdescs[(xcr0 & X86_XSTATE_X87) ? 1 : 0]
696     [(xcr0 & X86_XSTATE_SSE) ? 1 : 0]
697     [(xcr0 & X86_XSTATE_AVX) ? 1 : 0]
698     [(xcr0 & X86_XSTATE_MPX) ? 1 : 0]
699     [(xcr0 & X86_XSTATE_AVX512) ? 1 : 0]
700     [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0];
701
702   if (*tdesc == NULL)
703     {
704       *tdesc = allocate_target_description ();
705       set_tdesc_architecture (*tdesc, bfd_scan_arch ("i386"));
706       set_tdesc_osabi (*tdesc, osabi_from_tdesc_string ("GNU/Linux"));
707
708       long regnum = 0;
709
710       if (xcr0 & X86_XSTATE_X87)
711         regnum = create_feature_i386_32bit_core (*tdesc, regnum);
712
713       if (xcr0 & X86_XSTATE_SSE)
714         regnum = create_feature_i386_32bit_sse (*tdesc, regnum);
715
716       regnum = create_feature_i386_32bit_linux (*tdesc, regnum);
717
718       if (xcr0 & X86_XSTATE_AVX)
719         regnum = create_feature_i386_32bit_avx (*tdesc, regnum);
720
721       if (xcr0 & X86_XSTATE_MPX)
722         regnum = create_feature_i386_32bit_mpx (*tdesc, regnum);
723
724       if (xcr0 & X86_XSTATE_AVX512)
725         regnum = create_feature_i386_32bit_avx512 (*tdesc, regnum);
726
727       if (xcr0 & X86_XSTATE_PKRU)
728         regnum = create_feature_i386_32bit_pkeys (*tdesc, regnum);
729     }
730
731   return *tdesc;
732 }
733
734 /* Get Linux/x86 target description from core dump.  */
735
736 static const struct target_desc *
737 i386_linux_core_read_description (struct gdbarch *gdbarch,
738                                   struct target_ops *target,
739                                   bfd *abfd)
740 {
741   /* Linux/i386.  */
742   uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
743   const struct target_desc *tdesc = i386_linux_read_description (xcr0);
744
745   if (tdesc != NULL)
746     return tdesc;
747
748   if (bfd_get_section_by_name (abfd, ".reg-xfp") != NULL)
749     return i386_linux_read_description (X86_XSTATE_SSE_MASK);
750   else
751     return i386_linux_read_description (X86_XSTATE_X87_MASK);
752 }
753
754 /* Similar to i386_supply_fpregset, but use XSAVE extended state.  */
755
756 static void
757 i386_linux_supply_xstateregset (const struct regset *regset,
758                                 struct regcache *regcache, int regnum,
759                                 const void *xstateregs, size_t len)
760 {
761   i387_supply_xsave (regcache, regnum, xstateregs);
762 }
763
764 struct type *
765 x86_linux_get_siginfo_type (struct gdbarch *gdbarch)
766 {
767   return linux_get_siginfo_type_with_fields (gdbarch, LINUX_SIGINFO_FIELD_ADDR_BND);
768 }
769
770 /* Similar to i386_collect_fpregset, but use XSAVE extended state.  */
771
772 static void
773 i386_linux_collect_xstateregset (const struct regset *regset,
774                                  const struct regcache *regcache,
775                                  int regnum, void *xstateregs, size_t len)
776 {
777   i387_collect_xsave (regcache, regnum, xstateregs, 1);
778 }
779
780 /* Register set definitions.  */
781
782 static const struct regset i386_linux_xstateregset =
783   {
784     NULL,
785     i386_linux_supply_xstateregset,
786     i386_linux_collect_xstateregset
787   };
788
789 /* Iterate over core file register note sections.  */
790
791 static void
792 i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
793                                          iterate_over_regset_sections_cb *cb,
794                                          void *cb_data,
795                                          const struct regcache *regcache)
796 {
797   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
798
799   cb (".reg", 68, &i386_gregset, NULL, cb_data);
800
801   if (tdep->xcr0 & X86_XSTATE_AVX)
802     cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0),
803         &i386_linux_xstateregset, "XSAVE extended state", cb_data);
804   else if (tdep->xcr0 & X86_XSTATE_SSE)
805     cb (".reg-xfp", 512, &i386_fpregset, "extended floating-point",
806         cb_data);
807   else
808     cb (".reg2", 108, &i386_fpregset, NULL, cb_data);
809 }
810
811 /* Linux kernel shows PC value after the 'int $0x80' instruction even if
812    inferior is still inside the syscall.  On next PTRACE_SINGLESTEP it will
813    finish the syscall but PC will not change.
814    
815    Some vDSOs contain 'int $0x80; ret' and during stepping out of the syscall
816    i386_displaced_step_fixup would keep PC at the displaced pad location.
817    As PC is pointing to the 'ret' instruction before the step
818    i386_displaced_step_fixup would expect inferior has just executed that 'ret'
819    and PC should not be adjusted.  In reality it finished syscall instead and
820    PC should get relocated back to its vDSO address.  Hide the 'ret'
821    instruction by 'nop' so that i386_displaced_step_fixup is not confused.
822    
823    It is not fully correct as the bytes in struct displaced_step_closure will
824    not match the inferior code.  But we would need some new flag in
825    displaced_step_closure otherwise to keep the state that syscall is finishing
826    for the later i386_displaced_step_fixup execution as the syscall execution
827    is already no longer detectable there.  The new flag field would mean
828    i386-linux-tdep.c needs to wrap all the displacement methods of i386-tdep.c
829    which does not seem worth it.  The same effect is achieved by patching that
830    'nop' instruction there instead.  */
831
832 static struct displaced_step_closure *
833 i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
834                                      CORE_ADDR from, CORE_ADDR to,
835                                      struct regcache *regs)
836 {
837   struct displaced_step_closure *closure;
838   
839   closure = i386_displaced_step_copy_insn (gdbarch, from, to, regs);
840
841   if (i386_linux_get_syscall_number_from_regcache (regs) != -1)
842     {
843       /* Since we use simple_displaced_step_copy_insn, our closure is a
844          copy of the instruction.  */
845       gdb_byte *insn = (gdb_byte *) closure;
846
847       /* Fake nop.  */
848       insn[0] = 0x90;
849     }
850
851   return closure;
852 }
853
854 static void
855 i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
856 {
857   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
858   const struct target_desc *tdesc = info.target_desc;
859   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
860   const struct tdesc_feature *feature;
861   int valid_p;
862
863   gdb_assert (tdesc_data);
864
865   linux_init_abi (info, gdbarch);
866
867   /* GNU/Linux uses ELF.  */
868   i386_elf_init_abi (info, gdbarch);
869
870   /* Reserve a number for orig_eax.  */
871   set_gdbarch_num_regs (gdbarch, I386_LINUX_NUM_REGS);
872
873   if (! tdesc_has_registers (tdesc))
874     tdesc = i386_linux_read_description (X86_XSTATE_SSE_MASK);
875   tdep->tdesc = tdesc;
876
877   feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
878   if (feature == NULL)
879     return;
880
881   valid_p = tdesc_numbered_register (feature, tdesc_data,
882                                      I386_LINUX_ORIG_EAX_REGNUM,
883                                      "orig_eax");
884   if (!valid_p)
885     return;
886
887   /* Add the %orig_eax register used for syscall restarting.  */
888   set_gdbarch_write_pc (gdbarch, i386_linux_write_pc);
889
890   tdep->register_reggroup_p = i386_linux_register_reggroup_p;
891
892   tdep->gregset_reg_offset = i386_linux_gregset_reg_offset;
893   tdep->gregset_num_regs = ARRAY_SIZE (i386_linux_gregset_reg_offset);
894   tdep->sizeof_gregset = 17 * 4;
895
896   tdep->jb_pc_offset = 20;      /* From <bits/setjmp.h>.  */
897
898   tdep->sigtramp_p = i386_linux_sigtramp_p;
899   tdep->sigcontext_addr = i386_linux_sigcontext_addr;
900   tdep->sc_reg_offset = i386_linux_sc_reg_offset;
901   tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset);
902
903   tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET;
904
905   set_gdbarch_process_record (gdbarch, i386_process_record);
906   set_gdbarch_process_record_signal (gdbarch, i386_linux_record_signal);
907
908   /* Initialize the i386_linux_record_tdep.  */
909   /* These values are the size of the type that will be used in a system
910      call.  They are obtained from Linux Kernel source.  */
911   i386_linux_record_tdep.size_pointer
912     = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
913   i386_linux_record_tdep.size__old_kernel_stat = 32;
914   i386_linux_record_tdep.size_tms = 16;
915   i386_linux_record_tdep.size_loff_t = 8;
916   i386_linux_record_tdep.size_flock = 16;
917   i386_linux_record_tdep.size_oldold_utsname = 45;
918   i386_linux_record_tdep.size_ustat = 20;
919   i386_linux_record_tdep.size_old_sigaction = 16;
920   i386_linux_record_tdep.size_old_sigset_t = 4;
921   i386_linux_record_tdep.size_rlimit = 8;
922   i386_linux_record_tdep.size_rusage = 72;
923   i386_linux_record_tdep.size_timeval = 8;
924   i386_linux_record_tdep.size_timezone = 8;
925   i386_linux_record_tdep.size_old_gid_t = 2;
926   i386_linux_record_tdep.size_old_uid_t = 2;
927   i386_linux_record_tdep.size_fd_set = 128;
928   i386_linux_record_tdep.size_old_dirent = 268;
929   i386_linux_record_tdep.size_statfs = 64;
930   i386_linux_record_tdep.size_statfs64 = 84;
931   i386_linux_record_tdep.size_sockaddr = 16;
932   i386_linux_record_tdep.size_int
933     = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
934   i386_linux_record_tdep.size_long
935     = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
936   i386_linux_record_tdep.size_ulong
937     = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
938   i386_linux_record_tdep.size_msghdr = 28;
939   i386_linux_record_tdep.size_itimerval = 16;
940   i386_linux_record_tdep.size_stat = 88;
941   i386_linux_record_tdep.size_old_utsname = 325;
942   i386_linux_record_tdep.size_sysinfo = 64;
943   i386_linux_record_tdep.size_msqid_ds = 88;
944   i386_linux_record_tdep.size_shmid_ds = 84;
945   i386_linux_record_tdep.size_new_utsname = 390;
946   i386_linux_record_tdep.size_timex = 128;
947   i386_linux_record_tdep.size_mem_dqinfo = 24;
948   i386_linux_record_tdep.size_if_dqblk = 68;
949   i386_linux_record_tdep.size_fs_quota_stat = 68;
950   i386_linux_record_tdep.size_timespec = 8;
951   i386_linux_record_tdep.size_pollfd = 8;
952   i386_linux_record_tdep.size_NFS_FHSIZE = 32;
953   i386_linux_record_tdep.size_knfsd_fh = 132;
954   i386_linux_record_tdep.size_TASK_COMM_LEN = 16;
955   i386_linux_record_tdep.size_sigaction = 20;
956   i386_linux_record_tdep.size_sigset_t = 8;
957   i386_linux_record_tdep.size_siginfo_t = 128;
958   i386_linux_record_tdep.size_cap_user_data_t = 12;
959   i386_linux_record_tdep.size_stack_t = 12;
960   i386_linux_record_tdep.size_off_t = i386_linux_record_tdep.size_long;
961   i386_linux_record_tdep.size_stat64 = 96;
962   i386_linux_record_tdep.size_gid_t = 4;
963   i386_linux_record_tdep.size_uid_t = 4;
964   i386_linux_record_tdep.size_PAGE_SIZE = 4096;
965   i386_linux_record_tdep.size_flock64 = 24;
966   i386_linux_record_tdep.size_user_desc = 16;
967   i386_linux_record_tdep.size_io_event = 32;
968   i386_linux_record_tdep.size_iocb = 64;
969   i386_linux_record_tdep.size_epoll_event = 12;
970   i386_linux_record_tdep.size_itimerspec
971     = i386_linux_record_tdep.size_timespec * 2;
972   i386_linux_record_tdep.size_mq_attr = 32;
973   i386_linux_record_tdep.size_termios = 36;
974   i386_linux_record_tdep.size_termios2 = 44;
975   i386_linux_record_tdep.size_pid_t = 4;
976   i386_linux_record_tdep.size_winsize = 8;
977   i386_linux_record_tdep.size_serial_struct = 60;
978   i386_linux_record_tdep.size_serial_icounter_struct = 80;
979   i386_linux_record_tdep.size_hayes_esp_config = 12;
980   i386_linux_record_tdep.size_size_t = 4;
981   i386_linux_record_tdep.size_iovec = 8;
982   i386_linux_record_tdep.size_time_t = 4;
983
984   /* These values are the second argument of system call "sys_ioctl".
985      They are obtained from Linux Kernel source.  */
986   i386_linux_record_tdep.ioctl_TCGETS = 0x5401;
987   i386_linux_record_tdep.ioctl_TCSETS = 0x5402;
988   i386_linux_record_tdep.ioctl_TCSETSW = 0x5403;
989   i386_linux_record_tdep.ioctl_TCSETSF = 0x5404;
990   i386_linux_record_tdep.ioctl_TCGETA = 0x5405;
991   i386_linux_record_tdep.ioctl_TCSETA = 0x5406;
992   i386_linux_record_tdep.ioctl_TCSETAW = 0x5407;
993   i386_linux_record_tdep.ioctl_TCSETAF = 0x5408;
994   i386_linux_record_tdep.ioctl_TCSBRK = 0x5409;
995   i386_linux_record_tdep.ioctl_TCXONC = 0x540A;
996   i386_linux_record_tdep.ioctl_TCFLSH = 0x540B;
997   i386_linux_record_tdep.ioctl_TIOCEXCL = 0x540C;
998   i386_linux_record_tdep.ioctl_TIOCNXCL = 0x540D;
999   i386_linux_record_tdep.ioctl_TIOCSCTTY = 0x540E;
1000   i386_linux_record_tdep.ioctl_TIOCGPGRP = 0x540F;
1001   i386_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
1002   i386_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
1003   i386_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
1004   i386_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
1005   i386_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
1006   i386_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
1007   i386_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
1008   i386_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
1009   i386_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
1010   i386_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
1011   i386_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541A;
1012   i386_linux_record_tdep.ioctl_FIONREAD = 0x541B;
1013   i386_linux_record_tdep.ioctl_TIOCINQ = i386_linux_record_tdep.ioctl_FIONREAD;
1014   i386_linux_record_tdep.ioctl_TIOCLINUX = 0x541C;
1015   i386_linux_record_tdep.ioctl_TIOCCONS = 0x541D;
1016   i386_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541E;
1017   i386_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541F;
1018   i386_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
1019   i386_linux_record_tdep.ioctl_FIONBIO = 0x5421;
1020   i386_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
1021   i386_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
1022   i386_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
1023   i386_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
1024   i386_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
1025   i386_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
1026   i386_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
1027   i386_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
1028   i386_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
1029   i386_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
1030   i386_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
1031   i386_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
1032   i386_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
1033   i386_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
1034   i386_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
1035   i386_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
1036   i386_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
1037   i386_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
1038   i386_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
1039   i386_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
1040   i386_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
1041   i386_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
1042   i386_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
1043   i386_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
1044   i386_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545A;
1045   i386_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545B;
1046   i386_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545C;
1047   i386_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545D;
1048   i386_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545E;
1049   i386_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545F;
1050   i386_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;
1051
1052   /* These values are the second argument of system call "sys_fcntl"
1053      and "sys_fcntl64".  They are obtained from Linux Kernel source.  */
1054   i386_linux_record_tdep.fcntl_F_GETLK = 5;
1055   i386_linux_record_tdep.fcntl_F_GETLK64 = 12;
1056   i386_linux_record_tdep.fcntl_F_SETLK64 = 13;
1057   i386_linux_record_tdep.fcntl_F_SETLKW64 = 14;
1058
1059   i386_linux_record_tdep.arg1 = I386_EBX_REGNUM;
1060   i386_linux_record_tdep.arg2 = I386_ECX_REGNUM;
1061   i386_linux_record_tdep.arg3 = I386_EDX_REGNUM;
1062   i386_linux_record_tdep.arg4 = I386_ESI_REGNUM;
1063   i386_linux_record_tdep.arg5 = I386_EDI_REGNUM;
1064   i386_linux_record_tdep.arg6 = I386_EBP_REGNUM;
1065
1066   tdep->i386_intx80_record = i386_linux_intx80_sysenter_syscall_record;
1067   tdep->i386_sysenter_record = i386_linux_intx80_sysenter_syscall_record;
1068   tdep->i386_syscall_record = i386_linux_intx80_sysenter_syscall_record;
1069
1070   /* N_FUN symbols in shared libaries have 0 for their values and need
1071      to be relocated.  */
1072   set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
1073
1074   /* GNU/Linux uses SVR4-style shared libraries.  */
1075   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
1076   set_solib_svr4_fetch_link_map_offsets
1077     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1078
1079   /* GNU/Linux uses the dynamic linker included in the GNU C Library.  */
1080   set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
1081
1082   dwarf2_frame_set_signal_frame_p (gdbarch, i386_linux_dwarf_signal_frame_p);
1083
1084   /* Enable TLS support.  */
1085   set_gdbarch_fetch_tls_load_module_address (gdbarch,
1086                                              svr4_fetch_objfile_link_map);
1087
1088   /* Core file support.  */
1089   set_gdbarch_iterate_over_regset_sections
1090     (gdbarch, i386_linux_iterate_over_regset_sections);
1091   set_gdbarch_core_read_description (gdbarch,
1092                                      i386_linux_core_read_description);
1093
1094   /* Displaced stepping.  */
1095   set_gdbarch_displaced_step_copy_insn (gdbarch,
1096                                         i386_linux_displaced_step_copy_insn);
1097   set_gdbarch_displaced_step_fixup (gdbarch, i386_displaced_step_fixup);
1098   set_gdbarch_displaced_step_location (gdbarch,
1099                                        linux_displaced_step_location);
1100
1101   /* Functions for 'catch syscall'.  */
1102   set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_I386);
1103   set_gdbarch_get_syscall_number (gdbarch,
1104                                   i386_linux_get_syscall_number);
1105
1106   set_gdbarch_get_siginfo_type (gdbarch, x86_linux_get_siginfo_type);
1107   set_gdbarch_handle_segmentation_fault (gdbarch,
1108                                          i386_linux_handle_segmentation_fault);
1109 }
1110
1111 /* Provide a prototype to silence -Wmissing-prototypes.  */
1112 extern void _initialize_i386_linux_tdep (void);
1113
1114 void
1115 _initialize_i386_linux_tdep (void)
1116 {
1117   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LINUX,
1118                           i386_linux_init_abi);
1119
1120 #if GDB_SELF_TEST
1121   struct
1122   {
1123     const char *xml;
1124     uint64_t mask;
1125   } xml_masks[] = {
1126     { "i386/i386-linux.xml", X86_XSTATE_SSE_MASK },
1127     { "i386/i386-mmx-linux.xml", X86_XSTATE_X87_MASK },
1128     { "i386/i386-avx-linux.xml", X86_XSTATE_AVX_MASK },
1129     { "i386/i386-mpx-linux.xml", X86_XSTATE_MPX_MASK },
1130     { "i386/i386-avx-mpx-linux.xml", X86_XSTATE_AVX_MPX_MASK },
1131     { "i386/i386-avx-avx512-linux.xml", X86_XSTATE_AVX_AVX512_MASK },
1132     { "i386/i386-avx-mpx-avx512-pku-linux.xml",
1133       X86_XSTATE_AVX_MPX_AVX512_PKU_MASK },
1134   };
1135
1136   for (auto &a : xml_masks)
1137     {
1138       auto tdesc = i386_linux_read_description (a.mask);
1139
1140       selftests::record_xml_tdesc (a.xml, tdesc);
1141     }
1142 #endif /* GDB_SELF_TEST */
1143 }