GDB (xrefs)
/tmp/gdb-7.10/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-2015 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 "glibc-tdep.h"
34 #include "solib-svr4.h"
35 #include "symtab.h"
36 #include "arch-utils.h"
37 #include "xml-syscall.h"
38 
39 #include "i387-tdep.h"
40 #include "x86-xstate.h"
41 
42 /* The syscall's XML filename for i386. */
43 #define XML_SYSCALL_FILENAME_I386 "syscalls/i386-linux.xml"
44 
45 #include "record-full.h"
46 #include "linux-record.h"
52 
53 /* Return non-zero, when the register is in the corresponding register
54  group. Put the LINUX_ORIG_EAX register in the system group. */
55 static int
57  struct reggroup *group)
58 {
59  if (regnum == I386_LINUX_ORIG_EAX_REGNUM)
60  return (group == system_reggroup
61  || group == save_reggroup
62  || group == restore_reggroup);
63  return i386_register_reggroup_p (gdbarch, regnum, group);
64 }
65 
66 
67 /* Recognizing signal handler frames. */
68 
69 /* GNU/Linux has two flavors of signals. Normal signal handlers, and
70  "realtime" (RT) signals. The RT signals can provide additional
71  information to the signal handler if the SA_SIGINFO flag is set
72  when establishing a signal handler using `sigaction'. It is not
73  unlikely that future versions of GNU/Linux will support SA_SIGINFO
74  for normal signals too. */
75 
76 /* When the i386 Linux kernel calls a signal handler and the
77  SA_RESTORER flag isn't set, the return address points to a bit of
78  code on the stack. This function returns whether the PC appears to
79  be within this bit of code.
80 
81  The instruction sequence for normal signals is
82  pop %eax
83  mov $0x77, %eax
84  int $0x80
85  or 0x58 0xb8 0x77 0x00 0x00 0x00 0xcd 0x80.
86 
87  Checking for the code sequence should be somewhat reliable, because
88  the effect is to call the system call sigreturn. This is unlikely
89  to occur anywhere other than in a signal trampoline.
90 
91  It kind of sucks that we have to read memory from the process in
92  order to identify a signal trampoline, but there doesn't seem to be
93  any other way. Therefore we only do the memory reads if no
94  function name could be identified, which should be the case since
95  the code is on the stack.
96 
97  Detection of signal trampolines for handlers that set the
98  SA_RESTORER flag is in general not possible. Unfortunately this is
99  what the GNU C Library has been doing for quite some time now.
100  However, as of version 2.1.2, the GNU C Library uses signal
101  trampolines (named __restore and __restore_rt) that are identical
102  to the ones used by the kernel. Therefore, these trampolines are
103  supported too. */
104 
105 #define LINUX_SIGTRAMP_INSN0 0x58 /* pop %eax */
106 #define LINUX_SIGTRAMP_OFFSET0 0
107 #define LINUX_SIGTRAMP_INSN1 0xb8 /* mov $NNNN, %eax */
108 #define LINUX_SIGTRAMP_OFFSET1 1
109 #define LINUX_SIGTRAMP_INSN2 0xcd /* int */
110 #define LINUX_SIGTRAMP_OFFSET2 6
111 
113 {
114  LINUX_SIGTRAMP_INSN0, /* pop %eax */
115  LINUX_SIGTRAMP_INSN1, 0x77, 0x00, 0x00, 0x00, /* mov $0x77, %eax */
116  LINUX_SIGTRAMP_INSN2, 0x80 /* int $0x80 */
117 };
118 
119 #define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
120 
121 /* If THIS_FRAME is a sigtramp routine, return the address of the
122  start of the routine. Otherwise, return 0. */
123 
124 static CORE_ADDR
126 {
127  CORE_ADDR pc = get_frame_pc (this_frame);
129 
130  /* We only recognize a signal trampoline if PC is at the start of
131  one of the three instructions. We optimize for finding the PC at
132  the start, as will be the case when the trampoline is not the
133  first frame on the stack. We assume that in the case where the
134  PC is not at the start of the instruction sequence, there will be
135  a few trailing readable bytes on the stack. */
136 
137  if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
138  return 0;
139 
140  if (buf[0] != LINUX_SIGTRAMP_INSN0)
141  {
142  int adjust;
143 
144  switch (buf[0])
145  {
147  adjust = LINUX_SIGTRAMP_OFFSET1;
148  break;
150  adjust = LINUX_SIGTRAMP_OFFSET2;
151  break;
152  default:
153  return 0;
154  }
155 
156  pc -= adjust;
157 
158  if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
159  return 0;
160  }
161 
162  if (memcmp (buf, linux_sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
163  return 0;
164 
165  return pc;
166 }
167 
168 /* This function does the same for RT signals. Here the instruction
169  sequence is
170  mov $0xad, %eax
171  int $0x80
172  or 0xb8 0xad 0x00 0x00 0x00 0xcd 0x80.
173 
174  The effect is to call the system call rt_sigreturn. */
175 
176 #define LINUX_RT_SIGTRAMP_INSN0 0xb8 /* mov $NNNN, %eax */
177 #define LINUX_RT_SIGTRAMP_OFFSET0 0
178 #define LINUX_RT_SIGTRAMP_INSN1 0xcd /* int */
179 #define LINUX_RT_SIGTRAMP_OFFSET1 5
180 
182 {
183  LINUX_RT_SIGTRAMP_INSN0, 0xad, 0x00, 0x00, 0x00, /* mov $0xad, %eax */
184  LINUX_RT_SIGTRAMP_INSN1, 0x80 /* int $0x80 */
185 };
186 
187 #define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code)
188 
189 /* If THIS_FRAME is an RT sigtramp routine, return the address of the
190  start of the routine. Otherwise, return 0. */
191 
192 static CORE_ADDR
194 {
195  CORE_ADDR pc = get_frame_pc (this_frame);
197 
198  /* We only recognize a signal trampoline if PC is at the start of
199  one of the two instructions. We optimize for finding the PC at
200  the start, as will be the case when the trampoline is not the
201  first frame on the stack. We assume that in the case where the
202  PC is not at the start of the instruction sequence, there will be
203  a few trailing readable bytes on the stack. */
204 
205  if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_RT_SIGTRAMP_LEN))
206  return 0;
207 
208  if (buf[0] != LINUX_RT_SIGTRAMP_INSN0)
209  {
210  if (buf[0] != LINUX_RT_SIGTRAMP_INSN1)
211  return 0;
212 
214 
215  if (!safe_frame_unwind_memory (this_frame, pc, buf,
217  return 0;
218  }
219 
220  if (memcmp (buf, linux_rt_sigtramp_code, LINUX_RT_SIGTRAMP_LEN) != 0)
221  return 0;
222 
223  return pc;
224 }
225 
226 /* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
227  routine. */
228 
229 static int
230 i386_linux_sigtramp_p (struct frame_info *this_frame)
231 {
232  CORE_ADDR pc = get_frame_pc (this_frame);
233  const char *name;
234 
235  find_pc_partial_function (pc, &name, NULL, NULL);
236 
237  /* If we have NAME, we can optimize the search. The trampolines are
238  named __restore and __restore_rt. However, they aren't dynamically
239  exported from the shared C library, so the trampoline may appear to
240  be part of the preceding function. This should always be sigaction,
241  __sigaction, or __libc_sigaction (all aliases to the same function). */
242  if (name == NULL || strstr (name, "sigaction") != NULL)
243  return (i386_linux_sigtramp_start (this_frame) != 0
244  || i386_linux_rt_sigtramp_start (this_frame) != 0);
245 
246  return (strcmp ("__restore", name) == 0
247  || strcmp ("__restore_rt", name) == 0);
248 }
249 
250 /* Return one if the PC of THIS_FRAME is in a signal trampoline which
251  may have DWARF-2 CFI. */
252 
253 static int
255  struct frame_info *this_frame)
256 {
257  CORE_ADDR pc = get_frame_pc (this_frame);
258  const char *name;
259 
260  find_pc_partial_function (pc, &name, NULL, NULL);
261 
262  /* If a vsyscall DSO is in use, the signal trampolines may have these
263  names. */
264  if (name && (strcmp (name, "__kernel_sigreturn") == 0
265  || strcmp (name, "__kernel_rt_sigreturn") == 0))
266  return 1;
267 
268  return 0;
269 }
270 
271 /* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
272 #define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 20
273 
274 /* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
275  address of the associated sigcontext structure. */
276 
277 static CORE_ADDR
279 {
280  struct gdbarch *gdbarch = get_frame_arch (this_frame);
281  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
282  CORE_ADDR pc;
283  CORE_ADDR sp;
284  gdb_byte buf[4];
285 
286  get_frame_register (this_frame, I386_ESP_REGNUM, buf);
287  sp = extract_unsigned_integer (buf, 4, byte_order);
288 
289  pc = i386_linux_sigtramp_start (this_frame);
290  if (pc)
291  {
292  /* The sigcontext structure lives on the stack, right after
293  the signum argument. We determine the address of the
294  sigcontext structure by looking at the frame's stack
295  pointer. Keep in mind that the first instruction of the
296  sigtramp code is "pop %eax". If the PC is after this
297  instruction, adjust the returned value accordingly. */
298  if (pc == get_frame_pc (this_frame))
299  return sp + 4;
300  return sp;
301  }
302 
303  pc = i386_linux_rt_sigtramp_start (this_frame);
304  if (pc)
305  {
306  CORE_ADDR ucontext_addr;
307 
308  /* The sigcontext structure is part of the user context. A
309  pointer to the user context is passed as the third argument
310  to the signal handler. */
311  read_memory (sp + 8, buf, 4);
312  ucontext_addr = extract_unsigned_integer (buf, 4, byte_order);
313  return ucontext_addr + I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET;
314  }
315 
316  error (_("Couldn't recognize signal trampoline."));
317  return 0;
318 }
319 
320 /* Set the program counter for process PTID to PC. */
321 
322 static void
324 {
326 
327  /* We must be careful with modifying the program counter. If we
328  just interrupted a system call, the kernel might try to restart
329  it when we resume the inferior. On restarting the system call,
330  the kernel will try backing up the program counter even though it
331  no longer points at the system call. This typically results in a
332  SIGSEGV or SIGILL. We can prevent this by writing `-1' in the
333  "orig_eax" pseudo-register.
334 
335  Note that "orig_eax" is saved when setting up a dummy call frame.
336  This means that it is properly restored when that frame is
337  popped, and that the interrupted system call will be restarted
338  when we resume the inferior on return from a function call from
339  within GDB. In all other cases the system call will not be
340  restarted. */
342 }
343 
344 /* Record all registers but IP register for process-record. */
345 
346 static int
348 {
350  return -1;
352  return -1;
354  return -1;
356  return -1;
358  return -1;
360  return -1;
362  return -1;
364  return -1;
366  return -1;
367 
368  return 0;
369 }
370 
371 /* i386_canonicalize_syscall maps from the native i386 Linux set
372  of syscall ids into a canonical set of syscall ids used by
373  process record (a mostly trivial mapping, since the canonical
374  set was originally taken from the i386 set). */
375 
376 static enum gdb_syscall
378 {
379  enum { i386_syscall_max = 499 };
380 
381  if (syscall <= i386_syscall_max)
382  return syscall;
383  else
384  return -1;
385 }
386 
387 /* Parse the arguments of current system call instruction and record
388  the values of the registers and memory that will be changed into
389  "record_arch_list". This instruction is "int 0x80" (Linux
390  Kernel2.4) or "sysenter" (Linux Kernel 2.6).
391 
392  Return -1 if something wrong. */
393 
395 
396 static int
398 {
399  int ret;
400  LONGEST syscall_native;
401  enum gdb_syscall syscall_gdb;
402 
403  regcache_raw_read_signed (regcache, I386_EAX_REGNUM, &syscall_native);
404 
405  syscall_gdb = i386_canonicalize_syscall (syscall_native);
406 
407  if (syscall_gdb < 0)
408  {
409  printf_unfiltered (_("Process record and replay target doesn't "
410  "support syscall number %s\n"),
411  plongest (syscall_native));
412  return -1;
413  }
414 
415  if (syscall_gdb == gdb_sys_sigreturn
416  || syscall_gdb == gdb_sys_rt_sigreturn)
417  {
418  if (i386_all_but_ip_registers_record (regcache))
419  return -1;
420  return 0;
421  }
422 
423  ret = record_linux_system_call (syscall_gdb, regcache,
425  if (ret)
426  return ret;
427 
428  /* Record the return value of the system call. */
430  return -1;
431 
432  return 0;
433 }
434 
435 #define I386_LINUX_xstate 270
436 #define I386_LINUX_frame_size 732
437 
438 static int
440  struct regcache *regcache,
441  enum gdb_signal signal)
442 {
443  ULONGEST esp;
444 
445  if (i386_all_but_ip_registers_record (regcache))
446  return -1;
447 
449  return -1;
450 
451  /* Record the change in the stack. */
453  /* This is for xstate.
454  sp -= sizeof (struct _fpstate); */
455  esp -= I386_LINUX_xstate;
456  /* This is for frame_size.
457  sp -= sizeof (struct rt_sigframe); */
458  esp -= I386_LINUX_frame_size;
461  return -1;
462 
464  return -1;
465 
466  return 0;
467 }
468 
469 
470 /* Core of the implementation for gdbarch get_syscall_number. Get pending
471  syscall number from REGCACHE. If there is no pending syscall -1 will be
472  returned. Pending syscall means ptrace has stepped into the syscall but
473  another ptrace call will step out. PC is right after the int $0x80
474  / syscall / sysenter instruction in both cases, PC does not change during
475  the second ptrace step. */
476 
477 static LONGEST
479 {
480  struct gdbarch *gdbarch = get_regcache_arch (regcache);
481  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
482  /* The content of a register. */
483  gdb_byte buf[4];
484  /* The result. */
485  LONGEST ret;
486 
487  /* Getting the system call number from the register.
488  When dealing with x86 architecture, this information
489  is stored at %eax register. */
491 
492  ret = extract_signed_integer (buf, 4, byte_order);
493 
494  return ret;
495 }
496 
497 /* Wrapper for i386_linux_get_syscall_number_from_regcache to make it
498  compatible with gdbarch get_syscall_number method prototype. */
499 
500 static LONGEST
502  ptid_t ptid)
503 {
504  struct regcache *regcache = get_thread_regcache (ptid);
505 
507 }
508 
509 /* The register sets used in GNU/Linux ELF core-dumps are identical to
510  the register sets in `struct user' that are used for a.out
511  core-dumps. These are also used by ptrace(2). The corresponding
512  types are `elf_gregset_t' for the general-purpose registers (with
513  `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
514  for the floating-point registers.
515 
516  Those types used to be available under the names `gregset_t' and
517  `fpregset_t' too, and GDB used those names in the past. But those
518  names are now used for the register sets used in the `mcontext_t'
519  type, which have a different size and layout. */
520 
521 /* Mapping between the general-purpose registers in `struct user'
522  format and GDB's register cache layout. */
523 
524 /* From <sys/reg.h>. */
526 {
527  6 * 4, /* %eax */
528  1 * 4, /* %ecx */
529  2 * 4, /* %edx */
530  0 * 4, /* %ebx */
531  15 * 4, /* %esp */
532  5 * 4, /* %ebp */
533  3 * 4, /* %esi */
534  4 * 4, /* %edi */
535  12 * 4, /* %eip */
536  14 * 4, /* %eflags */
537  13 * 4, /* %cs */
538  16 * 4, /* %ss */
539  7 * 4, /* %ds */
540  8 * 4, /* %es */
541  9 * 4, /* %fs */
542  10 * 4, /* %gs */
543  -1, -1, -1, -1, -1, -1, -1, -1,
544  -1, -1, -1, -1, -1, -1, -1, -1,
545  -1, -1, -1, -1, -1, -1, -1, -1,
546  -1,
547  -1, -1, -1, -1, -1, -1, -1, -1,
548  -1, -1, -1, -1, /* MPX registers BND0 ... BND3. */
549  -1, -1, /* MPX registers BNDCFGU, BNDSTATUS. */
550  -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512) */
551  -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm7 (AVX512) */
552  11 * 4, /* "orig_eax" */
553 };
554 
555 /* Mapping between the general-purpose registers in `struct
556  sigcontext' format and GDB's register cache layout. */
557 
558 /* From <asm/sigcontext.h>. */
560 {
561  11 * 4, /* %eax */
562  10 * 4, /* %ecx */
563  9 * 4, /* %edx */
564  8 * 4, /* %ebx */
565  7 * 4, /* %esp */
566  6 * 4, /* %ebp */
567  5 * 4, /* %esi */
568  4 * 4, /* %edi */
569  14 * 4, /* %eip */
570  16 * 4, /* %eflags */
571  15 * 4, /* %cs */
572  18 * 4, /* %ss */
573  3 * 4, /* %ds */
574  2 * 4, /* %es */
575  1 * 4, /* %fs */
576  0 * 4 /* %gs */
577 };
578 
579 /* Get XSAVE extended state xcr0 from core dump. */
580 
581 uint64_t
583 {
584  asection *xstate = bfd_get_section_by_name (abfd, ".reg-xstate");
585  uint64_t xcr0;
586 
587  if (xstate)
588  {
589  size_t size = bfd_section_size (abfd, xstate);
590 
591  /* Check extended state size. */
592  if (size < X86_XSTATE_AVX_SIZE)
593  xcr0 = X86_XSTATE_SSE_MASK;
594  else
595  {
596  char contents[8];
597 
598  if (! bfd_get_section_contents (abfd, xstate, contents,
600  8))
601  {
602  warning (_("Couldn't read `xcr0' bytes from "
603  "`.reg-xstate' section in core file."));
604  return 0;
605  }
606 
607  xcr0 = bfd_get_64 (abfd, contents);
608  }
609  }
610  else
611  xcr0 = 0;
612 
613  return xcr0;
614 }
615 
616 /* Get Linux/x86 target description from core dump. */
617 
618 static const struct target_desc *
620  struct target_ops *target,
621  bfd *abfd)
622 {
623  /* Linux/i386. */
624  uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
625 
626  switch ((xcr0 & X86_XSTATE_ALL_MASK))
627  {
631  case X86_XSTATE_MPX_MASK:
632  return tdesc_i386_mpx_linux;
633  case X86_XSTATE_AVX_MASK:
634  return tdesc_i386_avx_linux;
635  case X86_XSTATE_SSE_MASK:
636  return tdesc_i386_linux;
637  case X86_XSTATE_X87_MASK:
638  return tdesc_i386_mmx_linux;
639  default:
640  break;
641  }
642 
643  if (bfd_get_section_by_name (abfd, ".reg-xfp") != NULL)
644  return tdesc_i386_linux;
645  else
646  return tdesc_i386_mmx_linux;
647 }
648 
649 /* Similar to i386_supply_fpregset, but use XSAVE extended state. */
650 
651 static void
653  struct regcache *regcache, int regnum,
654  const void *xstateregs, size_t len)
655 {
656  i387_supply_xsave (regcache, regnum, xstateregs);
657 }
658 
659 /* Similar to i386_collect_fpregset, but use XSAVE extended state. */
660 
661 static void
663  const struct regcache *regcache,
664  int regnum, void *xstateregs, size_t len)
665 {
666  i387_collect_xsave (regcache, regnum, xstateregs, 1);
667 }
668 
669 /* Register set definitions. */
670 
671 static const struct regset i386_linux_xstateregset =
672  {
673  NULL,
676  };
677 
678 /* Iterate over core file register note sections. */
679 
680 static void
683  void *cb_data,
684  const struct regcache *regcache)
685 {
686  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
687 
688  cb (".reg", 68, &i386_gregset, NULL, cb_data);
689 
690  if (tdep->xcr0 & X86_XSTATE_AVX)
691  cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0),
692  &i386_linux_xstateregset, "XSAVE extended state", cb_data);
693  else if (tdep->xcr0 & X86_XSTATE_SSE)
694  cb (".reg-xfp", 512, &i386_fpregset, "extended floating-point",
695  cb_data);
696  else
697  cb (".reg2", 108, &i386_fpregset, NULL, cb_data);
698 }
699 
700 /* Linux kernel shows PC value after the 'int $0x80' instruction even if
701  inferior is still inside the syscall. On next PTRACE_SINGLESTEP it will
702  finish the syscall but PC will not change.
703 
704  Some vDSOs contain 'int $0x80; ret' and during stepping out of the syscall
705  i386_displaced_step_fixup would keep PC at the displaced pad location.
706  As PC is pointing to the 'ret' instruction before the step
707  i386_displaced_step_fixup would expect inferior has just executed that 'ret'
708  and PC should not be adjusted. In reality it finished syscall instead and
709  PC should get relocated back to its vDSO address. Hide the 'ret'
710  instruction by 'nop' so that i386_displaced_step_fixup is not confused.
711 
712  It is not fully correct as the bytes in struct displaced_step_closure will
713  not match the inferior code. But we would need some new flag in
714  displaced_step_closure otherwise to keep the state that syscall is finishing
715  for the later i386_displaced_step_fixup execution as the syscall execution
716  is already no longer detectable there. The new flag field would mean
717  i386-linux-tdep.c needs to wrap all the displacement methods of i386-tdep.c
718  which does not seem worth it. The same effect is achieved by patching that
719  'nop' instruction there instead. */
720 
721 static struct displaced_step_closure *
724  struct regcache *regs)
725 {
726  struct displaced_step_closure *closure;
727 
728  closure = i386_displaced_step_copy_insn (gdbarch, from, to, regs);
729 
731  {
732  /* Since we use simple_displaced_step_copy_insn, our closure is a
733  copy of the instruction. */
734  gdb_byte *insn = (gdb_byte *) closure;
735 
736  /* Fake nop. */
737  insn[0] = 0x90;
738  }
739 
740  return closure;
741 }
742 
743 static void
745 {
746  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
747  const struct target_desc *tdesc = info.target_desc;
748  struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
749  const struct tdesc_feature *feature;
750  int valid_p;
751 
752  gdb_assert (tdesc_data);
753 
754  linux_init_abi (info, gdbarch);
755 
756  /* GNU/Linux uses ELF. */
757  i386_elf_init_abi (info, gdbarch);
758 
759  /* Reserve a number for orig_eax. */
761 
762  if (! tdesc_has_registers (tdesc))
763  tdesc = tdesc_i386_linux;
764  tdep->tdesc = tdesc;
765 
766  feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
767  if (feature == NULL)
768  return;
769 
770  valid_p = tdesc_numbered_register (feature, tdesc_data,
772  "orig_eax");
773  if (!valid_p)
774  return;
775 
776  /* Add the %orig_eax register used for syscall restarting. */
778 
780 
782  tdep->gregset_num_regs = ARRAY_SIZE (i386_linux_gregset_reg_offset);
783  tdep->sizeof_gregset = 17 * 4;
784 
785  tdep->jb_pc_offset = 20; /* From <bits/setjmp.h>. */
786 
790  tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset);
791 
793 
796 
797  /* Initialize the i386_linux_record_tdep. */
798  /* These values are the size of the type that will be used in a system
799  call. They are obtained from Linux Kernel source. */
801  = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
823  = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
825  = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
827  = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
873 
874  /* These values are the second argument of system call "sys_ioctl".
875  They are obtained from Linux Kernel source. */
941 
942  /* These values are the second argument of system call "sys_fcntl"
943  and "sys_fcntl64". They are obtained from Linux Kernel source. */
948 
955 
959 
960  /* N_FUN symbols in shared libaries have 0 for their values and need
961  to be relocated. */
963 
964  /* GNU/Linux uses SVR4-style shared libraries. */
968 
969  /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
971 
973 
974  /* Enable TLS support. */
977 
978  /* Core file support. */
983 
984  /* Displaced stepping. */
992 
993  /* Functions for 'catch syscall'. */
997 }
998 
999 /* Provide a prototype to silence -Wmissing-prototypes. */
1000 extern void _initialize_i386_linux_tdep (void);
1001 
1002 void
1004 {
1005  gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LINUX,
1007 
1008  /* Initialize the Linux target description. */
1014 }
int i386_register_reggroup_p(struct gdbarch *gdbarch, int regnum, struct reggroup *group)
Definition: i386-tdep.c:4437
void set_gdbarch_num_regs(struct gdbarch *gdbarch, int num_regs)
Definition: gdbarch.c:1909
#define LINUX_RT_SIGTRAMP_LEN
#define X86_XSTATE_AVX_MASK
Definition: x86-xstate.h:41
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
Definition: findvar.c:84
static int i386_linux_sigtramp_p(struct frame_info *this_frame)
int jb_pc_offset
Definition: i386-tdep.h:199
int xsave_xcr0_offset
Definition: i386-tdep.h:142
int size_serial_icounter_struct
Definition: linux-record.h:90
#define LINUX_SIGTRAMP_LEN
void set_gdbarch_displaced_step_fixup(struct gdbarch *gdbarch, gdbarch_displaced_step_fixup_ftype displaced_step_fixup)
Definition: gdbarch.c:3709
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2217
#define X86_XSTATE_SSE_MASK
Definition: x86-xstate.h:40
#define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET
Definition: target.h:98
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:2822
#define I386_LINUX_NUM_REGS
int i386_process_record(struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR input_addr)
Definition: i386-tdep.c:4950
struct regcache * get_thread_regcache(ptid_t ptid)
Definition: regcache.c:529
int sc_num_regs
Definition: i386-tdep.h:216
uint64_t i386_linux_core_read_xcr0(bfd *abfd)
int(* i386_intx80_record)(struct regcache *regcache)
Definition: i386-tdep.h:235
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:466
#define X86_XSTATE_MPX_MASK
Definition: x86-xstate.h:42
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
Definition: regcache.c:297
int gdbarch_int_bit(struct gdbarch *gdbarch)
Definition: gdbarch.c:1490
#define LINUX_SIGTRAMP_INSN0
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype skip_trampoline_code)
Definition: gdbarch.c:3084
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:1802
void set_gdbarch_displaced_step_location(struct gdbarch *gdbarch, gdbarch_displaced_step_location_ftype displaced_step_location)
Definition: gdbarch.c:3743
int gdbarch_ptr_bit(struct gdbarch *gdbarch)
Definition: gdbarch.c:1690
#define LINUX_RT_SIGTRAMP_INSN1
const struct regset i386_fpregset
Definition: i386-tdep.c:3824
void set_gdbarch_process_record_signal(struct gdbarch *gdbarch, gdbarch_process_record_signal_ftype process_record_signal)
Definition: gdbarch.c:3905
int(* i386_syscall_record)(struct regcache *regcache)
Definition: i386-tdep.h:239
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:775
void linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: linux-tdep.c:2427
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:1507
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3149
struct reggroup *const restore_reggroup
Definition: reggroups.c:298
void dwarf2_frame_set_signal_frame_p(struct gdbarch *gdbarch, int(*signal_frame_p)(struct gdbarch *, struct frame_info *))
Definition: dwarf2-frame.c:806
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:40
struct gdbarch_tdep_info * tdep_info
Definition: gdbarch.h:1560
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:812
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1402
void set_gdbarch_process_record(struct gdbarch *gdbarch, gdbarch_process_record_ftype process_record)
Definition: gdbarch.c:3881
#define X86_XSTATE_SIZE(XCR0)
Definition: x86-xstate.h:62
Definition: ptid.h:35
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:1573
static const struct target_desc * i386_linux_core_read_description(struct gdbarch *gdbarch, struct target_ops *target, bfd *abfd)
Definition: regset.h:34
int(* i386_sysenter_record)(struct regcache *regcache)
Definition: i386-tdep.h:237
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:68
int * from
Definition: varobj.h:282
struct target_desc * tdesc_i386_avx512_linux
#define I386_LINUX_frame_size
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:227
CORE_ADDR find_solib_trampoline_target(struct frame_info *frame, CORE_ADDR pc)
Definition: minsyms.c:1394
int safe_frame_unwind_memory(struct frame_info *this_frame, CORE_ADDR addr, gdb_byte *buf, int len)
Definition: frame.c:2525
struct reggroup *const system_reggroup
Definition: reggroups.c:294
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)
#define LINUX_SIGTRAMP_OFFSET1
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1420
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
#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:3108
static void initialize_tdesc_i386_avx_linux(void)
int find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr)
Definition: blockframe.c:321
#define LINUX_SIGTRAMP_INSN1
#define LINUX_RT_SIGTRAMP_OFFSET1
#define I386_LINUX_xstate
const void * register_reggroup_p
Definition: i386-tdep.h:196
#define gdb_assert(expr)
Definition: gdb_assert.h:33
#define X86_XSTATE_MPX_AVX512_MASK
Definition: x86-xstate.h:44
const struct regset i386_gregset
Definition: i386-tdep.c:3819
enum register_status regcache_raw_read_unsigned(struct regcache *regcache, int regnum, ULONGEST *val)
Definition: regcache.c:690
int regnum
Definition: aarch64-tdep.c:69
void set_xml_syscall_file_name(struct gdbarch *gdbarch, const char *name)
Definition: xml-syscall.c:392
void printf_unfiltered(const char *format,...)
Definition: utils.c:2399
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:244
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:98
static CORE_ADDR i386_linux_sigtramp_start(struct frame_info *this_frame)
CORE_ADDR linux_displaced_step_location(struct gdbarch *gdbarch)
Definition: linux-tdep.c:2384
static void initialize_tdesc_i386_linux(void)
Definition: i386-linux.c:10
#define LINUX_SIGTRAMP_OFFSET2
void set_gdbarch_sofun_address_maybe_missing(struct gdbarch *gdbarch, int sofun_address_maybe_missing)
Definition: gdbarch.c:3857
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:184
int record_full_arch_list_add_mem(CORE_ADDR addr, int len)
Definition: record-full.c:489
const struct target_desc * target_desc
Definition: gdbarch.h:1566
void i387_collect_xsave(const struct regcache *regcache, int regnum, void *xsave, int gcore)
Definition: i387-tdep.c:1267
int * gregset_reg_offset
Definition: i386-tdep.h:59
static const gdb_byte linux_rt_sigtramp_code[]
#define X86_XSTATE_X87_MASK
Definition: x86-xstate.h:39
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:209
void set_gdbarch_displaced_step_copy_insn(struct gdbarch *gdbarch, gdbarch_displaced_step_copy_insn_ftype displaced_step_copy_insn)
Definition: gdbarch.c:3667
#define X86_XSTATE_AVX512_MASK
Definition: x86-xstate.h:43
#define I386_LINUX_ORIG_EAX_REGNUM
uint64_t xcr0
Definition: i386-tdep.h:139
struct target_desc * tdesc_i386_mpx_linux
Definition: i386-mpx-linux.c:8
#define X86_XSTATE_AVX_SIZE
Definition: x86-xstate.h:49
static void initialize_tdesc_i386_mmx_linux(void)
void regcache_cooked_write_unsigned(struct regcache *regcache, int regnum, ULONGEST val)
Definition: regcache.c:871
void i386_elf_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: i386-tdep.c:4332
void set_gdbarch_get_syscall_number(struct gdbarch *gdbarch, gdbarch_get_syscall_number_ftype get_syscall_number)
Definition: gdbarch.c:4025
static void initialize_tdesc_i386_mpx_linux(void)
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:1085
enum register_status regcache_cooked_read(struct regcache *regcache, int regnum, gdb_byte *buf)
Definition: regcache.c:737
size_t sizeof_gregset
Definition: i386-tdep.h:61
#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:193
int * sc_reg_offset
Definition: i386-tdep.h:215
struct target_desc * tdesc_i386_mmx_linux
Definition: i386-mmx-linux.c:8
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)
void set_gdbarch_displaced_step_free_closure(struct gdbarch *gdbarch, gdbarch_displaced_step_free_closure_ftype displaced_step_free_closure)
Definition: gdbarch.c:3726
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:297
struct target_desc * tdesc_i386_linux
Definition: i386-linux.c:8
int int * to
Definition: varobj.h:282
void _initialize_i386_linux_tdep(void)
#define I386_LINUX_XSAVE_XCR0_OFFSET
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype iterate_over_regset_sections)
Definition: gdbarch.c:3398
LONGEST extract_signed_integer(const gdb_byte *, int, enum bfd_endian)
Definition: findvar.c:49
static struct gdbarch_data * tdesc_data
void i387_supply_xsave(struct regcache *regcache, int regnum, const void *xsave)
Definition: i387-tdep.c:894
void set_gdbarch_skip_solib_resolver(struct gdbarch *gdbarch, gdbarch_skip_solib_resolver_ftype skip_solib_resolver)
Definition: gdbarch.c:3101
static const gdb_byte linux_sigtramp_code[]
int gregset_num_regs
Definition: i386-tdep.h:60
enum bfd_endian byte_order
Definition: gdbarch.c:128
#define X86_XSTATE_AVX
Definition: x86-xstate.h:26
struct target_desc * tdesc_i386_avx_linux
Definition: i386-avx-linux.c:8
static void initialize_tdesc_i386_avx512_linux(void)
int record_full_arch_list_add_end(void)
Definition: record-full.c:520
void set_gdbarch_core_read_description(struct gdbarch *gdbarch, gdbarch_core_read_description_ftype core_read_description)
Definition: gdbarch.c:3816
int tdesc_has_registers(const struct target_desc *target_desc)
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:148
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:2535
long long LONGEST
Definition: common-types.h:52
const ULONGEST const LONGEST len
Definition: target.h:309
void simple_displaced_step_free_closure(struct gdbarch *gdbarch, struct displaced_step_closure *closure)
Definition: arch-utils.c:64
enum register_status regcache_raw_read_signed(struct regcache *regcache, int regnum, LONGEST *val)
Definition: regcache.c:671
#define X86_XSTATE_ALL_MASK
Definition: x86-xstate.h:46