GDB (xrefs)
/tmp/gdb-8.1/gdb/i386-linux-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for GNU/Linux i386.
2 
3  Copyright (C) 2000-2018 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 "arch/i386.h"
50 #include "target-descriptions.h"
51 
52 /* Return non-zero, when the register is in the corresponding register
53  group. Put the LINUX_ORIG_EAX register in the system group. */
54 static int
56  struct reggroup *group)
57 {
59  return (group == system_reggroup
60  || group == save_reggroup
61  || group == restore_reggroup);
62  return i386_register_reggroup_p (gdbarch, regnum, group);
63 }
64 
65 
66 /* Recognizing signal handler frames. */
67 
68 /* GNU/Linux has two flavors of signals. Normal signal handlers, and
69  "realtime" (RT) signals. The RT signals can provide additional
70  information to the signal handler if the SA_SIGINFO flag is set
71  when establishing a signal handler using `sigaction'. It is not
72  unlikely that future versions of GNU/Linux will support SA_SIGINFO
73  for normal signals too. */
74 
75 /* When the i386 Linux kernel calls a signal handler and the
76  SA_RESTORER flag isn't set, the return address points to a bit of
77  code on the stack. This function returns whether the PC appears to
78  be within this bit of code.
79 
80  The instruction sequence for normal signals is
81  pop %eax
82  mov $0x77, %eax
83  int $0x80
84  or 0x58 0xb8 0x77 0x00 0x00 0x00 0xcd 0x80.
85 
86  Checking for the code sequence should be somewhat reliable, because
87  the effect is to call the system call sigreturn. This is unlikely
88  to occur anywhere other than in a signal trampoline.
89 
90  It kind of sucks that we have to read memory from the process in
91  order to identify a signal trampoline, but there doesn't seem to be
92  any other way. Therefore we only do the memory reads if no
93  function name could be identified, which should be the case since
94  the code is on the stack.
95 
96  Detection of signal trampolines for handlers that set the
97  SA_RESTORER flag is in general not possible. Unfortunately this is
98  what the GNU C Library has been doing for quite some time now.
99  However, as of version 2.1.2, the GNU C Library uses signal
100  trampolines (named __restore and __restore_rt) that are identical
101  to the ones used by the kernel. Therefore, these trampolines are
102  supported too. */
103 
104 #define LINUX_SIGTRAMP_INSN0 0x58 /* pop %eax */
105 #define LINUX_SIGTRAMP_OFFSET0 0
106 #define LINUX_SIGTRAMP_INSN1 0xb8 /* mov $NNNN, %eax */
107 #define LINUX_SIGTRAMP_OFFSET1 1
108 #define LINUX_SIGTRAMP_INSN2 0xcd /* int */
109 #define LINUX_SIGTRAMP_OFFSET2 6
110 
112 {
113  LINUX_SIGTRAMP_INSN0, /* pop %eax */
114  LINUX_SIGTRAMP_INSN1, 0x77, 0x00, 0x00, 0x00, /* mov $0x77, %eax */
115  LINUX_SIGTRAMP_INSN2, 0x80 /* int $0x80 */
116 };
117 
118 #define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
119 
120 /* If THIS_FRAME is a sigtramp routine, return the address of the
121  start of the routine. Otherwise, return 0. */
122 
123 static CORE_ADDR
125 {
126  CORE_ADDR pc = get_frame_pc (this_frame);
128 
129  /* We only recognize a signal trampoline if PC is at the start of
130  one of the three instructions. We optimize for finding the PC at
131  the start, as will be the case when the trampoline is not the
132  first frame on the stack. We assume that in the case where the
133  PC is not at the start of the instruction sequence, there will be
134  a few trailing readable bytes on the stack. */
135 
136  if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
137  return 0;
138 
139  if (buf[0] != LINUX_SIGTRAMP_INSN0)
140  {
141  int adjust;
142 
143  switch (buf[0])
144  {
146  adjust = LINUX_SIGTRAMP_OFFSET1;
147  break;
149  adjust = LINUX_SIGTRAMP_OFFSET2;
150  break;
151  default:
152  return 0;
153  }
154 
155  pc -= adjust;
156 
157  if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
158  return 0;
159  }
160 
161  if (memcmp (buf, linux_sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
162  return 0;
163 
164  return pc;
165 }
166 
167 /* This function does the same for RT signals. Here the instruction
168  sequence is
169  mov $0xad, %eax
170  int $0x80
171  or 0xb8 0xad 0x00 0x00 0x00 0xcd 0x80.
172 
173  The effect is to call the system call rt_sigreturn. */
174 
175 #define LINUX_RT_SIGTRAMP_INSN0 0xb8 /* mov $NNNN, %eax */
176 #define LINUX_RT_SIGTRAMP_OFFSET0 0
177 #define LINUX_RT_SIGTRAMP_INSN1 0xcd /* int */
178 #define LINUX_RT_SIGTRAMP_OFFSET1 5
179 
181 {
182  LINUX_RT_SIGTRAMP_INSN0, 0xad, 0x00, 0x00, 0x00, /* mov $0xad, %eax */
183  LINUX_RT_SIGTRAMP_INSN1, 0x80 /* int $0x80 */
184 };
185 
186 #define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code)
187 
188 /* If THIS_FRAME is an RT sigtramp routine, return the address of the
189  start of the routine. Otherwise, return 0. */
190 
191 static CORE_ADDR
193 {
194  CORE_ADDR pc = get_frame_pc (this_frame);
196 
197  /* We only recognize a signal trampoline if PC is at the start of
198  one of the two instructions. We optimize for finding the PC at
199  the start, as will be the case when the trampoline is not the
200  first frame on the stack. We assume that in the case where the
201  PC is not at the start of the instruction sequence, there will be
202  a few trailing readable bytes on the stack. */
203 
204  if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_RT_SIGTRAMP_LEN))
205  return 0;
206 
207  if (buf[0] != LINUX_RT_SIGTRAMP_INSN0)
208  {
209  if (buf[0] != LINUX_RT_SIGTRAMP_INSN1)
210  return 0;
211 
213 
214  if (!safe_frame_unwind_memory (this_frame, pc, buf,
216  return 0;
217  }
218 
219  if (memcmp (buf, linux_rt_sigtramp_code, LINUX_RT_SIGTRAMP_LEN) != 0)
220  return 0;
221 
222  return pc;
223 }
224 
225 /* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
226  routine. */
227 
228 static int
229 i386_linux_sigtramp_p (struct frame_info *this_frame)
230 {
231  CORE_ADDR pc = get_frame_pc (this_frame);
232  const char *name;
233 
234  find_pc_partial_function (pc, &name, NULL, NULL);
235 
236  /* If we have NAME, we can optimize the search. The trampolines are
237  named __restore and __restore_rt. However, they aren't dynamically
238  exported from the shared C library, so the trampoline may appear to
239  be part of the preceding function. This should always be sigaction,
240  __sigaction, or __libc_sigaction (all aliases to the same function). */
241  if (name == NULL || strstr (name, "sigaction") != NULL)
242  return (i386_linux_sigtramp_start (this_frame) != 0
243  || i386_linux_rt_sigtramp_start (this_frame) != 0);
244 
245  return (strcmp ("__restore", name) == 0
246  || strcmp ("__restore_rt", name) == 0);
247 }
248 
249 /* Return one if the PC of THIS_FRAME is in a signal trampoline which
250  may have DWARF-2 CFI. */
251 
252 static int
254  struct frame_info *this_frame)
255 {
256  CORE_ADDR pc = get_frame_pc (this_frame);
257  const char *name;
258 
259  find_pc_partial_function (pc, &name, NULL, NULL);
260 
261  /* If a vsyscall DSO is in use, the signal trampolines may have these
262  names. */
263  if (name && (strcmp (name, "__kernel_sigreturn") == 0
264  || strcmp (name, "__kernel_rt_sigreturn") == 0))
265  return 1;
266 
267  return 0;
268 }
269 
270 /* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
271 #define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 20
272 
273 /* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
274  address of the associated sigcontext structure. */
275 
276 static CORE_ADDR
278 {
279  struct gdbarch *gdbarch = get_frame_arch (this_frame);
280  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
281  CORE_ADDR pc;
282  CORE_ADDR sp;
283  gdb_byte buf[4];
284 
285  get_frame_register (this_frame, I386_ESP_REGNUM, buf);
286  sp = extract_unsigned_integer (buf, 4, byte_order);
287 
288  pc = i386_linux_sigtramp_start (this_frame);
289  if (pc)
290  {
291  /* The sigcontext structure lives on the stack, right after
292  the signum argument. We determine the address of the
293  sigcontext structure by looking at the frame's stack
294  pointer. Keep in mind that the first instruction of the
295  sigtramp code is "pop %eax". If the PC is after this
296  instruction, adjust the returned value accordingly. */
297  if (pc == get_frame_pc (this_frame))
298  return sp + 4;
299  return sp;
300  }
301 
302  pc = i386_linux_rt_sigtramp_start (this_frame);
303  if (pc)
304  {
305  CORE_ADDR ucontext_addr;
306 
307  /* The sigcontext structure is part of the user context. A
308  pointer to the user context is passed as the third argument
309  to the signal handler. */
310  read_memory (sp + 8, buf, 4);
311  ucontext_addr = extract_unsigned_integer (buf, 4, byte_order);
312  return ucontext_addr + I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET;
313  }
314 
315  error (_("Couldn't recognize signal trampoline."));
316  return 0;
317 }
318 
319 /* Set the program counter for process PTID to PC. */
320 
321 static void
323 {
325 
326  /* We must be careful with modifying the program counter. If we
327  just interrupted a system call, the kernel might try to restart
328  it when we resume the inferior. On restarting the system call,
329  the kernel will try backing up the program counter even though it
330  no longer points at the system call. This typically results in a
331  SIGSEGV or SIGILL. We can prevent this by writing `-1' in the
332  "orig_eax" pseudo-register.
333 
334  Note that "orig_eax" is saved when setting up a dummy call frame.
335  This means that it is properly restored when that frame is
336  popped, and that the interrupted system call will be restarted
337  when we resume the inferior on return from a function call from
338  within GDB. In all other cases the system call will not be
339  restarted. */
341 }
342 
343 /* Record all registers but IP register for process-record. */
344 
345 static int
347 {
349  return -1;
351  return -1;
353  return -1;
355  return -1;
357  return -1;
359  return -1;
361  return -1;
363  return -1;
365  return -1;
366 
367  return 0;
368 }
369 
370 /* i386_canonicalize_syscall maps from the native i386 Linux set
371  of syscall ids into a canonical set of syscall ids used by
372  process record (a mostly trivial mapping, since the canonical
373  set was originally taken from the i386 set). */
374 
375 static enum gdb_syscall
377 {
378  enum { i386_syscall_max = 499 };
379 
380  if (syscall <= i386_syscall_max)
381  return (enum gdb_syscall) syscall;
382  else
383  return gdb_sys_no_syscall;
384 }
385 
386 /* Value of the sigcode in case of a boundary fault. */
387 
388 #define SIG_CODE_BONDARY_FAULT 3
389 
390 /* i386 GNU/Linux implementation of the handle_segmentation_fault
391  gdbarch hook. Displays information related to MPX bound
392  violations. */
393 void
395  struct ui_out *uiout)
396 {
397  /* -Wmaybe-uninitialized */
398  CORE_ADDR lower_bound = 0, upper_bound = 0, access = 0;
399  int is_upper;
400  long sig_code = 0;
401 
402  if (!i386_mpx_enabled ())
403  return;
404 
405  TRY
406  {
407  /* Sigcode evaluates if the actual segfault is a boundary violation. */
408  sig_code = parse_and_eval_long ("$_siginfo.si_code\n");
409 
410  lower_bound
411  = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._lower");
412  upper_bound
413  = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._upper");
414  access
415  = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
416  }
417  CATCH (exception, RETURN_MASK_ALL)
418  {
419  return;
420  }
421  END_CATCH
422 
423  /* If this is not a boundary violation just return. */
424  if (sig_code != SIG_CODE_BONDARY_FAULT)
425  return;
426 
427  is_upper = (access > upper_bound ? 1 : 0);
428 
429  uiout->text ("\n");
430  if (is_upper)
431  uiout->field_string ("sigcode-meaning", _("Upper bound violation"));
432  else
433  uiout->field_string ("sigcode-meaning", _("Lower bound violation"));
434 
435  uiout->text (_(" while accessing address "));
436  uiout->field_fmt ("bound-access", "%s", paddress (gdbarch, access));
437 
438  uiout->text (_("\nBounds: [lower = "));
439  uiout->field_fmt ("lower-bound", "%s", paddress (gdbarch, lower_bound));
440 
441  uiout->text (_(", upper = "));
442  uiout->field_fmt ("upper-bound", "%s", paddress (gdbarch, upper_bound));
443 
444  uiout->text (_("]"));
445 }
446 
447 /* Parse the arguments of current system call instruction and record
448  the values of the registers and memory that will be changed into
449  "record_arch_list". This instruction is "int 0x80" (Linux
450  Kernel2.4) or "sysenter" (Linux Kernel 2.6).
451 
452  Return -1 if something wrong. */
453 
455 
456 static int
458 {
459  int ret;
460  LONGEST syscall_native;
461  enum gdb_syscall syscall_gdb;
462 
464 
465  syscall_gdb = i386_canonicalize_syscall (syscall_native);
466 
467  if (syscall_gdb < 0)
468  {
469  printf_unfiltered (_("Process record and replay target doesn't "
470  "support syscall number %s\n"),
471  plongest (syscall_native));
472  return -1;
473  }
474 
475  if (syscall_gdb == gdb_sys_sigreturn
476  || syscall_gdb == gdb_sys_rt_sigreturn)
477  {
479  return -1;
480  return 0;
481  }
482 
483  ret = record_linux_system_call (syscall_gdb, regcache,
485  if (ret)
486  return ret;
487 
488  /* Record the return value of the system call. */
490  return -1;
491 
492  return 0;
493 }
494 
495 #define I386_LINUX_xstate 270
496 #define I386_LINUX_frame_size 732
497 
498 static int
500  struct regcache *regcache,
501  enum gdb_signal signal)
502 {
503  ULONGEST esp;
504 
506  return -1;
507 
509  return -1;
510 
511  /* Record the change in the stack. */
513  /* This is for xstate.
514  sp -= sizeof (struct _fpstate); */
515  esp -= I386_LINUX_xstate;
516  /* This is for frame_size.
517  sp -= sizeof (struct rt_sigframe); */
518  esp -= I386_LINUX_frame_size;
521  return -1;
522 
524  return -1;
525 
526  return 0;
527 }
528 
529 
530 /* Core of the implementation for gdbarch get_syscall_number. Get pending
531  syscall number from REGCACHE. If there is no pending syscall -1 will be
532  returned. Pending syscall means ptrace has stepped into the syscall but
533  another ptrace call will step out. PC is right after the int $0x80
534  / syscall / sysenter instruction in both cases, PC does not change during
535  the second ptrace step. */
536 
537 static LONGEST
539 {
540  struct gdbarch *gdbarch = regcache->arch ();
541  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
542  /* The content of a register. */
543  gdb_byte buf[4];
544  /* The result. */
545  LONGEST ret;
546 
547  /* Getting the system call number from the register.
548  When dealing with x86 architecture, this information
549  is stored at %eax register. */
551 
552  ret = extract_signed_integer (buf, 4, byte_order);
553 
554  return ret;
555 }
556 
557 /* Wrapper for i386_linux_get_syscall_number_from_regcache to make it
558  compatible with gdbarch get_syscall_number method prototype. */
559 
560 static LONGEST
562  ptid_t ptid)
563 {
565 
567 }
568 
569 /* The register sets used in GNU/Linux ELF core-dumps are identical to
570  the register sets in `struct user' that are used for a.out
571  core-dumps. These are also used by ptrace(2). The corresponding
572  types are `elf_gregset_t' for the general-purpose registers (with
573  `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
574  for the floating-point registers.
575 
576  Those types used to be available under the names `gregset_t' and
577  `fpregset_t' too, and GDB used those names in the past. But those
578  names are now used for the register sets used in the `mcontext_t'
579  type, which have a different size and layout. */
580 
581 /* Mapping between the general-purpose registers in `struct user'
582  format and GDB's register cache layout. */
583 
584 /* From <sys/reg.h>. */
586 {
587  6 * 4, /* %eax */
588  1 * 4, /* %ecx */
589  2 * 4, /* %edx */
590  0 * 4, /* %ebx */
591  15 * 4, /* %esp */
592  5 * 4, /* %ebp */
593  3 * 4, /* %esi */
594  4 * 4, /* %edi */
595  12 * 4, /* %eip */
596  14 * 4, /* %eflags */
597  13 * 4, /* %cs */
598  16 * 4, /* %ss */
599  7 * 4, /* %ds */
600  8 * 4, /* %es */
601  9 * 4, /* %fs */
602  10 * 4, /* %gs */
603  -1, -1, -1, -1, -1, -1, -1, -1,
604  -1, -1, -1, -1, -1, -1, -1, -1,
605  -1, -1, -1, -1, -1, -1, -1, -1,
606  -1,
607  -1, -1, -1, -1, -1, -1, -1, -1,
608  -1, -1, -1, -1, /* MPX registers BND0 ... BND3. */
609  -1, -1, /* MPX registers BNDCFGU, BNDSTATUS. */
610  -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512) */
611  -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm7 (AVX512) */
612  -1, /* PKRU register */
613  11 * 4, /* "orig_eax" */
614 };
615 
616 /* Mapping between the general-purpose registers in `struct
617  sigcontext' format and GDB's register cache layout. */
618 
619 /* From <asm/sigcontext.h>. */
621 {
622  11 * 4, /* %eax */
623  10 * 4, /* %ecx */
624  9 * 4, /* %edx */
625  8 * 4, /* %ebx */
626  7 * 4, /* %esp */
627  6 * 4, /* %ebp */
628  5 * 4, /* %esi */
629  4 * 4, /* %edi */
630  14 * 4, /* %eip */
631  16 * 4, /* %eflags */
632  15 * 4, /* %cs */
633  18 * 4, /* %ss */
634  3 * 4, /* %ds */
635  2 * 4, /* %es */
636  1 * 4, /* %fs */
637  0 * 4 /* %gs */
638 };
639 
640 /* Get XSAVE extended state xcr0 from core dump. */
641 
642 uint64_t
644 {
645  asection *xstate = bfd_get_section_by_name (abfd, ".reg-xstate");
646  uint64_t xcr0;
647 
648  if (xstate)
649  {
650  size_t size = bfd_section_size (abfd, xstate);
651 
652  /* Check extended state size. */
654  xcr0 = X86_XSTATE_SSE_MASK;
655  else
656  {
657  char contents[8];
658 
659  if (! bfd_get_section_contents (abfd, xstate, contents,
661  8))
662  {
663  warning (_("Couldn't read `xcr0' bytes from "
664  "`.reg-xstate' section in core file."));
665  return 0;
666  }
667 
668  xcr0 = bfd_get_64 (abfd, contents);
669  }
670  }
671  else
672  xcr0 = 0;
673 
674  return xcr0;
675 }
676 
677 /* See i386-linux-tdep.h. */
678 
679 const struct target_desc *
681 {
682  if (xcr0 == 0)
683  return NULL;
684 
685  static struct target_desc *i386_linux_tdescs \
686  [2/*X87*/][2/*SSE*/][2/*AVX*/][2/*MPX*/][2/*AVX512*/][2/*PKRU*/] = {};
687  struct target_desc **tdesc;
688 
689  tdesc = &i386_linux_tdescs[(xcr0 & X86_XSTATE_X87) ? 1 : 0]
690  [(xcr0 & X86_XSTATE_SSE) ? 1 : 0]
691  [(xcr0 & X86_XSTATE_AVX) ? 1 : 0]
692  [(xcr0 & X86_XSTATE_MPX) ? 1 : 0]
693  [(xcr0 & X86_XSTATE_AVX512) ? 1 : 0]
694  [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0];
695 
696  if (*tdesc == NULL)
697  *tdesc = i386_create_target_description (xcr0, true);
698 
699  return *tdesc;
700 }
701 
702 /* Get Linux/x86 target description from core dump. */
703 
704 static const struct target_desc *
706  struct target_ops *target,
707  bfd *abfd)
708 {
709  /* Linux/i386. */
710  uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
711  const struct target_desc *tdesc = i386_linux_read_description (xcr0);
712 
713  if (tdesc != NULL)
714  return tdesc;
715 
716  if (bfd_get_section_by_name (abfd, ".reg-xfp") != NULL)
718  else
720 }
721 
722 /* Similar to i386_supply_fpregset, but use XSAVE extended state. */
723 
724 static void
726  struct regcache *regcache, int regnum,
727  const void *xstateregs, size_t len)
728 {
729  i387_supply_xsave (regcache, regnum, xstateregs);
730 }
731 
732 struct type *
734 {
736 }
737 
738 /* Similar to i386_collect_fpregset, but use XSAVE extended state. */
739 
740 static void
742  const struct regcache *regcache,
743  int regnum, void *xstateregs, size_t len)
744 {
745  i387_collect_xsave (regcache, regnum, xstateregs, 1);
746 }
747 
748 /* Register set definitions. */
749 
750 static const struct regset i386_linux_xstateregset =
751  {
752  NULL,
755  };
756 
757 /* Iterate over core file register note sections. */
758 
759 static void
762  void *cb_data,
763  const struct regcache *regcache)
764 {
765  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
766 
767  cb (".reg", 68, &i386_gregset, NULL, cb_data);
768 
769  if (tdep->xcr0 & X86_XSTATE_AVX)
770  cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0),
771  &i386_linux_xstateregset, "XSAVE extended state", cb_data);
772  else if (tdep->xcr0 & X86_XSTATE_SSE)
773  cb (".reg-xfp", 512, &i386_fpregset, "extended floating-point",
774  cb_data);
775  else
776  cb (".reg2", 108, &i386_fpregset, NULL, cb_data);
777 }
778 
779 /* Linux kernel shows PC value after the 'int $0x80' instruction even if
780  inferior is still inside the syscall. On next PTRACE_SINGLESTEP it will
781  finish the syscall but PC will not change.
782 
783  Some vDSOs contain 'int $0x80; ret' and during stepping out of the syscall
784  i386_displaced_step_fixup would keep PC at the displaced pad location.
785  As PC is pointing to the 'ret' instruction before the step
786  i386_displaced_step_fixup would expect inferior has just executed that 'ret'
787  and PC should not be adjusted. In reality it finished syscall instead and
788  PC should get relocated back to its vDSO address. Hide the 'ret'
789  instruction by 'nop' so that i386_displaced_step_fixup is not confused.
790 
791  It is not fully correct as the bytes in struct displaced_step_closure will
792  not match the inferior code. But we would need some new flag in
793  displaced_step_closure otherwise to keep the state that syscall is finishing
794  for the later i386_displaced_step_fixup execution as the syscall execution
795  is already no longer detectable there. The new flag field would mean
796  i386-linux-tdep.c needs to wrap all the displacement methods of i386-tdep.c
797  which does not seem worth it. The same effect is achieved by patching that
798  'nop' instruction there instead. */
799 
800 static struct displaced_step_closure *
802  CORE_ADDR from, CORE_ADDR to,
803  struct regcache *regs)
804 {
805  displaced_step_closure *closure_
806  = i386_displaced_step_copy_insn (gdbarch, from, to, regs);
807 
809  {
810  /* The closure returned by i386_displaced_step_copy_insn is simply a
811  buffer with a copy of the instruction. */
813  = (i386_displaced_step_closure *) closure_;
814 
815  /* Fake nop. */
816  closure->buf[0] = 0x90;
817  }
818 
819  return closure_;
820 }
821 
822 static void
824 {
825  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
826  const struct target_desc *tdesc = info.target_desc;
827  struct tdesc_arch_data *tdesc_data = info.tdesc_data;
828  const struct tdesc_feature *feature;
829  int valid_p;
830 
832 
833  linux_init_abi (info, gdbarch);
834 
835  /* GNU/Linux uses ELF. */
836  i386_elf_init_abi (info, gdbarch);
837 
838  /* Reserve a number for orig_eax. */
840 
841  if (! tdesc_has_registers (tdesc))
843  tdep->tdesc = tdesc;
844 
845  feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
846  if (feature == NULL)
847  return;
848 
849  valid_p = tdesc_numbered_register (feature, tdesc_data,
851  "orig_eax");
852  if (!valid_p)
853  return;
854 
855  /* Add the %orig_eax register used for syscall restarting. */
857 
859 
861  tdep->gregset_num_regs = ARRAY_SIZE (i386_linux_gregset_reg_offset);
862  tdep->sizeof_gregset = 17 * 4;
863 
864  tdep->jb_pc_offset = 20; /* From <bits/setjmp.h>. */
865 
869  tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset);
870 
872 
875 
876  /* Initialize the i386_linux_record_tdep. */
877  /* These values are the size of the type that will be used in a system
878  call. They are obtained from Linux Kernel source. */
951 
952  /* These values are the second argument of system call "sys_ioctl".
953  They are obtained from Linux Kernel source. */
1019 
1020  /* These values are the second argument of system call "sys_fcntl"
1021  and "sys_fcntl64". They are obtained from Linux Kernel source. */
1026 
1033 
1037 
1038  /* N_FUN symbols in shared libaries have 0 for their values and need
1039  to be relocated. */
1041 
1042  /* GNU/Linux uses SVR4-style shared libraries. */
1046 
1047  /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
1049 
1051 
1052  /* Enable TLS support. */
1055 
1056  /* Core file support. */
1061 
1062  /* Displaced stepping. */
1068 
1069  /* Functions for 'catch syscall'. */
1073 
1077 }
1078 
1079 void
1081 {
1082  gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LINUX,
1084 
1085 #if GDB_SELF_TEST
1086  struct
1087  {
1088  const char *xml;
1089  uint64_t mask;
1090  } xml_masks[] = {
1091  { "i386/i386-linux.xml", X86_XSTATE_SSE_MASK },
1092  { "i386/i386-mmx-linux.xml", X86_XSTATE_X87_MASK },
1093  { "i386/i386-avx-linux.xml", X86_XSTATE_AVX_MASK },
1094  { "i386/i386-mpx-linux.xml", X86_XSTATE_MPX_MASK },
1095  { "i386/i386-avx-mpx-linux.xml", X86_XSTATE_AVX_MPX_MASK },
1096  { "i386/i386-avx-avx512-linux.xml", X86_XSTATE_AVX_AVX512_MASK },
1097  { "i386/i386-avx-mpx-avx512-pku-linux.xml",
1099  };
1100 
1101  for (auto &a : xml_masks)
1102  {
1103  auto tdesc = i386_linux_read_description (a.mask);
1104 
1105  selftests::record_xml_tdesc (a.xml, tdesc);
1106  }
1107 #endif /* GDB_SELF_TEST */
1108 }
int i386_register_reggroup_p(struct gdbarch *gdbarch, int regnum, struct reggroup *group)
Definition: i386-tdep.c:4515
void set_gdbarch_num_regs(struct gdbarch *gdbarch, int num_regs)
Definition: gdbarch.c:2050
#define LINUX_RT_SIGTRAMP_LEN
#define X86_XSTATE_AVX_MASK
Definition: x86-xstate.h:43
static int i386_linux_sigtramp_p(struct frame_info *this_frame)
int jb_pc_offset
Definition: i386-tdep.h:210
int xsave_xcr0_offset
Definition: i386-tdep.h:144
int size_serial_icounter_struct
Definition: linux-record.h:88
gdbarch_register_reggroup_p_ftype * register_reggroup_p
Definition: i386-tdep.h:207
#define LINUX_SIGTRAMP_LEN
const struct target_desc * i386_linux_read_description(uint64_t xcr0)
void set_gdbarch_displaced_step_fixup(struct gdbarch *gdbarch, gdbarch_displaced_step_fixup_ftype displaced_step_fixup)
Definition: gdbarch.c:3982
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2376
#define X86_XSTATE_SSE_MASK
Definition: x86-xstate.h:42
#define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET
void field_string(const char *fldname, const char *string)
Definition: ui-out.c:544
bfd_vma CORE_ADDR
Definition: common-types.h:41
void set_gdbarch_fetch_tls_load_module_address(struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype fetch_tls_load_module_address)
Definition: gdbarch.c:3038
#define I386_LINUX_NUM_REGS
int i386_process_record(struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR input_addr)
Definition: i386-tdep.c:5025
struct regcache * get_thread_regcache(ptid_t ptid)
Definition: regcache.c:434
int sc_num_regs
Definition: i386-tdep.h:227
uint64_t i386_linux_core_read_xcr0(bfd *abfd)
int(* i386_intx80_record)(struct regcache *regcache)
Definition: i386-tdep.h:246
static struct linux_record_tdep i386_linux_record_tdep
int record_full_arch_list_add_reg(struct regcache *regcache, int regnum)
Definition: record-full.c:468
#define X86_XSTATE_MPX_MASK
Definition: x86-xstate.h:44
struct type * linux_get_siginfo_type_with_fields(struct gdbarch *gdbarch, linux_siginfo_extra_fields extra_fields)
Definition: linux-tdep.c:255
int gdbarch_int_bit(struct gdbarch *gdbarch)
Definition: gdbarch.c:1579
gdb::byte_vector buf
Definition: infrun.h:262
#define LINUX_SIGTRAMP_INSN0
void() iterate_over_regset_sections_cb(const char *sect_name, int size, const struct regset *regset, const char *human_name, void *cb_data)
Definition: gdbarch.h:99
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype skip_trampoline_code)
Definition: gdbarch.c:3316
void warning(const char *fmt,...)
Definition: errors.c:26
CORE_ADDR glibc_skip_solib_resolver(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition: glibc-tdep.c:38
void set_gdbarch_write_pc(struct gdbarch *gdbarch, gdbarch_write_pc_ftype write_pc)
Definition: gdbarch.c:1943
void set_gdbarch_get_siginfo_type(struct gdbarch *gdbarch, gdbarch_get_siginfo_type_ftype get_siginfo_type)
Definition: gdbarch.c:4233
void set_gdbarch_displaced_step_location(struct gdbarch *gdbarch, gdbarch_displaced_step_location_ftype displaced_step_location)
Definition: gdbarch.c:3999
int gdbarch_ptr_bit(struct gdbarch *gdbarch)
Definition: gdbarch.c:1831
#define LINUX_RT_SIGTRAMP_INSN1
const struct regset i386_fpregset
Definition: i386-tdep.c:3933
void set_gdbarch_process_record_signal(struct gdbarch *gdbarch, gdbarch_process_record_signal_ftype process_record_signal)
Definition: gdbarch.c:4161
int(* i386_syscall_record)(struct regcache *regcache)
Definition: i386-tdep.h:250
struct displaced_step_closure * i386_displaced_step_copy_insn(struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs)
Definition: i386-tdep.c:800
void i386_linux_handle_segmentation_fault(struct gdbarch *gdbarch, struct ui_out *uiout)
void linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: linux-tdep.c:2492
int i386_mpx_enabled(void)
Definition: i386-tdep.c:8756
CORE_ADDR(* sigcontext_addr)(struct frame_info *)
Definition: alpha-tdep.h:82
static CORE_ADDR i386_linux_rt_sigtramp_start(struct frame_info *this_frame)
int gdbarch_long_bit(struct gdbarch *gdbarch)
Definition: gdbarch.c:1596
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3183
struct reggroup *const restore_reggroup
Definition: reggroups.c:320
void dwarf2_frame_set_signal_frame_p(struct gdbarch *gdbarch, int(*signal_frame_p)(struct gdbarch *, struct frame_info *))
Definition: dwarf2-frame.c:771
static CORE_ADDR i386_linux_sigcontext_addr(struct frame_info *this_frame)
static int i386_linux_register_reggroup_p(struct gdbarch *gdbarch, int regnum, struct reggroup *group)
#define _(String)
Definition: gdb_locale.h:35
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1491
#define END_CATCH
void text(const char *string)
Definition: ui-out.c:581
void set_gdbarch_process_record(struct gdbarch *gdbarch, gdbarch_process_record_ftype process_record)
Definition: gdbarch.c:4137
#define X86_XSTATE_SIZE(XCR0)
Definition: x86-xstate.h:69
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: utils.c:2745
struct type * x86_linux_get_siginfo_type(struct gdbarch *gdbarch)
static LONGEST i386_linux_get_syscall_number_from_regcache(struct regcache *regcache)
CORE_ADDR svr4_fetch_objfile_link_map(struct objfile *objfile)
Definition: solib-svr4.c:1579
static const struct target_desc * i386_linux_core_read_description(struct gdbarch *gdbarch, struct target_ops *target, bfd *abfd)
Definition: regset.h:34
#define TRY
int(* i386_sysenter_record)(struct regcache *regcache)
Definition: i386-tdep.h:248
static const struct regset i386_linux_xstateregset
int tdesc_numbered_register(const struct tdesc_feature *feature, struct tdesc_arch_data *data, int regno, const char *name)
const char *const name
Definition: aarch64-tdep.c:76
#define X86_XSTATE_PKRU
Definition: x86-xstate.h:38
#define CATCH(EXCEPTION, MASK)
#define I386_LINUX_frame_size
#define X86_XSTATE_AVX_AVX512_MASK
Definition: x86-xstate.h:46
static int i386_linux_record_signal(struct gdbarch *gdbarch, struct regcache *regcache, enum gdb_signal signal)
static int i386_all_but_ip_registers_record(struct regcache *regcache)
int record_linux_system_call(enum gdb_syscall syscall, struct regcache *regcache, struct linux_record_tdep *tdep)
Definition: linux-record.c:241
CORE_ADDR find_solib_trampoline_target(struct frame_info *frame, CORE_ADDR pc)
Definition: minsyms.c:1492
static ULONGEST extract_unsigned_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
Definition: defs.h:577
int safe_frame_unwind_memory(struct frame_info *this_frame, CORE_ADDR addr, gdb_byte *buf, int len)
Definition: frame.c:2681
struct reggroup *const system_reggroup
Definition: reggroups.c:316
static void i386_linux_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
static LONGEST i386_linux_get_syscall_number(struct gdbarch *gdbarch, ptid_t ptid)
Definition: ptid.h:35
#define LINUX_SIGTRAMP_OFFSET1
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1509
static void i386_linux_supply_xstateregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *xstateregs, size_t len)
#define X86_XSTATE_SSE
Definition: x86-xstate.h:25
target_desc * i386_create_target_description(uint64_t xcr0, bool is_linux)
Definition: i386.c:34
#define TARGET_CHAR_BIT
Definition: host-defs.h:29
static void i386_linux_write_pc(struct regcache *regcache, CORE_ADDR pc)
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
Definition: solib-svr4.c:3137
Definition: gdbtypes.h:749
int find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr)
Definition: blockframe.c:320
#define LINUX_SIGTRAMP_INSN1
#define LINUX_RT_SIGTRAMP_OFFSET1
#define I386_LINUX_xstate
const struct regset i386_gregset
Definition: i386-tdep.c:3928
void i386_displaced_step_fixup(struct gdbarch *gdbarch, struct displaced_step_closure *closure_, CORE_ADDR from, CORE_ADDR to, struct regcache *regs)
Definition: i386-tdep.c:838
int regnum
Definition: aarch64-tdep.c:77
void set_xml_syscall_file_name(struct gdbarch *gdbarch, const char *name)
Definition: xml-syscall.c:513
void printf_unfiltered(const char *format,...)
Definition: utils.c:2056
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:258
static CORE_ADDR i386_linux_sigtramp_start(struct frame_info *this_frame)
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition: osabi.c:143
CORE_ADDR linux_displaced_step_location(struct gdbarch *gdbarch)
Definition: linux-tdep.c:2437
#define LINUX_SIGTRAMP_OFFSET2
void set_gdbarch_sofun_address_maybe_missing(struct gdbarch *gdbarch, int sofun_address_maybe_missing)
Definition: gdbarch.c:4113
static void i386_linux_collect_xstateregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *xstateregs, size_t len)
gdb_syscall
Definition: linux-record.h:183
int record_full_arch_list_add_mem(CORE_ADDR addr, int len)
Definition: record-full.c:491
#define gdb_assert(expr)
Definition: gdb_assert.h:32
const struct target_desc * target_desc
Definition: gdbarch.h:1660
void i387_collect_xsave(const struct regcache *regcache, int regnum, void *xsave, int gcore)
Definition: i387-tdep.c:1306
int * gregset_reg_offset
Definition: i386-tdep.h:61
static const gdb_byte linux_rt_sigtramp_code[]
Definition: ui-out.h:77
#define X86_XSTATE_X87_MASK
Definition: x86-xstate.h:41
bfd_byte gdb_byte
Definition: common-types.h:38
static int i386_linux_sc_reg_offset[]
static int i386_linux_dwarf_signal_frame_p(struct gdbarch *gdbarch, struct frame_info *this_frame)
int(* sigtramp_p)(struct frame_info *)
Definition: i386-tdep.h:220
void set_gdbarch_displaced_step_copy_insn(struct gdbarch *gdbarch, gdbarch_displaced_step_copy_insn_ftype displaced_step_copy_insn)
Definition: gdbarch.c:3940
#define I386_LINUX_ORIG_EAX_REGNUM
uint64_t xcr0
Definition: i386-tdep.h:141
#define X86_XSTATE_AVX_SIZE
Definition: x86-xstate.h:54
void regcache_cooked_write_unsigned(struct regcache *regcache, int regnum, ULONGEST val)
Definition: regcache.c:806
#define X86_XSTATE_AVX512
Definition: x86-xstate.h:35
void i386_elf_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: i386-tdep.c:4439
void set_gdbarch_get_syscall_number(struct gdbarch *gdbarch, gdbarch_get_syscall_number_ftype get_syscall_number)
Definition: gdbarch.c:4281
static enum gdb_syscall i386_canonicalize_syscall(int syscall)
void get_frame_register(struct frame_info *frame, int regnum, gdb_byte *buf)
Definition: frame.c:1165
gdbarch * arch() const
Definition: regcache.c:221
enum register_status regcache_cooked_read(struct regcache *regcache, int regnum, gdb_byte *buf)
Definition: regcache.c:661
size_t sizeof_gregset
Definition: i386-tdep.h:63
static LONGEST extract_signed_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
Definition: defs.h:570
#define LINUX_SIGTRAMP_INSN2
static void i386_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
const struct target_desc * tdesc
Definition: i386-tdep.h:204
#define X86_XSTATE_MPX
Definition: x86-xstate.h:29
#define X86_XSTATE_X87
Definition: x86-xstate.h:24
int * sc_reg_offset
Definition: i386-tdep.h:226
#define SIG_CODE_BONDARY_FAULT
unsigned long long ULONGEST
Definition: common-types.h:53
int i386_linux_gregset_reg_offset[]
const struct tdesc_feature * tdesc_find_feature(const struct target_desc *target_desc, const char *name)
#define LINUX_RT_SIGTRAMP_INSN0
#define XML_SYSCALL_FILENAME_I386
static int i386_linux_intx80_sysenter_syscall_record(struct regcache *regcache)
#define X86_XSTATE_AVX_MPX_MASK
Definition: x86-xstate.h:45
static struct displaced_step_closure * i386_linux_displaced_step_copy_insn(struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs)
struct reggroup *const save_reggroup
Definition: reggroups.c:319
void _initialize_i386_linux_tdep(void)
enum register_status regcache_raw_read_unsigned(struct regcache *regcache, int regnum, ULONGEST *val)
Definition: regcache.c:612
#define I386_LINUX_XSAVE_XCR0_OFFSET
void set_gdbarch_handle_segmentation_fault(struct gdbarch *gdbarch, gdbarch_handle_segmentation_fault_ftype handle_segmentation_fault)
Definition: gdbarch.c:2139
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype iterate_over_regset_sections)
Definition: gdbarch.c:3647
ptid_t ptid() const
Definition: regcache.h:325
static struct gdbarch_data * tdesc_data
void i387_supply_xsave(struct regcache *regcache, int regnum, const void *xsave)
Definition: i387-tdep.c:898
void set_gdbarch_skip_solib_resolver(struct gdbarch *gdbarch, gdbarch_skip_solib_resolver_ftype skip_solib_resolver)
Definition: gdbarch.c:3333
struct tdesc_arch_data * tdesc_data
Definition: gdbarch.h:1648
static const gdb_byte linux_sigtramp_code[]
int gregset_num_regs
Definition: i386-tdep.h:62
enum bfd_endian byte_order
Definition: gdbarch.c:137
#define X86_XSTATE_AVX
Definition: x86-xstate.h:26
int record_full_arch_list_add_end(void)
Definition: record-full.c:522
void set_gdbarch_core_read_description(struct gdbarch *gdbarch, gdbarch_core_read_description_ftype core_read_description)
Definition: gdbarch.c:4072
int tdesc_has_registers(const struct target_desc *target_desc)
void error(const char *fmt,...)
Definition: errors.c:38
size_t size
Definition: go32-nat.c:242
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2691
#define X86_XSTATE_AVX_MPX_AVX512_PKU_MASK
Definition: x86-xstate.h:47
long long LONGEST
Definition: common-types.h:52
void field_fmt(const char *fldname, const char *format,...) ATTRIBUTE_PRINTF(3
Definition: ui-out.c:557
enum register_status regcache_raw_read_signed(struct regcache *regcache, int regnum, LONGEST *val)
Definition: regcache.c:586
LONGEST parse_and_eval_long(const char *exp)
Definition: eval.c:111