GDB (xrefs)
/tmp/gdb-8.1/gdb/amd64-linux-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for GNU/Linux x86-64.
2 
3  Copyright (C) 2001-2018 Free Software Foundation, Inc.
4  Contributed by Jiri Smid, SuSE Labs.
5 
6  This file is part of GDB.
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 
21 #include "defs.h"
22 #include "arch-utils.h"
23 #include "frame.h"
24 #include "gdbcore.h"
25 #include "regcache.h"
26 #include "osabi.h"
27 #include "symtab.h"
28 #include "gdbtypes.h"
29 #include "reggroups.h"
30 #include "regset.h"
31 #include "parser-defs.h"
32 #include "user-regs.h"
33 #include "amd64-linux-tdep.h"
34 #include "i386-linux-tdep.h"
35 #include "linux-tdep.h"
36 #include "x86-xstate.h"
37 
38 #include "amd64-tdep.h"
39 #include "solib-svr4.h"
40 #include "xml-syscall.h"
41 #include "glibc-tdep.h"
42 #include "arch/amd64.h"
43 #include "target-descriptions.h"
44 
45 /* The syscall's XML filename for i386. */
46 #define XML_SYSCALL_FILENAME_AMD64 "syscalls/amd64-linux.xml"
47 
48 #include "record-full.h"
49 #include "linux-record.h"
50 
51 /* Mapping between the general-purpose registers in `struct user'
52  format and GDB's register cache layout. */
53 
54 /* From <sys/reg.h>. */
56 {
57  10 * 8, /* %rax */
58  5 * 8, /* %rbx */
59  11 * 8, /* %rcx */
60  12 * 8, /* %rdx */
61  13 * 8, /* %rsi */
62  14 * 8, /* %rdi */
63  4 * 8, /* %rbp */
64  19 * 8, /* %rsp */
65  9 * 8, /* %r8 ... */
66  8 * 8,
67  7 * 8,
68  6 * 8,
69  3 * 8,
70  2 * 8,
71  1 * 8,
72  0 * 8, /* ... %r15 */
73  16 * 8, /* %rip */
74  18 * 8, /* %eflags */
75  17 * 8, /* %cs */
76  20 * 8, /* %ss */
77  23 * 8, /* %ds */
78  24 * 8, /* %es */
79  25 * 8, /* %fs */
80  26 * 8, /* %gs */
81  -1, -1, -1, -1, -1, -1, -1, -1,
82  -1, -1, -1, -1, -1, -1, -1, -1,
83  -1, -1, -1, -1, -1, -1, -1, -1,
84  -1, -1, -1, -1, -1, -1, -1, -1, -1,
85  -1, -1, -1, -1, -1, -1, -1, -1,
86  -1, -1, -1, -1, -1, -1, -1, -1,
87  -1, -1, -1, -1, /* MPX registers BND0 ... BND3. */
88  -1, -1, /* MPX registers BNDCFGU and BNDSTATUS. */
89  -1, -1, -1, -1, -1, -1, -1, -1, /* xmm16 ... xmm31 (AVX512) */
90  -1, -1, -1, -1, -1, -1, -1, -1,
91  -1, -1, -1, -1, -1, -1, -1, -1, /* ymm16 ... ymm31 (AVX512) */
92  -1, -1, -1, -1, -1, -1, -1, -1,
93  -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512) */
94  -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm31 (AVX512) */
95  -1, -1, -1, -1, -1, -1, -1, -1,
96  -1, -1, -1, -1, -1, -1, -1, -1,
97  -1, -1, -1, -1, -1, -1, -1, -1,
98  -1, /* PKEYS register pkru */
99 
100  /* End of hardware registers */
101  21 * 8, 22 * 8, /* fs_base and gs_base. */
102  15 * 8 /* "orig_rax" */
103 };
104 
105 
106 /* Support for signal handlers. */
107 
108 #define LINUX_SIGTRAMP_INSN0 0x48 /* mov $NNNNNNNN, %rax */
109 #define LINUX_SIGTRAMP_OFFSET0 0
110 #define LINUX_SIGTRAMP_INSN1 0x0f /* syscall */
111 #define LINUX_SIGTRAMP_OFFSET1 7
112 
114 {
115  /* mov $__NR_rt_sigreturn, %rax */
116  LINUX_SIGTRAMP_INSN0, 0xc7, 0xc0, 0x0f, 0x00, 0x00, 0x00,
117  /* syscall */
119 };
120 
122 {
123  /* mov $__NR_rt_sigreturn, %rax. */
124  LINUX_SIGTRAMP_INSN0, 0xc7, 0xc0, 0x01, 0x02, 0x00, 0x40,
125  /* syscall */
127 };
128 
129 #define LINUX_SIGTRAMP_LEN (sizeof amd64_linux_sigtramp_code)
130 
131 /* If PC is in a sigtramp routine, return the address of the start of
132  the routine. Otherwise, return 0. */
133 
134 static CORE_ADDR
136 {
137  struct gdbarch *gdbarch;
138  const gdb_byte *sigtramp_code;
139  CORE_ADDR pc = get_frame_pc (this_frame);
141 
142  /* We only recognize a signal trampoline if PC is at the start of
143  one of the two instructions. We optimize for finding the PC at
144  the start, as will be the case when the trampoline is not the
145  first frame on the stack. We assume that in the case where the
146  PC is not at the start of the instruction sequence, there will be
147  a few trailing readable bytes on the stack. */
148 
149  if (!safe_frame_unwind_memory (this_frame, pc, buf, sizeof buf))
150  return 0;
151 
152  if (buf[0] != LINUX_SIGTRAMP_INSN0)
153  {
154  if (buf[0] != LINUX_SIGTRAMP_INSN1)
155  return 0;
156 
158  if (!safe_frame_unwind_memory (this_frame, pc, buf, sizeof buf))
159  return 0;
160  }
161 
162  gdbarch = get_frame_arch (this_frame);
163  if (gdbarch_ptr_bit (gdbarch) == 32)
165  else
167  if (memcmp (buf, sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
168  return 0;
169 
170  return pc;
171 }
172 
173 /* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
174  routine. */
175 
176 static int
177 amd64_linux_sigtramp_p (struct frame_info *this_frame)
178 {
179  CORE_ADDR pc = get_frame_pc (this_frame);
180  const char *name;
181 
182  find_pc_partial_function (pc, &name, NULL, NULL);
183 
184  /* If we have NAME, we can optimize the search. The trampoline is
185  named __restore_rt. However, it isn't dynamically exported from
186  the shared C library, so the trampoline may appear to be part of
187  the preceding function. This should always be sigaction,
188  __sigaction, or __libc_sigaction (all aliases to the same
189  function). */
190  if (name == NULL || strstr (name, "sigaction") != NULL)
191  return (amd64_linux_sigtramp_start (this_frame) != 0);
192 
193  return (strcmp ("__restore_rt", name) == 0);
194 }
195 
196 /* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
197 #define AMD64_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 40
198 
199 /* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
200  address of the associated sigcontext structure. */
201 
202 static CORE_ADDR
204 {
205  struct gdbarch *gdbarch = get_frame_arch (this_frame);
206  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
207  CORE_ADDR sp;
208  gdb_byte buf[8];
209 
210  get_frame_register (this_frame, AMD64_RSP_REGNUM, buf);
211  sp = extract_unsigned_integer (buf, 8, byte_order);
212 
213  /* The sigcontext structure is part of the user context. A pointer
214  to the user context is passed as the third argument to the signal
215  handler, i.e. in %rdx. Unfortunately %rdx isn't preserved across
216  function calls so we can't use it. Fortunately the user context
217  is part of the signal frame and the unwound %rsp directly points
218  at it. */
220 }
221 
222 
223 static LONGEST
225  ptid_t ptid)
226 {
228  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
229  /* The content of a register. */
230  gdb_byte buf[8];
231  /* The result. */
232  LONGEST ret;
233 
234  /* Getting the system call number from the register.
235  When dealing with x86_64 architecture, this information
236  is stored at %rax register. */
238 
239  ret = extract_signed_integer (buf, 8, byte_order);
240 
241  return ret;
242 }
243 
244 
245 /* From <asm/sigcontext.h>. */
247 {
248  13 * 8, /* %rax */
249  11 * 8, /* %rbx */
250  14 * 8, /* %rcx */
251  12 * 8, /* %rdx */
252  9 * 8, /* %rsi */
253  8 * 8, /* %rdi */
254  10 * 8, /* %rbp */
255  15 * 8, /* %rsp */
256  0 * 8, /* %r8 */
257  1 * 8, /* %r9 */
258  2 * 8, /* %r10 */
259  3 * 8, /* %r11 */
260  4 * 8, /* %r12 */
261  5 * 8, /* %r13 */
262  6 * 8, /* %r14 */
263  7 * 8, /* %r15 */
264  16 * 8, /* %rip */
265  17 * 8, /* %eflags */
266 
267  /* FIXME: kettenis/2002030531: The registers %cs, %fs and %gs are
268  available in `struct sigcontext'. However, they only occupy two
269  bytes instead of four, which makes using them here rather
270  difficult. Leave them out for now. */
271  -1, /* %cs */
272  -1, /* %ss */
273  -1, /* %ds */
274  -1, /* %es */
275  -1, /* %fs */
276  -1 /* %gs */
277 };
278 
279 static int
281  struct reggroup *group)
282 {
286  return (group == system_reggroup
287  || group == save_reggroup
288  || group == restore_reggroup);
289  return i386_register_reggroup_p (gdbarch, regnum, group);
290 }
291 
292 /* Set the program counter for process PTID to PC. */
293 
294 static void
296 {
298 
299  /* We must be careful with modifying the program counter. If we
300  just interrupted a system call, the kernel might try to restart
301  it when we resume the inferior. On restarting the system call,
302  the kernel will try backing up the program counter even though it
303  no longer points at the system call. This typically results in a
304  SIGSEGV or SIGILL. We can prevent this by writing `-1' in the
305  "orig_rax" pseudo-register.
306 
307  Note that "orig_rax" is saved when setting up a dummy call frame.
308  This means that it is properly restored when that frame is
309  popped, and that the interrupted system call will be restarted
310  when we resume the inferior on return from a function call from
311  within GDB. In all other cases the system call will not be
312  restarted. */
314 }
315 
316 /* Record all registers but IP register for process-record. */
317 
318 static int
320 {
322  return -1;
324  return -1;
326  return -1;
328  return -1;
330  return -1;
332  return -1;
334  return -1;
336  return -1;
338  return -1;
340  return -1;
342  return -1;
344  return -1;
346  return -1;
348  return -1;
350  return -1;
352  return -1;
354  return -1;
355 
356  return 0;
357 }
358 
359 /* amd64_canonicalize_syscall maps from the native amd64 Linux set
360  of syscall ids into a canonical set of syscall ids used by
361  process record. */
362 
363 static enum gdb_syscall
365 {
368 
369  switch (syscall_number) {
370  case amd64_sys_read:
371  case amd64_x32_sys_read:
372  return gdb_sys_read;
373 
374  case amd64_sys_write:
375  case amd64_x32_sys_write:
376  return gdb_sys_write;
377 
378  case amd64_sys_open:
379  case amd64_x32_sys_open:
380  return gdb_sys_open;
381 
382  case amd64_sys_close:
383  case amd64_x32_sys_close:
384  return gdb_sys_close;
385 
386  case amd64_sys_newstat:
388  return gdb_sys_newstat;
389 
390  case amd64_sys_newfstat:
392  return gdb_sys_newfstat;
393 
394  case amd64_sys_newlstat:
396  return gdb_sys_newlstat;
397 
398  case amd64_sys_poll:
399  case amd64_x32_sys_poll:
400  return gdb_sys_poll;
401 
402  case amd64_sys_lseek:
403  case amd64_x32_sys_lseek:
404  return gdb_sys_lseek;
405 
406  case amd64_sys_mmap:
407  case amd64_x32_sys_mmap:
408  return gdb_sys_mmap2;
409 
410  case amd64_sys_mprotect:
412  return gdb_sys_mprotect;
413 
414  case amd64_sys_munmap:
416  return gdb_sys_munmap;
417 
418  case amd64_sys_brk:
419  case amd64_x32_sys_brk:
420  return gdb_sys_brk;
421 
424  return gdb_sys_rt_sigaction;
425 
428  return gdb_sys_rt_sigprocmask;
429 
432  return gdb_sys_rt_sigreturn;
433 
434  case amd64_sys_ioctl:
435  case amd64_x32_sys_ioctl:
436  return gdb_sys_ioctl;
437 
438  case amd64_sys_pread64:
440  return gdb_sys_pread64;
441 
442  case amd64_sys_pwrite64:
444  return gdb_sys_pwrite64;
445 
446  case amd64_sys_readv:
447  case amd64_x32_sys_readv:
448  return gdb_sys_readv;
449 
450  case amd64_sys_writev:
452  return gdb_sys_writev;
453 
454  case amd64_sys_access:
456  return gdb_sys_access;
457 
458  case amd64_sys_pipe:
459  case amd64_x32_sys_pipe:
460  return gdb_sys_pipe;
461 
462  case amd64_sys_select:
464  return gdb_sys_select;
465 
468  return gdb_sys_sched_yield;
469 
470  case amd64_sys_mremap:
472  return gdb_sys_mremap;
473 
474  case amd64_sys_msync:
475  case amd64_x32_sys_msync:
476  return gdb_sys_msync;
477 
478  case amd64_sys_mincore:
480  return gdb_sys_mincore;
481 
482  case amd64_sys_madvise:
484  return gdb_sys_madvise;
485 
486  case amd64_sys_shmget:
488  return gdb_sys_shmget;
489 
490  case amd64_sys_shmat:
491  case amd64_x32_sys_shmat:
492  return gdb_sys_shmat;
493 
494  case amd64_sys_shmctl:
496  return gdb_sys_shmctl;
497 
498  case amd64_sys_dup:
499  case amd64_x32_sys_dup:
500  return gdb_sys_dup;
501 
502  case amd64_sys_dup2:
503  case amd64_x32_sys_dup2:
504  return gdb_sys_dup2;
505 
506  case amd64_sys_pause:
507  case amd64_x32_sys_pause:
508  return gdb_sys_pause;
509 
510  case amd64_sys_nanosleep:
512  return gdb_sys_nanosleep;
513 
514  case amd64_sys_getitimer:
516  return gdb_sys_getitimer;
517 
518  case amd64_sys_alarm:
519  case amd64_x32_sys_alarm:
520  return gdb_sys_alarm;
521 
522  case amd64_sys_setitimer:
524  return gdb_sys_setitimer;
525 
526  case amd64_sys_getpid:
528  return gdb_sys_getpid;
529 
532  return gdb_sys_sendfile64;
533 
534  case amd64_sys_socket:
536  return gdb_sys_socket;
537 
538  case amd64_sys_connect:
540  return gdb_sys_connect;
541 
542  case amd64_sys_accept:
544  return gdb_sys_accept;
545 
546  case amd64_sys_sendto:
548  return gdb_sys_sendto;
549 
550  case amd64_sys_recvfrom:
552  return gdb_sys_recvfrom;
553 
554  case amd64_sys_sendmsg:
556  return gdb_sys_sendmsg;
557 
558  case amd64_sys_recvmsg:
560  return gdb_sys_recvmsg;
561 
562  case amd64_sys_shutdown:
564  return gdb_sys_shutdown;
565 
566  case amd64_sys_bind:
567  case amd64_x32_sys_bind:
568  return gdb_sys_bind;
569 
570  case amd64_sys_listen:
572  return gdb_sys_listen;
573 
576  return gdb_sys_getsockname;
577 
580  return gdb_sys_getpeername;
581 
584  return gdb_sys_socketpair;
585 
588  return gdb_sys_setsockopt;
589 
592  return gdb_sys_getsockopt;
593 
594  case amd64_sys_clone:
595  case amd64_x32_sys_clone:
596  return gdb_sys_clone;
597 
598  case amd64_sys_fork:
599  case amd64_x32_sys_fork:
600  return gdb_sys_fork;
601 
602  case amd64_sys_vfork:
603  case amd64_x32_sys_vfork:
604  return gdb_sys_vfork;
605 
606  case amd64_sys_execve:
608  return gdb_sys_execve;
609 
610  case amd64_sys_exit:
611  case amd64_x32_sys_exit:
612  return gdb_sys_exit;
613 
614  case amd64_sys_wait4:
615  case amd64_x32_sys_wait4:
616  return gdb_sys_wait4;
617 
618  case amd64_sys_kill:
619  case amd64_x32_sys_kill:
620  return gdb_sys_kill;
621 
622  case amd64_sys_uname:
623  case amd64_x32_sys_uname:
624  return gdb_sys_uname;
625 
626  case amd64_sys_semget:
628  return gdb_sys_semget;
629 
630  case amd64_sys_semop:
631  case amd64_x32_sys_semop:
632  return gdb_sys_semop;
633 
634  case amd64_sys_semctl:
636  return gdb_sys_semctl;
637 
638  case amd64_sys_shmdt:
639  case amd64_x32_sys_shmdt:
640  return gdb_sys_shmdt;
641 
642  case amd64_sys_msgget:
644  return gdb_sys_msgget;
645 
646  case amd64_sys_msgsnd:
648  return gdb_sys_msgsnd;
649 
650  case amd64_sys_msgrcv:
652  return gdb_sys_msgrcv;
653 
654  case amd64_sys_msgctl:
656  return gdb_sys_msgctl;
657 
658  case amd64_sys_fcntl:
659  case amd64_x32_sys_fcntl:
660  return gdb_sys_fcntl;
661 
662  case amd64_sys_flock:
663  case amd64_x32_sys_flock:
664  return gdb_sys_flock;
665 
666  case amd64_sys_fsync:
667  case amd64_x32_sys_fsync:
668  return gdb_sys_fsync;
669 
670  case amd64_sys_fdatasync:
672  return gdb_sys_fdatasync;
673 
674  case amd64_sys_truncate:
676  return gdb_sys_truncate;
677 
678  case amd64_sys_ftruncate:
680  return gdb_sys_ftruncate;
681 
682  case amd64_sys_getdents:
684  return gdb_sys_getdents;
685 
686  case amd64_sys_getcwd:
688  return gdb_sys_getcwd;
689 
690  case amd64_sys_chdir:
691  case amd64_x32_sys_chdir:
692  return gdb_sys_chdir;
693 
694  case amd64_sys_fchdir:
696  return gdb_sys_fchdir;
697 
698  case amd64_sys_rename:
700  return gdb_sys_rename;
701 
702  case amd64_sys_mkdir:
703  case amd64_x32_sys_mkdir:
704  return gdb_sys_mkdir;
705 
706  case amd64_sys_rmdir:
707  case amd64_x32_sys_rmdir:
708  return gdb_sys_rmdir;
709 
710  case amd64_sys_creat:
711  case amd64_x32_sys_creat:
712  return gdb_sys_creat;
713 
714  case amd64_sys_link:
715  case amd64_x32_sys_link:
716  return gdb_sys_link;
717 
718  case amd64_sys_unlink:
720  return gdb_sys_unlink;
721 
722  case amd64_sys_symlink:
724  return gdb_sys_symlink;
725 
726  case amd64_sys_readlink:
728  return gdb_sys_readlink;
729 
730  case amd64_sys_chmod:
731  case amd64_x32_sys_chmod:
732  return gdb_sys_chmod;
733 
734  case amd64_sys_fchmod:
736  return gdb_sys_fchmod;
737 
738  case amd64_sys_chown:
739  case amd64_x32_sys_chown:
740  return gdb_sys_chown;
741 
742  case amd64_sys_fchown:
744  return gdb_sys_fchown;
745 
746  case amd64_sys_lchown:
748  return gdb_sys_lchown;
749 
750  case amd64_sys_umask:
751  case amd64_x32_sys_umask:
752  return gdb_sys_umask;
753 
756  return gdb_sys_gettimeofday;
757 
758  case amd64_sys_getrlimit:
760  return gdb_sys_getrlimit;
761 
762  case amd64_sys_getrusage:
764  return gdb_sys_getrusage;
765 
766  case amd64_sys_sysinfo:
768  return gdb_sys_sysinfo;
769 
770  case amd64_sys_times:
771  case amd64_x32_sys_times:
772  return gdb_sys_times;
773 
774  case amd64_sys_ptrace:
776  return gdb_sys_ptrace;
777 
778  case amd64_sys_getuid:
780  return gdb_sys_getuid;
781 
782  case amd64_sys_syslog:
784  return gdb_sys_syslog;
785 
786  case amd64_sys_getgid:
788  return gdb_sys_getgid;
789 
790  case amd64_sys_setuid:
792  return gdb_sys_setuid;
793 
794  case amd64_sys_setgid:
796  return gdb_sys_setgid;
797 
798  case amd64_sys_geteuid:
800  return gdb_sys_geteuid;
801 
802  case amd64_sys_getegid:
804  return gdb_sys_getegid;
805 
806  case amd64_sys_setpgid:
808  return gdb_sys_setpgid;
809 
810  case amd64_sys_getppid:
812  return gdb_sys_getppid;
813 
814  case amd64_sys_getpgrp:
816  return gdb_sys_getpgrp;
817 
818  case amd64_sys_setsid:
820  return gdb_sys_setsid;
821 
822  case amd64_sys_setreuid:
824  return gdb_sys_setreuid;
825 
826  case amd64_sys_setregid:
828  return gdb_sys_setregid;
829 
830  case amd64_sys_getgroups:
832  return gdb_sys_getgroups;
833 
834  case amd64_sys_setgroups:
836  return gdb_sys_setgroups;
837 
838  case amd64_sys_setresuid:
840  return gdb_sys_setresuid;
841 
842  case amd64_sys_getresuid:
844  return gdb_sys_getresuid;
845 
846  case amd64_sys_setresgid:
848  return gdb_sys_setresgid;
849 
850  case amd64_sys_getresgid:
852  return gdb_sys_getresgid;
853 
854  case amd64_sys_getpgid:
856  return gdb_sys_getpgid;
857 
858  case amd64_sys_setfsuid:
860  return gdb_sys_setfsuid;
861 
862  case amd64_sys_setfsgid:
864  return gdb_sys_setfsgid;
865 
866  case amd64_sys_getsid:
868  return gdb_sys_getsid;
869 
870  case amd64_sys_capget:
872  return gdb_sys_capget;
873 
874  case amd64_sys_capset:
876  return gdb_sys_capset;
877 
880  return gdb_sys_rt_sigpending;
881 
885 
889 
892  return gdb_sys_rt_sigsuspend;
893 
896  return gdb_sys_sigaltstack;
897 
898  case amd64_sys_utime:
899  case amd64_x32_sys_utime:
900  return gdb_sys_utime;
901 
902  case amd64_sys_mknod:
903  case amd64_x32_sys_mknod:
904  return gdb_sys_mknod;
905 
908  return gdb_sys_personality;
909 
910  case amd64_sys_ustat:
911  case amd64_x32_sys_ustat:
912  return gdb_sys_ustat;
913 
914  case amd64_sys_statfs:
916  return gdb_sys_statfs;
917 
918  case amd64_sys_fstatfs:
920  return gdb_sys_fstatfs;
921 
922  case amd64_sys_sysfs:
923  case amd64_x32_sys_sysfs:
924  return gdb_sys_sysfs;
925 
928  return gdb_sys_getpriority;
929 
932  return gdb_sys_setpriority;
933 
936  return gdb_sys_sched_setparam;
937 
940  return gdb_sys_sched_getparam;
941 
945 
949 
953 
957 
961 
962  case amd64_sys_mlock:
963  case amd64_x32_sys_mlock:
964  return gdb_sys_mlock;
965 
966  case amd64_sys_munlock:
968  return gdb_sys_munlock;
969 
970  case amd64_sys_mlockall:
972  return gdb_sys_mlockall;
973 
976  return gdb_sys_munlockall;
977 
978  case amd64_sys_vhangup:
980  return gdb_sys_vhangup;
981 
984  return gdb_sys_modify_ldt;
985 
988  return gdb_sys_pivot_root;
989 
990  case amd64_sys_sysctl:
992  return gdb_sys_sysctl;
993 
994  case amd64_sys_prctl:
995  case amd64_x32_sys_prctl:
996  return gdb_sys_prctl;
997 
1000  return gdb_sys_no_syscall; /* Note */
1001 
1002  case amd64_sys_adjtimex:
1004  return gdb_sys_adjtimex;
1005 
1006  case amd64_sys_setrlimit:
1008  return gdb_sys_setrlimit;
1009 
1010  case amd64_sys_chroot:
1011  case amd64_x32_sys_chroot:
1012  return gdb_sys_chroot;
1013 
1014  case amd64_sys_sync:
1015  case amd64_x32_sys_sync:
1016  return gdb_sys_sync;
1017 
1018  case amd64_sys_acct:
1019  case amd64_x32_sys_acct:
1020  return gdb_sys_acct;
1021 
1024  return gdb_sys_settimeofday;
1025 
1026  case amd64_sys_mount:
1027  case amd64_x32_sys_mount:
1028  return gdb_sys_mount;
1029 
1030  case amd64_sys_umount:
1031  case amd64_x32_sys_umount:
1032  return gdb_sys_umount;
1033 
1034  case amd64_sys_swapon:
1035  case amd64_x32_sys_swapon:
1036  return gdb_sys_swapon;
1037 
1038  case amd64_sys_swapoff:
1039  case amd64_x32_sys_swapoff:
1040  return gdb_sys_swapoff;
1041 
1042  case amd64_sys_reboot:
1043  case amd64_x32_sys_reboot:
1044  return gdb_sys_reboot;
1045 
1046  case amd64_sys_sethostname:
1048  return gdb_sys_sethostname;
1049 
1052  return gdb_sys_setdomainname;
1053 
1054  case amd64_sys_iopl:
1055  case amd64_x32_sys_iopl:
1056  return gdb_sys_iopl;
1057 
1058  case amd64_sys_ioperm:
1059  case amd64_x32_sys_ioperm:
1060  return gdb_sys_ioperm;
1061 
1062  case amd64_sys_init_module:
1064  return gdb_sys_init_module;
1065 
1068  return gdb_sys_delete_module;
1069 
1070  case amd64_sys_quotactl:
1072  return gdb_sys_quotactl;
1073 
1074  case amd64_sys_nfsservctl:
1075  return gdb_sys_nfsservctl;
1076 
1077  case amd64_sys_gettid:
1078  case amd64_x32_sys_gettid:
1079  return gdb_sys_gettid;
1080 
1081  case amd64_sys_readahead:
1083  return gdb_sys_readahead;
1084 
1085  case amd64_sys_setxattr:
1087  return gdb_sys_setxattr;
1088 
1089  case amd64_sys_lsetxattr:
1091  return gdb_sys_lsetxattr;
1092 
1093  case amd64_sys_fsetxattr:
1095  return gdb_sys_fsetxattr;
1096 
1097  case amd64_sys_getxattr:
1099  return gdb_sys_getxattr;
1100 
1101  case amd64_sys_lgetxattr:
1103  return gdb_sys_lgetxattr;
1104 
1105  case amd64_sys_fgetxattr:
1107  return gdb_sys_fgetxattr;
1108 
1109  case amd64_sys_listxattr:
1111  return gdb_sys_listxattr;
1112 
1113  case amd64_sys_llistxattr:
1115  return gdb_sys_llistxattr;
1116 
1117  case amd64_sys_flistxattr:
1119  return gdb_sys_flistxattr;
1120 
1121  case amd64_sys_removexattr:
1123  return gdb_sys_removexattr;
1124 
1127  return gdb_sys_lremovexattr;
1128 
1131  return gdb_sys_fremovexattr;
1132 
1133  case amd64_sys_tkill:
1134  case amd64_x32_sys_tkill:
1135  return gdb_sys_tkill;
1136 
1137  case amd64_sys_time:
1138  case amd64_x32_sys_time:
1139  return gdb_sys_time;
1140 
1141  case amd64_sys_futex:
1142  case amd64_x32_sys_futex:
1143  return gdb_sys_futex;
1144 
1148 
1152 
1153  case amd64_sys_io_setup:
1155  return gdb_sys_io_setup;
1156 
1157  case amd64_sys_io_destroy:
1159  return gdb_sys_io_destroy;
1160 
1163  return gdb_sys_io_getevents;
1164 
1165  case amd64_sys_io_submit:
1167  return gdb_sys_io_submit;
1168 
1169  case amd64_sys_io_cancel:
1171  return gdb_sys_io_cancel;
1172 
1175  return gdb_sys_lookup_dcookie;
1176 
1179  return gdb_sys_epoll_create;
1180 
1183  return gdb_sys_remap_file_pages;
1184 
1185  case amd64_sys_getdents64:
1187  return gdb_sys_getdents64;
1188 
1191  return gdb_sys_set_tid_address;
1192 
1195  return gdb_sys_restart_syscall;
1196 
1197  case amd64_sys_semtimedop:
1199  return gdb_sys_semtimedop;
1200 
1201  case amd64_sys_fadvise64:
1203  return gdb_sys_fadvise64;
1204 
1207  return gdb_sys_timer_create;
1208 
1211  return gdb_sys_timer_settime;
1212 
1215  return gdb_sys_timer_gettime;
1216 
1219  return gdb_sys_timer_getoverrun;
1220 
1223  return gdb_sys_timer_delete;
1224 
1227  return gdb_sys_clock_settime;
1228 
1231  return gdb_sys_clock_gettime;
1232 
1235  return gdb_sys_clock_getres;
1236 
1239  return gdb_sys_clock_nanosleep;
1240 
1241  case amd64_sys_exit_group:
1243  return gdb_sys_exit_group;
1244 
1245  case amd64_sys_epoll_wait:
1247  return gdb_sys_epoll_wait;
1248 
1249  case amd64_sys_epoll_ctl:
1251  return gdb_sys_epoll_ctl;
1252 
1253  case amd64_sys_tgkill:
1254  case amd64_x32_sys_tgkill:
1255  return gdb_sys_tgkill;
1256 
1257  case amd64_sys_utimes:
1258  case amd64_x32_sys_utimes:
1259  return gdb_sys_utimes;
1260 
1261  case amd64_sys_mbind:
1262  case amd64_x32_sys_mbind:
1263  return gdb_sys_mbind;
1264 
1267  return gdb_sys_set_mempolicy;
1268 
1271  return gdb_sys_get_mempolicy;
1272 
1273  case amd64_sys_mq_open:
1274  case amd64_x32_sys_mq_open:
1275  return gdb_sys_mq_open;
1276 
1277  case amd64_sys_mq_unlink:
1279  return gdb_sys_mq_unlink;
1280 
1283  return gdb_sys_mq_timedsend;
1284 
1287  return gdb_sys_mq_timedreceive;
1288 
1289  case amd64_sys_mq_notify:
1291  return gdb_sys_mq_notify;
1292 
1295  return gdb_sys_mq_getsetattr;
1296 
1297  case amd64_sys_kexec_load:
1299  return gdb_sys_kexec_load;
1300 
1301  case amd64_sys_waitid:
1302  case amd64_x32_sys_waitid:
1303  return gdb_sys_waitid;
1304 
1305  case amd64_sys_add_key:
1306  case amd64_x32_sys_add_key:
1307  return gdb_sys_add_key;
1308 
1309  case amd64_sys_request_key:
1311  return gdb_sys_request_key;
1312 
1313  case amd64_sys_keyctl:
1314  case amd64_x32_sys_keyctl:
1315  return gdb_sys_keyctl;
1316 
1317  case amd64_sys_ioprio_set:
1319  return gdb_sys_ioprio_set;
1320 
1321  case amd64_sys_ioprio_get:
1323  return gdb_sys_ioprio_get;
1324 
1327  return gdb_sys_inotify_init;
1328 
1332 
1335  return gdb_sys_inotify_rm_watch;
1336 
1339  return gdb_sys_migrate_pages;
1340 
1341  case amd64_sys_openat:
1342  case amd64_x32_sys_openat:
1343  return gdb_sys_openat;
1344 
1345  case amd64_sys_mkdirat:
1346  case amd64_x32_sys_mkdirat:
1347  return gdb_sys_mkdirat;
1348 
1349  case amd64_sys_mknodat:
1350  case amd64_x32_sys_mknodat:
1351  return gdb_sys_mknodat;
1352 
1353  case amd64_sys_fchownat:
1355  return gdb_sys_fchownat;
1356 
1357  case amd64_sys_futimesat:
1359  return gdb_sys_futimesat;
1360 
1361  case amd64_sys_newfstatat:
1363  return gdb_sys_newfstatat;
1364 
1365  case amd64_sys_unlinkat:
1367  return gdb_sys_unlinkat;
1368 
1369  case amd64_sys_renameat:
1371  return gdb_sys_renameat;
1372 
1373  case amd64_sys_linkat:
1374  case amd64_x32_sys_linkat:
1375  return gdb_sys_linkat;
1376 
1377  case amd64_sys_symlinkat:
1379  return gdb_sys_symlinkat;
1380 
1381  case amd64_sys_readlinkat:
1383  return gdb_sys_readlinkat;
1384 
1385  case amd64_sys_fchmodat:
1387  return gdb_sys_fchmodat;
1388 
1389  case amd64_sys_faccessat:
1391  return gdb_sys_faccessat;
1392 
1393  case amd64_sys_pselect6:
1395  return gdb_sys_pselect6;
1396 
1397  case amd64_sys_ppoll:
1398  case amd64_x32_sys_ppoll:
1399  return gdb_sys_ppoll;
1400 
1401  case amd64_sys_unshare:
1402  case amd64_x32_sys_unshare:
1403  return gdb_sys_unshare;
1404 
1407  return gdb_sys_set_robust_list;
1408 
1411  return gdb_sys_get_robust_list;
1412 
1413  case amd64_sys_splice:
1414  case amd64_x32_sys_splice:
1415  return gdb_sys_splice;
1416 
1417  case amd64_sys_tee:
1418  case amd64_x32_sys_tee:
1419  return gdb_sys_tee;
1420 
1423  return gdb_sys_sync_file_range;
1424 
1425  case amd64_sys_vmsplice:
1427  return gdb_sys_vmsplice;
1428 
1429  case amd64_sys_move_pages:
1431  return gdb_sys_move_pages;
1432 
1433  default:
1434  return gdb_sys_no_syscall;
1435  }
1436 
1438 }
1439 
1440 /* Parse the arguments of current system call instruction and record
1441  the values of the registers and memory that will be changed into
1442  "record_full_arch_list". This instruction is "syscall".
1443 
1444  Return -1 if something wrong. */
1445 
1448 
1449 #define RECORD_ARCH_GET_FS 0x1003
1450 #define RECORD_ARCH_GET_GS 0x1004
1451 
1452 static int
1454  struct linux_record_tdep *linux_record_tdep_p)
1455 {
1456  int ret;
1457  ULONGEST syscall_native;
1458  enum gdb_syscall syscall_gdb = gdb_sys_no_syscall;
1459 
1461 
1462  switch (syscall_native)
1463  {
1467  return -1;
1468  return 0;
1469  break;
1470 
1471  case amd64_sys_arch_prctl:
1473  {
1474  ULONGEST arg3;
1475  regcache_raw_read_unsigned (regcache, linux_record_tdep_p->arg3,
1476  &arg3);
1478  {
1479  CORE_ADDR addr;
1480 
1482  linux_record_tdep_p->arg2,
1483  &addr);
1485  (addr, linux_record_tdep_p->size_ulong))
1486  return -1;
1487  }
1488  goto record_regs;
1489  }
1490  break;
1491  }
1492 
1493  syscall_gdb
1494  = amd64_canonicalize_syscall ((enum amd64_syscall) syscall_native);
1495 
1496  if (syscall_gdb == gdb_sys_no_syscall)
1497  {
1498  printf_unfiltered (_("Process record and replay target doesn't "
1499  "support syscall number %s\n"),
1500  pulongest (syscall_native));
1501  return -1;
1502  }
1503  else
1504  {
1505  ret = record_linux_system_call (syscall_gdb, regcache,
1506  linux_record_tdep_p);
1507  if (ret)
1508  return ret;
1509  }
1510 
1511  record_regs:
1512  /* Record the return value of the system call. */
1514  return -1;
1516  return -1;
1517 
1518  return 0;
1519 }
1520 
1521 static int
1523 {
1526 }
1527 
1528 static int
1530 {
1533 }
1534 
1535 #define AMD64_LINUX_redzone 128
1536 #define AMD64_LINUX_xstate 512
1537 #define AMD64_LINUX_frame_size 560
1538 
1539 static int
1541  struct regcache *regcache,
1542  enum gdb_signal signal)
1543 {
1544  ULONGEST rsp;
1545 
1547  return -1;
1548 
1550  return -1;
1551 
1552  /* Record the change in the stack. */
1554  /* redzone
1555  sp -= 128; */
1556  rsp -= AMD64_LINUX_redzone;
1557  /* This is for xstate.
1558  sp -= sizeof (struct _fpstate); */
1559  rsp -= AMD64_LINUX_xstate;
1560  /* This is for frame_size.
1561  sp -= sizeof (struct rt_sigframe); */
1562  rsp -= AMD64_LINUX_frame_size;
1566  return -1;
1567 
1569  return -1;
1570 
1571  return 0;
1572 }
1573 
1574 const target_desc *
1575 amd64_linux_read_description (uint64_t xcr0_features_bit, bool is_x32)
1576 {
1577  static target_desc *amd64_linux_tdescs \
1578  [2/*AVX*/][2/*MPX*/][2/*AVX512*/][2/*PKRU*/] = {};
1579  static target_desc *x32_linux_tdescs[2/*AVX*/][2/*AVX512*/] = {};
1580 
1581  target_desc **tdesc;
1582 
1583  if (is_x32)
1584  {
1585  tdesc = &x32_linux_tdescs[(xcr0_features_bit & X86_XSTATE_AVX) ? 1 : 0 ]
1586  [(xcr0_features_bit & X86_XSTATE_AVX512) ? 1 : 0];
1587  }
1588  else
1589  {
1590  tdesc = &amd64_linux_tdescs[(xcr0_features_bit & X86_XSTATE_AVX) ? 1 : 0]
1591  [(xcr0_features_bit & X86_XSTATE_MPX) ? 1 : 0]
1592  [(xcr0_features_bit & X86_XSTATE_AVX512) ? 1 : 0]
1593  [(xcr0_features_bit & X86_XSTATE_PKRU) ? 1 : 0];
1594  }
1595 
1596  if (*tdesc == NULL)
1597  *tdesc = amd64_create_target_description (xcr0_features_bit, is_x32, true);
1598 
1599  return *tdesc;
1600 }
1601 
1602 /* Get Linux/x86 target description from core dump. */
1603 
1604 static const struct target_desc *
1606  struct target_ops *target,
1607  bfd *abfd)
1608 {
1609  /* Linux/x86-64. */
1610  uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
1611 
1613  gdbarch_ptr_bit (gdbarch) == 32);
1614 }
1615 
1616 /* Similar to amd64_supply_fpregset, but use XSAVE extended state. */
1617 
1618 static void
1620  struct regcache *regcache, int regnum,
1621  const void *xstateregs, size_t len)
1622 {
1623  amd64_supply_xsave (regcache, regnum, xstateregs);
1624 }
1625 
1626 /* Similar to amd64_collect_fpregset, but use XSAVE extended state. */
1627 
1628 static void
1630  const struct regcache *regcache,
1631  int regnum, void *xstateregs, size_t len)
1632 {
1633  amd64_collect_xsave (regcache, regnum, xstateregs, 1);
1634 }
1635 
1636 static const struct regset amd64_linux_xstateregset =
1637  {
1638  NULL,
1641  };
1642 
1643 /* Iterate over core file register note sections. */
1644 
1645 static void
1648  void *cb_data,
1649  const struct regcache *regcache)
1650 {
1651  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1652 
1653  cb (".reg", 27 * 8, &i386_gregset, NULL, cb_data);
1654  cb (".reg2", 512, &amd64_fpregset, NULL, cb_data);
1655  cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0),
1656  &amd64_linux_xstateregset, "XSAVE extended state", cb_data);
1657 }
1658 
1659 /* The instruction sequences used in x86_64 machines for a
1660  disabled is-enabled probe. */
1661 
1663  /* xor %rax, %rax */ 0x48, 0x33, 0xc0,
1664  /* nop */ 0x90,
1665  /* nop */ 0x90
1666 };
1667 
1669  /* xor %rax, %rax */ 0x48, 0x33, 0xc0,
1670  /* ret */ 0xc3,
1671  /* nop */ 0x90
1672 };
1673 
1674 /* The instruction sequence used in x86_64 machines for enabling a
1675  DTrace is-enabled probe. */
1676 
1678  /* mov $0x1, %eax */ 0xb8, 0x01, 0x00, 0x00, 0x00
1679 };
1680 
1681 /* The instruction sequence used in x86_64 machines for disabling a
1682  DTrace is-enabled probe. */
1683 
1685  /* xor %rax, %rax; nop; nop */ 0x48, 0x33, 0xC0, 0x90, 0x90
1686 };
1687 
1688 /* Implementation of `gdbarch_dtrace_probe_is_enabled', as defined in
1689  gdbarch.h. */
1690 
1691 static int
1693 {
1694  gdb_byte buf[5];
1695 
1696  /* This function returns 1 if the instructions at ADDR do _not_
1697  follow any of the amd64_dtrace_disabled_probe_sequence_*
1698  patterns.
1699 
1700  Note that ADDR is offset 3 bytes from the beginning of these
1701  sequences. */
1702 
1703  read_code (addr - 3, buf, 5);
1704  return (memcmp (buf, amd64_dtrace_disabled_probe_sequence_1, 5) != 0
1705  && memcmp (buf, amd64_dtrace_disabled_probe_sequence_2, 5) != 0);
1706 }
1707 
1708 /* Implementation of `gdbarch_dtrace_enable_probe', as defined in
1709  gdbarch.h. */
1710 
1711 static void
1713 {
1714  /* Note also that ADDR is offset 3 bytes from the beginning of
1715  amd64_dtrace_enable_probe_sequence. */
1716 
1718 }
1719 
1720 /* Implementation of `gdbarch_dtrace_disable_probe', as defined in
1721  gdbarch.h. */
1722 
1723 static void
1725 {
1726  /* Note also that ADDR is offset 3 bytes from the beginning of
1727  amd64_dtrace_disable_probe_sequence. */
1728 
1730 }
1731 
1732 /* Implementation of `gdbarch_dtrace_parse_probe_argument', as defined
1733  in gdbarch.h. */
1734 
1735 static void
1737  struct parser_state *pstate,
1738  int narg)
1739 {
1740  struct stoken str;
1741 
1742  /* DTrace probe arguments can be found on the ABI-defined places for
1743  regular arguments at the current PC. The probe abstraction
1744  currently supports up to 12 arguments for probes. */
1745 
1746  if (narg < 6)
1747  {
1748  static const int arg_reg_map[6] =
1749  {
1750  AMD64_RDI_REGNUM, /* Arg 1. */
1751  AMD64_RSI_REGNUM, /* Arg 2. */
1752  AMD64_RDX_REGNUM, /* Arg 3. */
1753  AMD64_RCX_REGNUM, /* Arg 4. */
1754  AMD64_R8_REGNUM, /* Arg 5. */
1755  AMD64_R9_REGNUM /* Arg 6. */
1756  };
1757  int regno = arg_reg_map[narg];
1758  const char *regname = user_reg_map_regnum_to_name (gdbarch, regno);
1759 
1760  write_exp_elt_opcode (pstate, OP_REGISTER);
1761  str.ptr = regname;
1762  str.length = strlen (regname);
1763  write_exp_string (pstate, str);
1764  write_exp_elt_opcode (pstate, OP_REGISTER);
1765  }
1766  else
1767  {
1768  /* Additional arguments are passed on the stack. */
1769  const char *regname = user_reg_map_regnum_to_name (gdbarch, AMD64_RSP_REGNUM);
1770 
1771  /* Displacement. */
1772  write_exp_elt_opcode (pstate, OP_LONG);
1773  write_exp_elt_type (pstate, builtin_type (gdbarch)->builtin_long);
1774  write_exp_elt_longcst (pstate, narg - 6);
1775  write_exp_elt_opcode (pstate, OP_LONG);
1776 
1777  /* Register: SP. */
1778  write_exp_elt_opcode (pstate, OP_REGISTER);
1779  str.ptr = regname;
1780  str.length = strlen (regname);
1781  write_exp_string (pstate, str);
1782  write_exp_elt_opcode (pstate, OP_REGISTER);
1783 
1784  write_exp_elt_opcode (pstate, BINOP_ADD);
1785 
1786  /* Cast to long. */
1787  write_exp_elt_opcode (pstate, UNOP_CAST);
1789  lookup_pointer_type (builtin_type (gdbarch)->builtin_long));
1790  write_exp_elt_opcode (pstate, UNOP_CAST);
1791 
1792  write_exp_elt_opcode (pstate, UNOP_IND);
1793  }
1794 }
1795 
1796 static void
1798 {
1799  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1800 
1801  linux_init_abi (info, gdbarch);
1802 
1806  tdep->sc_num_regs = ARRAY_SIZE (amd64_linux_sc_reg_offset);
1807 
1809 
1810  /* Add the %orig_rax register used for syscall restarting. */
1812 
1814 
1815  /* Functions for 'catch syscall'. */
1819 
1820  /* Enable TLS support. */
1823 
1824  /* GNU/Linux uses SVR4-style shared libraries. */
1826 
1827  /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
1829 
1830  /* Iterate over core file register note sections. */
1833 
1836 
1837  /* Displaced stepping. */
1843 
1846 
1850 }
1851 
1852 static void
1854 {
1855  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1856  struct tdesc_arch_data *tdesc_data = info.tdesc_data;
1857  const struct tdesc_feature *feature;
1858  int valid_p;
1859 
1861 
1863  tdep->gregset_num_regs = ARRAY_SIZE (amd64_linux_gregset_reg_offset);
1864  tdep->sizeof_gregset = 27 * 8;
1865 
1866  amd64_init_abi (info, gdbarch,
1868 
1869  const target_desc *tdesc = tdep->tdesc;
1870 
1871  /* Reserve a number for orig_rax. */
1873 
1874  feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
1875  if (feature == NULL)
1876  return;
1877 
1878  valid_p = tdesc_numbered_register (feature, tdesc_data,
1880  "orig_rax");
1881  if (!valid_p)
1882  return;
1883 
1885 
1886  /* Initialize the amd64_linux_record_tdep. */
1887  /* These values are the size of the type that will be used in a system
1888  call. They are obtained from Linux Kernel source. */
1897  /* ADM64 doesn't need this size because it doesn't have sys_sigaction
1898  but sys_rt_sigaction. */
1900  /* ADM64 doesn't need this size because it doesn't have sys_sigpending
1901  but sys_rt_sigpending. */
1907  /* ADM64 doesn't need this size because it doesn't have sys_getgroups16
1908  but sys_getgroups. */
1910  /* ADM64 doesn't need this size because it doesn't have sys_getresuid16
1911  but sys_getresuid. */
1914  /* ADM64 doesn't need this size because it doesn't have sys_readdir. */
1969 
1970  /* These values are the second argument of system call "sys_fcntl"
1971  and "sys_fcntl64". They are obtained from Linux Kernel source. */
1976 
1983 
1984  /* These values are the second argument of system call "sys_ioctl".
1985  They are obtained from Linux Kernel source. */
2052 
2054 
2055  /* GNU/Linux uses SVR4-style shared libraries. */
2058 
2059  /* Register DTrace handlers. */
2064 }
2065 
2066 static void
2068 {
2069  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2070  struct tdesc_arch_data *tdesc_data = info.tdesc_data;
2071  const struct tdesc_feature *feature;
2072  int valid_p;
2073 
2075 
2077  tdep->gregset_num_regs = ARRAY_SIZE (amd64_linux_gregset_reg_offset);
2078  tdep->sizeof_gregset = 27 * 8;
2079 
2080  amd64_x32_init_abi (info, gdbarch,
2082  true));
2083 
2084  /* Reserve a number for orig_rax. */
2086 
2087  const target_desc *tdesc = tdep->tdesc;
2088 
2089  feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
2090  if (feature == NULL)
2091  return;
2092 
2093  valid_p = tdesc_numbered_register (feature, tdesc_data,
2095  "orig_rax");
2096  if (!valid_p)
2097  return;
2098 
2100 
2101  /* Initialize the amd64_x32_linux_record_tdep. */
2102  /* These values are the size of the type that will be used in a system
2103  call. They are obtained from Linux Kernel source. */
2112  /* ADM64 doesn't need this size because it doesn't have sys_sigaction
2113  but sys_rt_sigaction. */
2115  /* ADM64 doesn't need this size because it doesn't have sys_sigpending
2116  but sys_rt_sigpending. */
2122  /* ADM64 doesn't need this size because it doesn't have sys_getgroups16
2123  but sys_getgroups. */
2125  /* ADM64 doesn't need this size because it doesn't have sys_getresuid16
2126  but sys_getresuid. */
2129  /* ADM64 doesn't need this size because it doesn't have sys_readdir. */
2184 
2185  /* These values are the second argument of system call "sys_fcntl"
2186  and "sys_fcntl64". They are obtained from Linux Kernel source. */
2191 
2198 
2199  /* These values are the second argument of system call "sys_ioctl".
2200  They are obtained from Linux Kernel source. */
2266 
2268 
2269  /* GNU/Linux uses SVR4-style shared libraries. */
2272 }
2273 
2274 void
2276 {
2277  gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
2279  gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x64_32,
2281 
2282 #if GDB_SELF_TEST
2283  struct
2284  {
2285  const char *xml;
2286  uint64_t mask;
2287  } xml_masks[] = {
2288  { "i386/amd64-linux.xml", X86_XSTATE_SSE_MASK },
2289  { "i386/amd64-avx-linux.xml", X86_XSTATE_AVX_MASK },
2290  { "i386/amd64-mpx-linux.xml", X86_XSTATE_MPX_MASK },
2291  { "i386/amd64-avx-mpx-linux.xml", X86_XSTATE_AVX_MPX_MASK },
2292  { "i386/amd64-avx-avx512-linux.xml", X86_XSTATE_AVX_AVX512_MASK },
2293  { "i386/amd64-avx-mpx-avx512-pku-linux.xml",
2295  { "i386/x32-linux.xml", X86_XSTATE_SSE_MASK },
2296  { "i386/x32-avx-linux.xml", X86_XSTATE_AVX_MASK },
2297  { "i386/x32-avx-avx512-linux.xml", X86_XSTATE_AVX_AVX512_MASK },
2298  };
2299 
2300  for (auto &a : xml_masks)
2301  {
2302  auto tdesc = amd64_linux_read_description (a.mask,
2303  startswith (a.xml,
2304  "i386/x32"));
2305 
2306  selftests::record_xml_tdesc (a.xml, tdesc);
2307  }
2308 #endif /* GDB_SELF_TEST */
2309 }
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 X86_XSTATE_AVX_MASK
Definition: x86-xstate.h:43
const char * user_reg_map_regnum_to_name(struct gdbarch *gdbarch, int regnum)
Definition: user-regs.c:193
static void amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch)
static void amd64_linux_supply_xstateregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *xstateregs, size_t len)
void amd64_x32_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch, const target_desc *default_tdesc)
Definition: amd64-tdep.c:3229
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
static void amd64_x32_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
#define LINUX_SIGTRAMP_OFFSET1
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
const gdb_byte amd64_dtrace_disabled_probe_sequence_2[]
#define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
Definition: diagnostics.h:60
#define X86_XSTATE_SSE_MASK
Definition: x86-xstate.h:42
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
struct link_map_offsets * svr4_lp64_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3214
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
const char * ptr
Definition: parser-defs.h:91
uint64_t i386_linux_core_read_xcr0(bfd *abfd)
struct displaced_step_closure * amd64_displaced_step_copy_insn(struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs)
Definition: amd64-tdep.c:1416
#define AMD64_LINUX_redzone
void amd64_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch, const target_desc *default_tdesc)
Definition: amd64-tdep.c:3037
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
int gdbarch_int_bit(struct gdbarch *gdbarch)
Definition: gdbarch.c:1579
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
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
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
static int amd64_x32_linux_syscall_record(struct regcache *regcache)
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
CORE_ADDR(* sigcontext_addr)(struct frame_info *)
Definition: alpha-tdep.h:82
int gdbarch_long_bit(struct gdbarch *gdbarch)
Definition: gdbarch.c:1596
static void amd64_dtrace_enable_probe(struct gdbarch *gdbarch, CORE_ADDR addr)
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3183
amd64_syscall
void set_gdbarch_dtrace_probe_is_enabled(struct gdbarch *gdbarch, gdbarch_dtrace_probe_is_enabled_ftype dtrace_probe_is_enabled)
Definition: gdbarch.c:4547
struct reggroup *const restore_reggroup
Definition: reggroups.c:320
#define LINUX_SIGTRAMP_INSN1
#define _(String)
Definition: gdb_locale.h:35
#define AMD64_LINUX_xstate
const gdb_byte amd64_dtrace_disable_probe_sequence[]
static struct linux_record_tdep amd64_x32_linux_record_tdep
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1491
static const unsigned short sigtramp_code[]
Definition: cris-tdep.c:175
void _initialize_amd64_linux_tdep(void)
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
static LONGEST amd64_linux_get_syscall_number(struct gdbarch *gdbarch, ptid_t ptid)
struct type * x86_linux_get_siginfo_type(struct gdbarch *gdbarch)
CORE_ADDR svr4_fetch_objfile_link_map(struct objfile *objfile)
Definition: solib-svr4.c:1579
static int amd64_all_but_ip_registers_record(struct regcache *regcache)
Definition: regset.h:34
int tdesc_numbered_register(const struct tdesc_feature *feature, struct tdesc_arch_data *data, int regno, const char *name)
const gdb_byte amd64_dtrace_enable_probe_sequence[]
const char *const name
Definition: aarch64-tdep.c:76
#define X86_XSTATE_PKRU
Definition: x86-xstate.h:38
void write_exp_elt_longcst(struct parser_state *ps, LONGEST expelt)
Definition: parse.c:255
target_desc * amd64_create_target_description(uint64_t xcr0, bool is_x32, bool is_linux)
Definition: amd64.c:38
#define AMD64_LINUX_UCONTEXT_SIGCONTEXT_OFFSET
void set_gdbarch_dtrace_disable_probe(struct gdbarch *gdbarch, gdbarch_dtrace_disable_probe_ftype dtrace_disable_probe)
Definition: gdbarch.c:4595
static int amd64_linux_register_reggroup_p(struct gdbarch *gdbarch, int regnum, struct reggroup *group)
#define X86_XSTATE_AVX_AVX512_MASK
Definition: x86-xstate.h:46
static void amd64_dtrace_disable_probe(struct gdbarch *gdbarch, CORE_ADDR addr)
static struct parser_state * pstate
Definition: ada-exp.c:98
static void amd64_linux_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
#define AMD64_LINUX_ORIG_RAX_REGNUM
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 const gdb_byte amd64_linux_sigtramp_code[]
#define DIAGNOSTIC_PUSH
Definition: diagnostics.h:29
Definition: ptid.h:35
static void amd64_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
#define AMD64_LINUX_frame_size
void amd64_supply_xsave(struct regcache *regcache, int regnum, const void *xsave)
Definition: amd64-tdep.c:3327
static int amd64_linux_record_signal(struct gdbarch *gdbarch, struct regcache *regcache, enum gdb_signal signal)
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1509
#define TARGET_CHAR_BIT
Definition: host-defs.h:29
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
Definition: solib-svr4.c:3137
#define XML_SYSCALL_FILENAME_AMD64
int find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr)
Definition: blockframe.c:320
void read_code(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:274
int amd64_linux_gregset_reg_offset[]
static int startswith(const char *string, const char *pattern)
Definition: common-utils.h:107
const struct regset i386_gregset
Definition: i386-tdep.c:3928
#define LINUX_SIGTRAMP_LEN
static int amd64_linux_sc_reg_offset[]
const target_desc * amd64_linux_read_description(uint64_t xcr0_features_bit, bool is_x32)
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
static int amd64_linux_syscall_record_common(struct regcache *regcache, struct linux_record_tdep *linux_record_tdep_p)
const gdb_byte amd64_dtrace_disabled_probe_sequence_1[]
static const struct target_desc * amd64_linux_core_read_description(struct gdbarch *gdbarch, struct target_ops *target, bfd *abfd)
static const gdb_byte amd64_x32_linux_sigtramp_code[]
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
static void amd64_dtrace_parse_probe_argument(struct gdbarch *gdbarch, struct parser_state *pstate, int narg)
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
int * gregset_reg_offset
Definition: i386-tdep.h:61
const struct regset amd64_fpregset
Definition: amd64-tdep.c:2989
#define RECORD_ARCH_GET_GS
void write_exp_elt_opcode(struct parser_state *ps, enum exp_opcode expelt)
Definition: parse.c:205
bfd_byte gdb_byte
Definition: common-types.h:38
int(* sigtramp_p)(struct frame_info *)
Definition: i386-tdep.h:220
static CORE_ADDR amd64_linux_sigtramp_start(struct frame_info *this_frame)
static const struct regset amd64_linux_xstateregset
void set_gdbarch_displaced_step_copy_insn(struct gdbarch *gdbarch, gdbarch_displaced_step_copy_insn_ftype displaced_step_copy_insn)
Definition: gdbarch.c:3940
uint64_t xcr0
Definition: i386-tdep.h:141
#define AMD64_LINUX_NUM_REGS
static int amd64_linux_syscall_record(struct regcache *regcache)
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 set_gdbarch_dtrace_enable_probe(struct gdbarch *gdbarch, gdbarch_dtrace_enable_probe_ftype dtrace_enable_probe)
Definition: gdbarch.c:4571
#define LINUX_SIGTRAMP_INSN0
#define RECORD_ARCH_GET_FS
static CORE_ADDR amd64_linux_sigcontext_addr(struct frame_info *this_frame)
void set_gdbarch_get_syscall_number(struct gdbarch *gdbarch, gdbarch_get_syscall_number_ftype get_syscall_number)
Definition: gdbarch.c:4281
void get_frame_register(struct frame_info *frame, int regnum, gdb_byte *buf)
Definition: frame.c:1165
static int amd64_linux_sigtramp_p(struct frame_info *this_frame)
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
const struct target_desc * tdesc
Definition: i386-tdep.h:204
#define X86_XSTATE_MPX
Definition: x86-xstate.h:29
int * sc_reg_offset
Definition: i386-tdep.h:226
unsigned long long ULONGEST
Definition: common-types.h:53
static void amd64_linux_write_pc(struct regcache *regcache, CORE_ADDR pc)
const struct tdesc_feature * tdesc_find_feature(const struct target_desc *target_desc, const char *name)
void set_gdbarch_dtrace_parse_probe_argument(struct gdbarch *gdbarch, gdbarch_dtrace_parse_probe_argument_ftype dtrace_parse_probe_argument)
Definition: gdbarch.c:4523
static enum gdb_syscall amd64_canonicalize_syscall(enum amd64_syscall syscall_number)
void amd64_displaced_step_fixup(struct gdbarch *gdbarch, struct displaced_step_closure *dsc_, CORE_ADDR from, CORE_ADDR to, struct regcache *regs)
Definition: amd64-tdep.c:1622
#define X86_XSTATE_AVX_MPX_MASK
Definition: x86-xstate.h:45
void amd64_collect_xsave(const struct regcache *regcache, int regnum, void *xsave, int gcore)
Definition: amd64-tdep.c:3376
struct reggroup *const save_reggroup
Definition: reggroups.c:319
static struct linux_record_tdep amd64_linux_record_tdep
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
void write_memory(CORE_ADDR memaddr, const bfd_byte *myaddr, ssize_t len)
Definition: corefile.c:394
static struct gdbarch_data * tdesc_data
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
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
#define DIAGNOSTIC_POP
Definition: diagnostics.h:30
void write_exp_string(struct parser_state *ps, struct stoken str)
Definition: parse.c:318
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
void write_exp_elt_type(struct parser_state *ps, struct type *expelt)
Definition: parse.c:277
struct type * lookup_pointer_type(struct type *type)
Definition: gdbtypes.c:381
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
int length
Definition: parser-defs.h:93
static void amd64_linux_collect_xstateregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *xstateregs, size_t len)
static int amd64_dtrace_probe_is_enabled(struct gdbarch *gdbarch, CORE_ADDR addr)
#define X86_XSTATE_ALL_MASK
Definition: x86-xstate.h:50