1 /* Target-dependent code for GNU/Linux x86-64.
3 Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Jiri Smid, SuSE Labs.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
30 #include "reggroups.h"
31 #include "amd64-linux-tdep.h"
32 #include "linux-tdep.h"
34 #include "gdb_string.h"
36 #include "amd64-tdep.h"
37 #include "solib-svr4.h"
38 #include "xml-syscall.h"
40 /* The syscall's XML filename for i386. */
41 #define XML_SYSCALL_FILENAME_AMD64 "syscalls/amd64-linux.xml"
44 #include "linux-record.h"
46 /* Mapping between the general-purpose registers in `struct user'
47 format and GDB's register cache layout. */
49 /* From <sys/reg.h>. */
50 static int amd64_linux_gregset_reg_offset[] =
79 /* Support for signal handlers. */
81 #define LINUX_SIGTRAMP_INSN0 0x48 /* mov $NNNNNNNN, %rax */
82 #define LINUX_SIGTRAMP_OFFSET0 0
83 #define LINUX_SIGTRAMP_INSN1 0x0f /* syscall */
84 #define LINUX_SIGTRAMP_OFFSET1 7
86 static const gdb_byte linux_sigtramp_code[] =
88 /* mov $__NR_rt_sigreturn, %rax */
89 LINUX_SIGTRAMP_INSN0, 0xc7, 0xc0, 0x0f, 0x00, 0x00, 0x00,
91 LINUX_SIGTRAMP_INSN1, 0x05
94 #define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
96 /* If PC is in a sigtramp routine, return the address of the start of
97 the routine. Otherwise, return 0. */
100 amd64_linux_sigtramp_start (struct frame_info *this_frame)
102 CORE_ADDR pc = get_frame_pc (this_frame);
103 gdb_byte buf[LINUX_SIGTRAMP_LEN];
105 /* We only recognize a signal trampoline if PC is at the start of
106 one of the two instructions. We optimize for finding the PC at
107 the start, as will be the case when the trampoline is not the
108 first frame on the stack. We assume that in the case where the
109 PC is not at the start of the instruction sequence, there will be
110 a few trailing readable bytes on the stack. */
112 if (!safe_frame_unwind_memory (this_frame, pc, buf, sizeof buf))
115 if (buf[0] != LINUX_SIGTRAMP_INSN0)
117 if (buf[0] != LINUX_SIGTRAMP_INSN1)
120 pc -= LINUX_SIGTRAMP_OFFSET1;
121 if (!safe_frame_unwind_memory (this_frame, pc, buf, sizeof buf))
125 if (memcmp (buf, linux_sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
131 /* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
135 amd64_linux_sigtramp_p (struct frame_info *this_frame)
137 CORE_ADDR pc = get_frame_pc (this_frame);
140 find_pc_partial_function (pc, &name, NULL, NULL);
142 /* If we have NAME, we can optimize the search. The trampoline is
143 named __restore_rt. However, it isn't dynamically exported from
144 the shared C library, so the trampoline may appear to be part of
145 the preceding function. This should always be sigaction,
146 __sigaction, or __libc_sigaction (all aliases to the same
148 if (name == NULL || strstr (name, "sigaction") != NULL)
149 return (amd64_linux_sigtramp_start (this_frame) != 0);
151 return (strcmp ("__restore_rt", name) == 0);
154 /* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
155 #define AMD64_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 40
157 /* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
158 address of the associated sigcontext structure. */
161 amd64_linux_sigcontext_addr (struct frame_info *this_frame)
163 struct gdbarch *gdbarch = get_frame_arch (this_frame);
164 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
168 get_frame_register (this_frame, AMD64_RSP_REGNUM, buf);
169 sp = extract_unsigned_integer (buf, 8, byte_order);
171 /* The sigcontext structure is part of the user context. A pointer
172 to the user context is passed as the third argument to the signal
173 handler, i.e. in %rdx. Unfortunately %rdx isn't preserved across
174 function calls so we can't use it. Fortunately the user context
175 is part of the signal frame and the unwound %rsp directly points
177 return sp + AMD64_LINUX_UCONTEXT_SIGCONTEXT_OFFSET;
182 amd64_linux_get_syscall_number (struct gdbarch *gdbarch,
185 struct regcache *regcache = get_thread_regcache (ptid);
186 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
187 /* The content of a register. */
192 /* Getting the system call number from the register.
193 When dealing with x86_64 architecture, this information
194 is stored at %rax register. */
195 regcache_cooked_read (regcache, AMD64_LINUX_ORIG_RAX_REGNUM, buf);
197 ret = extract_signed_integer (buf, 8, byte_order);
203 /* From <asm/sigcontext.h>. */
204 static int amd64_linux_sc_reg_offset[] =
223 17 * 8, /* %eflags */
225 /* FIXME: kettenis/2002030531: The registers %cs, %fs and %gs are
226 available in `struct sigcontext'. However, they only occupy two
227 bytes instead of four, which makes using them here rather
228 difficult. Leave them out for now. */
237 /* Replacement register functions which know about %orig_rax. */
240 amd64_linux_register_name (struct gdbarch *gdbarch, int reg)
242 if (reg == AMD64_LINUX_ORIG_RAX_REGNUM)
245 return amd64_register_name (gdbarch, reg);
249 amd64_linux_register_type (struct gdbarch *gdbarch, int reg)
251 if (reg == AMD64_LINUX_ORIG_RAX_REGNUM)
252 return builtin_type (gdbarch)->builtin_int64;
254 return amd64_register_type (gdbarch, reg);
258 amd64_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
259 struct reggroup *group)
261 if (regnum == AMD64_LINUX_ORIG_RAX_REGNUM)
262 return (group == system_reggroup
263 || group == save_reggroup
264 || group == restore_reggroup);
265 return i386_register_reggroup_p (gdbarch, regnum, group);
268 /* Set the program counter for process PTID to PC. */
271 amd64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
273 regcache_cooked_write_unsigned (regcache, AMD64_RIP_REGNUM, pc);
275 /* We must be careful with modifying the program counter. If we
276 just interrupted a system call, the kernel might try to restart
277 it when we resume the inferior. On restarting the system call,
278 the kernel will try backing up the program counter even though it
279 no longer points at the system call. This typically results in a
280 SIGSEGV or SIGILL. We can prevent this by writing `-1' in the
281 "orig_rax" pseudo-register.
283 Note that "orig_rax" is saved when setting up a dummy call frame.
284 This means that it is properly restored when that frame is
285 popped, and that the interrupted system call will be restarted
286 when we resume the inferior on return from a function call from
287 within GDB. In all other cases the system call will not be
289 regcache_cooked_write_unsigned (regcache, AMD64_LINUX_ORIG_RAX_REGNUM, -1);
292 /* Record all registers but IP register for process-record. */
295 amd64_all_but_ip_registers_record (struct regcache *regcache)
297 if (record_arch_list_add_reg (regcache, AMD64_RAX_REGNUM))
299 if (record_arch_list_add_reg (regcache, AMD64_RCX_REGNUM))
301 if (record_arch_list_add_reg (regcache, AMD64_RDX_REGNUM))
303 if (record_arch_list_add_reg (regcache, AMD64_RBX_REGNUM))
305 if (record_arch_list_add_reg (regcache, AMD64_RSP_REGNUM))
307 if (record_arch_list_add_reg (regcache, AMD64_RBP_REGNUM))
309 if (record_arch_list_add_reg (regcache, AMD64_RSI_REGNUM))
311 if (record_arch_list_add_reg (regcache, AMD64_RDI_REGNUM))
313 if (record_arch_list_add_reg (regcache, AMD64_R8_REGNUM))
315 if (record_arch_list_add_reg (regcache, AMD64_R9_REGNUM))
317 if (record_arch_list_add_reg (regcache, AMD64_R10_REGNUM))
319 if (record_arch_list_add_reg (regcache, AMD64_R11_REGNUM))
321 if (record_arch_list_add_reg (regcache, AMD64_R12_REGNUM))
323 if (record_arch_list_add_reg (regcache, AMD64_R13_REGNUM))
325 if (record_arch_list_add_reg (regcache, AMD64_R14_REGNUM))
327 if (record_arch_list_add_reg (regcache, AMD64_R15_REGNUM))
329 if (record_arch_list_add_reg (regcache, AMD64_EFLAGS_REGNUM))
335 /* amd64_canonicalize_syscall maps from the native amd64 Linux set
336 of syscall ids into a canonical set of syscall ids used by
339 static enum gdb_syscall
340 amd64_canonicalize_syscall (enum amd64_syscall syscall)
346 case amd64_sys_write:
347 return gdb_sys_write;
352 case amd64_sys_close:
353 return gdb_sys_close;
355 case amd64_sys_newstat:
356 return gdb_sys_newstat;
358 case amd64_sys_newfstat:
359 return gdb_sys_newfstat;
361 case amd64_sys_newlstat:
362 return gdb_sys_newlstat;
367 case amd64_sys_lseek:
368 return gdb_sys_lseek;
371 return gdb_sys_mmap2;
373 case amd64_sys_mprotect:
374 return gdb_sys_mprotect;
376 case amd64_sys_munmap:
377 return gdb_sys_munmap;
382 case amd64_sys_rt_sigaction:
383 return gdb_sys_rt_sigaction;
385 case amd64_sys_rt_sigprocmask:
386 return gdb_sys_rt_sigprocmask;
388 case amd64_sys_rt_sigreturn:
389 return gdb_sys_rt_sigreturn;
391 case amd64_sys_ioctl:
392 return gdb_sys_ioctl;
394 case amd64_sys_pread64:
395 return gdb_sys_pread64;
397 case amd64_sys_pwrite64:
398 return gdb_sys_pwrite64;
400 case amd64_sys_readv:
401 return gdb_sys_readv;
403 case amd64_sys_writev:
404 return gdb_sys_writev;
406 case amd64_sys_access:
407 return gdb_sys_access;
412 case amd64_sys_select:
413 return gdb_sys_select;
415 case amd64_sys_sched_yield:
416 return gdb_sys_sched_yield;
418 case amd64_sys_mremap:
419 return gdb_sys_mremap;
421 case amd64_sys_msync:
422 return gdb_sys_msync;
424 case amd64_sys_mincore:
425 return gdb_sys_mincore;
427 case amd64_sys_madvise:
428 return gdb_sys_madvise;
430 case amd64_sys_shmget:
431 return gdb_sys_shmget;
433 case amd64_sys_shmat:
434 return gdb_sys_shmat;
436 case amd64_sys_shmctl:
437 return gdb_sys_shmctl;
445 case amd64_sys_pause:
446 return gdb_sys_pause;
448 case amd64_sys_nanosleep:
449 return gdb_sys_nanosleep;
451 case amd64_sys_getitimer:
452 return gdb_sys_getitimer;
454 case amd64_sys_alarm:
455 return gdb_sys_alarm;
457 case amd64_sys_setitimer:
458 return gdb_sys_setitimer;
460 case amd64_sys_getpid:
461 return gdb_sys_getpid;
463 case amd64_sys_sendfile64:
464 return gdb_sys_sendfile64;
466 case amd64_sys_socket:
467 return gdb_sys_socket;
469 case amd64_sys_connect:
470 return gdb_sys_connect;
472 case amd64_sys_accept:
473 return gdb_sys_accept;
475 case amd64_sys_sendto:
476 return gdb_sys_sendto;
478 case amd64_sys_recvfrom:
479 return gdb_sys_recvfrom;
481 case amd64_sys_sendmsg:
482 return gdb_sys_sendmsg;
484 case amd64_sys_recvmsg:
485 return gdb_sys_recvmsg;
487 case amd64_sys_shutdown:
488 return gdb_sys_shutdown;
493 case amd64_sys_listen:
494 return gdb_sys_listen;
496 case amd64_sys_getsockname:
497 return gdb_sys_getsockname;
499 case amd64_sys_getpeername:
500 return gdb_sys_getpeername;
502 case amd64_sys_socketpair:
503 return gdb_sys_socketpair;
505 case amd64_sys_setsockopt:
506 return gdb_sys_setsockopt;
508 case amd64_sys_getsockopt:
509 return gdb_sys_getsockopt;
511 case amd64_sys_clone:
512 return gdb_sys_clone;
517 case amd64_sys_vfork:
518 return gdb_sys_vfork;
520 case amd64_sys_execve:
521 return gdb_sys_execve;
526 case amd64_sys_wait4:
527 return gdb_sys_wait4;
532 case amd64_sys_uname:
533 return gdb_sys_uname;
535 case amd64_sys_semget:
536 return gdb_sys_semget;
538 case amd64_sys_semop:
539 return gdb_sys_semop;
541 case amd64_sys_semctl:
542 return gdb_sys_semctl;
544 case amd64_sys_shmdt:
545 return gdb_sys_shmdt;
547 case amd64_sys_msgget:
548 return gdb_sys_msgget;
550 case amd64_sys_msgsnd:
551 return gdb_sys_msgsnd;
553 case amd64_sys_msgrcv:
554 return gdb_sys_msgrcv;
556 case amd64_sys_msgctl:
557 return gdb_sys_msgctl;
559 case amd64_sys_fcntl:
560 return gdb_sys_fcntl;
562 case amd64_sys_flock:
563 return gdb_sys_flock;
565 case amd64_sys_fsync:
566 return gdb_sys_fsync;
568 case amd64_sys_fdatasync:
569 return gdb_sys_fdatasync;
571 case amd64_sys_truncate:
572 return gdb_sys_truncate;
574 case amd64_sys_ftruncate:
575 return gdb_sys_ftruncate;
577 case amd64_sys_getdents:
578 return gdb_sys_getdents;
580 case amd64_sys_getcwd:
581 return gdb_sys_getcwd;
583 case amd64_sys_chdir:
584 return gdb_sys_chdir;
586 case amd64_sys_fchdir:
587 return gdb_sys_fchdir;
589 case amd64_sys_rename:
590 return gdb_sys_rename;
592 case amd64_sys_mkdir:
593 return gdb_sys_mkdir;
595 case amd64_sys_rmdir:
596 return gdb_sys_rmdir;
598 case amd64_sys_creat:
599 return gdb_sys_creat;
604 case amd64_sys_unlink:
605 return gdb_sys_unlink;
607 case amd64_sys_symlink:
608 return gdb_sys_symlink;
610 case amd64_sys_readlink:
611 return gdb_sys_readlink;
613 case amd64_sys_chmod:
614 return gdb_sys_chmod;
616 case amd64_sys_fchmod:
617 return gdb_sys_fchmod;
619 case amd64_sys_chown:
620 return gdb_sys_chown;
622 case amd64_sys_fchown:
623 return gdb_sys_fchown;
625 case amd64_sys_lchown:
626 return gdb_sys_lchown;
628 case amd64_sys_umask:
629 return gdb_sys_umask;
631 case amd64_sys_gettimeofday:
632 return gdb_sys_gettimeofday;
634 case amd64_sys_getrlimit:
635 return gdb_sys_getrlimit;
637 case amd64_sys_getrusage:
638 return gdb_sys_getrusage;
640 case amd64_sys_sysinfo:
641 return gdb_sys_sysinfo;
643 case amd64_sys_times:
644 return gdb_sys_times;
646 case amd64_sys_ptrace:
647 return gdb_sys_ptrace;
649 case amd64_sys_getuid:
650 return gdb_sys_getuid;
652 case amd64_sys_syslog:
653 return gdb_sys_syslog;
655 case amd64_sys_getgid:
656 return gdb_sys_getgid;
658 case amd64_sys_setuid:
659 return gdb_sys_setuid;
661 case amd64_sys_setgid:
662 return gdb_sys_setgid;
664 case amd64_sys_geteuid:
665 return gdb_sys_geteuid;
667 case amd64_sys_getegid:
668 return gdb_sys_getegid;
670 case amd64_sys_setpgid:
671 return gdb_sys_setpgid;
673 case amd64_sys_getppid:
674 return gdb_sys_getppid;
676 case amd64_sys_getpgrp:
677 return gdb_sys_getpgrp;
679 case amd64_sys_setsid:
680 return gdb_sys_setsid;
682 case amd64_sys_setreuid:
683 return gdb_sys_setreuid;
685 case amd64_sys_setregid:
686 return gdb_sys_setregid;
688 case amd64_sys_getgroups:
689 return gdb_sys_getgroups;
691 case amd64_sys_setgroups:
692 return gdb_sys_setgroups;
694 case amd64_sys_setresuid:
695 return gdb_sys_setresuid;
697 case amd64_sys_getresuid:
698 return gdb_sys_getresuid;
700 case amd64_sys_setresgid:
701 return gdb_sys_setresgid;
703 case amd64_sys_getresgid:
704 return gdb_sys_getresgid;
706 case amd64_sys_getpgid:
707 return gdb_sys_getpgid;
709 case amd64_sys_setfsuid:
710 return gdb_sys_setfsuid;
712 case amd64_sys_setfsgid:
713 return gdb_sys_setfsgid;
715 case amd64_sys_getsid:
716 return gdb_sys_getsid;
718 case amd64_sys_capget:
719 return gdb_sys_capget;
721 case amd64_sys_capset:
722 return gdb_sys_capset;
724 case amd64_sys_rt_sigpending:
725 return gdb_sys_rt_sigpending;
727 case amd64_sys_rt_sigtimedwait:
728 return gdb_sys_rt_sigtimedwait;
730 case amd64_sys_rt_sigqueueinfo:
731 return gdb_sys_rt_sigqueueinfo;
733 case amd64_sys_rt_sigsuspend:
734 return gdb_sys_rt_sigsuspend;
736 case amd64_sys_sigaltstack:
737 return gdb_sys_sigaltstack;
739 case amd64_sys_utime:
740 return gdb_sys_utime;
742 case amd64_sys_mknod:
743 return gdb_sys_mknod;
745 case amd64_sys_personality:
746 return gdb_sys_personality;
748 case amd64_sys_ustat:
749 return gdb_sys_ustat;
751 case amd64_sys_statfs:
752 return gdb_sys_statfs;
754 case amd64_sys_fstatfs:
755 return gdb_sys_fstatfs;
757 case amd64_sys_sysfs:
758 return gdb_sys_sysfs;
760 case amd64_sys_getpriority:
761 return gdb_sys_getpriority;
763 case amd64_sys_setpriority:
764 return gdb_sys_setpriority;
766 case amd64_sys_sched_setparam:
767 return gdb_sys_sched_setparam;
769 case amd64_sys_sched_getparam:
770 return gdb_sys_sched_getparam;
772 case amd64_sys_sched_setscheduler:
773 return gdb_sys_sched_setscheduler;
775 case amd64_sys_sched_getscheduler:
776 return gdb_sys_sched_getscheduler;
778 case amd64_sys_sched_get_priority_max:
779 return gdb_sys_sched_get_priority_max;
781 case amd64_sys_sched_get_priority_min:
782 return gdb_sys_sched_get_priority_min;
784 case amd64_sys_sched_rr_get_interval:
785 return gdb_sys_sched_rr_get_interval;
787 case amd64_sys_mlock:
788 return gdb_sys_mlock;
790 case amd64_sys_munlock:
791 return gdb_sys_munlock;
793 case amd64_sys_mlockall:
794 return gdb_sys_mlockall;
796 case amd64_sys_munlockall:
797 return gdb_sys_munlockall;
799 case amd64_sys_vhangup:
800 return gdb_sys_vhangup;
802 case amd64_sys_modify_ldt:
803 return gdb_sys_modify_ldt;
805 case amd64_sys_pivot_root:
806 return gdb_sys_pivot_root;
808 case amd64_sys_sysctl:
809 return gdb_sys_sysctl;
811 case amd64_sys_prctl:
812 return gdb_sys_prctl;
814 case amd64_sys_arch_prctl:
815 return -1; /* Note */
817 case amd64_sys_adjtimex:
818 return gdb_sys_adjtimex;
820 case amd64_sys_setrlimit:
821 return gdb_sys_setrlimit;
823 case amd64_sys_chroot:
824 return gdb_sys_chroot;
832 case amd64_sys_settimeofday:
833 return gdb_sys_settimeofday;
835 case amd64_sys_mount:
836 return gdb_sys_mount;
838 case amd64_sys_umount:
839 return gdb_sys_umount;
841 case amd64_sys_swapon:
842 return gdb_sys_swapon;
844 case amd64_sys_swapoff:
845 return gdb_sys_swapoff;
847 case amd64_sys_reboot:
848 return gdb_sys_reboot;
850 case amd64_sys_sethostname:
851 return gdb_sys_sethostname;
853 case amd64_sys_setdomainname:
854 return gdb_sys_setdomainname;
859 case amd64_sys_ioperm:
860 return gdb_sys_ioperm;
862 case amd64_sys_init_module:
863 return gdb_sys_init_module;
865 case amd64_sys_delete_module:
866 return gdb_sys_delete_module;
868 case amd64_sys_quotactl:
869 return gdb_sys_quotactl;
871 case amd64_sys_nfsservctl:
872 return gdb_sys_nfsservctl;
874 case amd64_sys_gettid:
875 return gdb_sys_gettid;
877 case amd64_sys_readahead:
878 return gdb_sys_readahead;
880 case amd64_sys_setxattr:
881 return gdb_sys_setxattr;
883 case amd64_sys_lsetxattr:
884 return gdb_sys_lsetxattr;
886 case amd64_sys_fsetxattr:
887 return gdb_sys_fsetxattr;
889 case amd64_sys_getxattr:
890 return gdb_sys_getxattr;
892 case amd64_sys_lgetxattr:
893 return gdb_sys_lgetxattr;
895 case amd64_sys_fgetxattr:
896 return gdb_sys_fgetxattr;
898 case amd64_sys_listxattr:
899 return gdb_sys_listxattr;
901 case amd64_sys_llistxattr:
902 return gdb_sys_llistxattr;
904 case amd64_sys_flistxattr:
905 return gdb_sys_flistxattr;
907 case amd64_sys_removexattr:
908 return gdb_sys_removexattr;
910 case amd64_sys_lremovexattr:
911 return gdb_sys_lremovexattr;
913 case amd64_sys_fremovexattr:
914 return gdb_sys_fremovexattr;
916 case amd64_sys_tkill:
917 return gdb_sys_tkill;
922 case amd64_sys_futex:
923 return gdb_sys_futex;
925 case amd64_sys_sched_setaffinity:
926 return gdb_sys_sched_setaffinity;
928 case amd64_sys_sched_getaffinity:
929 return gdb_sys_sched_getaffinity;
931 case amd64_sys_io_setup:
932 return gdb_sys_io_setup;
934 case amd64_sys_io_destroy:
935 return gdb_sys_io_destroy;
937 case amd64_sys_io_getevents:
938 return gdb_sys_io_getevents;
940 case amd64_sys_io_submit:
941 return gdb_sys_io_submit;
943 case amd64_sys_io_cancel:
944 return gdb_sys_io_cancel;
946 case amd64_sys_lookup_dcookie:
947 return gdb_sys_lookup_dcookie;
949 case amd64_sys_epoll_create:
950 return gdb_sys_epoll_create;
952 case amd64_sys_remap_file_pages:
953 return gdb_sys_remap_file_pages;
955 case amd64_sys_getdents64:
956 return gdb_sys_getdents64;
958 case amd64_sys_set_tid_address:
959 return gdb_sys_set_tid_address;
961 case amd64_sys_restart_syscall:
962 return gdb_sys_restart_syscall;
964 case amd64_sys_semtimedop:
965 return gdb_sys_semtimedop;
967 case amd64_sys_fadvise64:
968 return gdb_sys_fadvise64;
970 case amd64_sys_timer_create:
971 return gdb_sys_timer_create;
973 case amd64_sys_timer_settime:
974 return gdb_sys_timer_settime;
976 case amd64_sys_timer_gettime:
977 return gdb_sys_timer_gettime;
979 case amd64_sys_timer_getoverrun:
980 return gdb_sys_timer_getoverrun;
982 case amd64_sys_timer_delete:
983 return gdb_sys_timer_delete;
985 case amd64_sys_clock_settime:
986 return gdb_sys_clock_settime;
988 case amd64_sys_clock_gettime:
989 return gdb_sys_clock_gettime;
991 case amd64_sys_clock_getres:
992 return gdb_sys_clock_getres;
994 case amd64_sys_clock_nanosleep:
995 return gdb_sys_clock_nanosleep;
997 case amd64_sys_exit_group:
998 return gdb_sys_exit_group;
1000 case amd64_sys_epoll_wait:
1001 return gdb_sys_epoll_wait;
1003 case amd64_sys_epoll_ctl:
1004 return gdb_sys_epoll_ctl;
1006 case amd64_sys_tgkill:
1007 return gdb_sys_tgkill;
1009 case amd64_sys_utimes:
1010 return gdb_sys_utimes;
1012 case amd64_sys_mbind:
1013 return gdb_sys_mbind;
1015 case amd64_sys_set_mempolicy:
1016 return gdb_sys_set_mempolicy;
1018 case amd64_sys_get_mempolicy:
1019 return gdb_sys_get_mempolicy;
1021 case amd64_sys_mq_open:
1022 return gdb_sys_mq_open;
1024 case amd64_sys_mq_unlink:
1025 return gdb_sys_mq_unlink;
1027 case amd64_sys_mq_timedsend:
1028 return gdb_sys_mq_timedsend;
1030 case amd64_sys_mq_timedreceive:
1031 return gdb_sys_mq_timedreceive;
1033 case amd64_sys_mq_notify:
1034 return gdb_sys_mq_notify;
1036 case amd64_sys_mq_getsetattr:
1037 return gdb_sys_mq_getsetattr;
1039 case amd64_sys_kexec_load:
1040 return gdb_sys_kexec_load;
1042 case amd64_sys_waitid:
1043 return gdb_sys_waitid;
1045 case amd64_sys_add_key:
1046 return gdb_sys_add_key;
1048 case amd64_sys_request_key:
1049 return gdb_sys_request_key;
1051 case amd64_sys_keyctl:
1052 return gdb_sys_keyctl;
1054 case amd64_sys_ioprio_set:
1055 return gdb_sys_ioprio_set;
1057 case amd64_sys_ioprio_get:
1058 return gdb_sys_ioprio_get;
1060 case amd64_sys_inotify_init:
1061 return gdb_sys_inotify_init;
1063 case amd64_sys_inotify_add_watch:
1064 return gdb_sys_inotify_add_watch;
1066 case amd64_sys_inotify_rm_watch:
1067 return gdb_sys_inotify_rm_watch;
1069 case amd64_sys_migrate_pages:
1070 return gdb_sys_migrate_pages;
1072 case amd64_sys_openat:
1073 return gdb_sys_openat;
1075 case amd64_sys_mkdirat:
1076 return gdb_sys_mkdirat;
1078 case amd64_sys_mknodat:
1079 return gdb_sys_mknodat;
1081 case amd64_sys_fchownat:
1082 return gdb_sys_fchownat;
1084 case amd64_sys_futimesat:
1085 return gdb_sys_futimesat;
1087 case amd64_sys_newfstatat:
1088 return gdb_sys_newfstatat;
1090 case amd64_sys_unlinkat:
1091 return gdb_sys_unlinkat;
1093 case amd64_sys_renameat:
1094 return gdb_sys_renameat;
1096 case amd64_sys_linkat:
1097 return gdb_sys_linkat;
1099 case amd64_sys_symlinkat:
1100 return gdb_sys_symlinkat;
1102 case amd64_sys_readlinkat:
1103 return gdb_sys_readlinkat;
1105 case amd64_sys_fchmodat:
1106 return gdb_sys_fchmodat;
1108 case amd64_sys_faccessat:
1109 return gdb_sys_faccessat;
1111 case amd64_sys_pselect6:
1112 return gdb_sys_pselect6;
1114 case amd64_sys_ppoll:
1115 return gdb_sys_ppoll;
1117 case amd64_sys_unshare:
1118 return gdb_sys_unshare;
1120 case amd64_sys_set_robust_list:
1121 return gdb_sys_set_robust_list;
1123 case amd64_sys_get_robust_list:
1124 return gdb_sys_get_robust_list;
1126 case amd64_sys_splice:
1127 return gdb_sys_splice;
1132 case amd64_sys_sync_file_range:
1133 return gdb_sys_sync_file_range;
1135 case amd64_sys_vmsplice:
1136 return gdb_sys_vmsplice;
1138 case amd64_sys_move_pages:
1139 return gdb_sys_move_pages;
1146 /* Parse the arguments of current system call instruction and record
1147 the values of the registers and memory that will be changed into
1148 "record_arch_list". This instruction is "syscall".
1150 Return -1 if something wrong. */
1152 static struct linux_record_tdep amd64_linux_record_tdep;
1154 #define RECORD_ARCH_GET_FS 0x1003
1155 #define RECORD_ARCH_GET_GS 0x1004
1158 amd64_linux_syscall_record (struct regcache *regcache)
1161 ULONGEST syscall_native;
1162 enum gdb_syscall syscall_gdb = -1;
1164 regcache_raw_read_unsigned (regcache, AMD64_RAX_REGNUM, &syscall_native);
1166 switch (syscall_native)
1168 case amd64_sys_rt_sigreturn:
1169 if (amd64_all_but_ip_registers_record (regcache))
1174 case amd64_sys_arch_prctl:
1175 if (syscall_native == amd64_sys_arch_prctl)
1179 regcache_raw_read_unsigned (regcache, amd64_linux_record_tdep.arg3,
1181 if (arg3 == RECORD_ARCH_GET_FS || arg3 == RECORD_ARCH_GET_GS)
1185 regcache_raw_read_unsigned (regcache,
1186 amd64_linux_record_tdep.arg2,
1188 if (record_arch_list_add_mem (addr,
1189 amd64_linux_record_tdep.size_ulong))
1197 syscall_gdb = amd64_canonicalize_syscall (syscall_native);
1199 if (syscall_gdb < 0)
1201 printf_unfiltered (_("Process record and replay target doesn't "
1202 "support syscall number %s\n"),
1203 pulongest (syscall_native));
1208 ret = record_linux_system_call (syscall_gdb, regcache,
1209 &amd64_linux_record_tdep);
1215 /* Record the return value of the system call. */
1216 if (record_arch_list_add_reg (regcache, AMD64_RCX_REGNUM))
1218 if (record_arch_list_add_reg (regcache, AMD64_R11_REGNUM))
1224 #define AMD64_LINUX_redzone 128
1225 #define AMD64_LINUX_xstate 512
1226 #define AMD64_LINUX_frame_size 560
1229 amd64_linux_record_signal (struct gdbarch *gdbarch,
1230 struct regcache *regcache,
1231 enum target_signal signal)
1235 if (amd64_all_but_ip_registers_record (regcache))
1238 if (record_arch_list_add_reg (regcache, AMD64_RIP_REGNUM))
1241 /* Record the change in the stack. */
1242 regcache_raw_read_unsigned (regcache, AMD64_RSP_REGNUM, &rsp);
1245 rsp -= AMD64_LINUX_redzone;
1246 /* This is for xstate.
1247 sp -= sizeof (struct _fpstate); */
1248 rsp -= AMD64_LINUX_xstate;
1249 /* This is for frame_size.
1250 sp -= sizeof (struct rt_sigframe); */
1251 rsp -= AMD64_LINUX_frame_size;
1252 if (record_arch_list_add_mem (rsp, AMD64_LINUX_redzone
1253 + AMD64_LINUX_xstate
1254 + AMD64_LINUX_frame_size))
1257 if (record_arch_list_add_end ())
1264 amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1266 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1268 tdep->gregset_reg_offset = amd64_linux_gregset_reg_offset;
1269 tdep->gregset_num_regs = ARRAY_SIZE (amd64_linux_gregset_reg_offset);
1270 tdep->sizeof_gregset = 27 * 8;
1272 amd64_init_abi (info, gdbarch);
1274 tdep->sigtramp_p = amd64_linux_sigtramp_p;
1275 tdep->sigcontext_addr = amd64_linux_sigcontext_addr;
1276 tdep->sc_reg_offset = amd64_linux_sc_reg_offset;
1277 tdep->sc_num_regs = ARRAY_SIZE (amd64_linux_sc_reg_offset);
1279 /* GNU/Linux uses SVR4-style shared libraries. */
1280 set_solib_svr4_fetch_link_map_offsets
1281 (gdbarch, svr4_lp64_fetch_link_map_offsets);
1283 /* Add the %orig_rax register used for syscall restarting. */
1284 set_gdbarch_write_pc (gdbarch, amd64_linux_write_pc);
1285 set_gdbarch_num_regs (gdbarch, AMD64_LINUX_NUM_REGS);
1286 set_gdbarch_register_name (gdbarch, amd64_linux_register_name);
1287 set_gdbarch_register_type (gdbarch, amd64_linux_register_type);
1288 set_gdbarch_register_reggroup_p (gdbarch, amd64_linux_register_reggroup_p);
1290 /* Functions for 'catch syscall'. */
1291 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_AMD64);
1292 set_gdbarch_get_syscall_number (gdbarch,
1293 amd64_linux_get_syscall_number);
1295 /* Enable TLS support. */
1296 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1297 svr4_fetch_objfile_link_map);
1299 /* GNU/Linux uses SVR4-style shared libraries. */
1300 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
1302 /* Displaced stepping. */
1303 set_gdbarch_displaced_step_copy_insn (gdbarch,
1304 amd64_displaced_step_copy_insn);
1305 set_gdbarch_displaced_step_fixup (gdbarch, amd64_displaced_step_fixup);
1306 set_gdbarch_displaced_step_free_closure (gdbarch,
1307 simple_displaced_step_free_closure);
1308 set_gdbarch_displaced_step_location (gdbarch,
1309 displaced_step_at_entry_point);
1311 set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
1313 set_gdbarch_process_record (gdbarch, i386_process_record);
1314 set_gdbarch_process_record_signal (gdbarch, amd64_linux_record_signal);
1316 /* Initialize the amd64_linux_record_tdep. */
1317 /* These values are the size of the type that will be used in a system
1318 call. They are obtained from Linux Kernel source. */
1319 amd64_linux_record_tdep.size_pointer
1320 = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
1321 amd64_linux_record_tdep.size__old_kernel_stat = 32;
1322 amd64_linux_record_tdep.size_tms = 32;
1323 amd64_linux_record_tdep.size_loff_t = 8;
1324 amd64_linux_record_tdep.size_flock = 32;
1325 amd64_linux_record_tdep.size_oldold_utsname = 45;
1326 amd64_linux_record_tdep.size_ustat = 32;
1327 /* ADM64 doesn't need this size because it doesn't have sys_sigaction
1328 but sys_rt_sigaction. */
1329 amd64_linux_record_tdep.size_old_sigaction = 152;
1330 /* ADM64 doesn't need this size because it doesn't have sys_sigpending
1331 but sys_rt_sigpending. */
1332 amd64_linux_record_tdep.size_old_sigset_t = 128;
1333 amd64_linux_record_tdep.size_rlimit = 16;
1334 amd64_linux_record_tdep.size_rusage = 144;
1335 amd64_linux_record_tdep.size_timeval = 16;
1336 amd64_linux_record_tdep.size_timezone = 8;
1337 /* ADM64 doesn't need this size because it doesn't have sys_getgroups16
1338 but sys_getgroups. */
1339 amd64_linux_record_tdep.size_old_gid_t = 2;
1340 /* ADM64 doesn't need this size because it doesn't have sys_getresuid16
1341 but sys_getresuid. */
1342 amd64_linux_record_tdep.size_old_uid_t = 2;
1343 amd64_linux_record_tdep.size_fd_set = 128;
1344 amd64_linux_record_tdep.size_dirent = 280;
1345 amd64_linux_record_tdep.size_dirent64 = 280;
1346 amd64_linux_record_tdep.size_statfs = 120;
1347 amd64_linux_record_tdep.size_statfs64 = 120;
1348 amd64_linux_record_tdep.size_sockaddr = 16;
1349 amd64_linux_record_tdep.size_int
1350 = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
1351 amd64_linux_record_tdep.size_long
1352 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
1353 amd64_linux_record_tdep.size_ulong
1354 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
1355 amd64_linux_record_tdep.size_msghdr = 56;
1356 amd64_linux_record_tdep.size_itimerval = 32;
1357 amd64_linux_record_tdep.size_stat = 144;
1358 amd64_linux_record_tdep.size_old_utsname = 325;
1359 amd64_linux_record_tdep.size_sysinfo = 112;
1360 amd64_linux_record_tdep.size_msqid_ds = 120;
1361 amd64_linux_record_tdep.size_shmid_ds = 112;
1362 amd64_linux_record_tdep.size_new_utsname = 390;
1363 amd64_linux_record_tdep.size_timex = 208;
1364 amd64_linux_record_tdep.size_mem_dqinfo = 24;
1365 amd64_linux_record_tdep.size_if_dqblk = 72;
1366 amd64_linux_record_tdep.size_fs_quota_stat = 80;
1367 amd64_linux_record_tdep.size_timespec = 16;
1368 amd64_linux_record_tdep.size_pollfd = 8;
1369 amd64_linux_record_tdep.size_NFS_FHSIZE = 32;
1370 amd64_linux_record_tdep.size_knfsd_fh = 132;
1371 amd64_linux_record_tdep.size_TASK_COMM_LEN = 16;
1372 amd64_linux_record_tdep.size_sigaction = 152;
1373 amd64_linux_record_tdep.size_sigset_t = 128;
1374 amd64_linux_record_tdep.size_siginfo_t = 128;
1375 amd64_linux_record_tdep.size_cap_user_data_t = 8;
1376 amd64_linux_record_tdep.size_stack_t = 24;
1377 amd64_linux_record_tdep.size_off_t = 8;
1378 amd64_linux_record_tdep.size_stat64 = 144;
1379 amd64_linux_record_tdep.size_gid_t = 4;
1380 amd64_linux_record_tdep.size_uid_t = 4;
1381 amd64_linux_record_tdep.size_PAGE_SIZE = 4096;
1382 amd64_linux_record_tdep.size_flock64 = 32;
1383 amd64_linux_record_tdep.size_user_desc = 16;
1384 amd64_linux_record_tdep.size_io_event = 32;
1385 amd64_linux_record_tdep.size_iocb = 64;
1386 amd64_linux_record_tdep.size_epoll_event = 12;
1387 amd64_linux_record_tdep.size_itimerspec = 32;
1388 amd64_linux_record_tdep.size_mq_attr = 64;
1389 amd64_linux_record_tdep.size_siginfo = 128;
1390 amd64_linux_record_tdep.size_termios = 60;
1391 amd64_linux_record_tdep.size_termios2 = 44;
1392 amd64_linux_record_tdep.size_pid_t = 4;
1393 amd64_linux_record_tdep.size_winsize = 8;
1394 amd64_linux_record_tdep.size_serial_struct = 72;
1395 amd64_linux_record_tdep.size_serial_icounter_struct = 80;
1396 amd64_linux_record_tdep.size_hayes_esp_config = 12;
1397 amd64_linux_record_tdep.size_size_t = 8;
1398 amd64_linux_record_tdep.size_iovec = 16;
1400 /* These values are the second argument of system call "sys_ioctl".
1401 They are obtained from Linux Kernel source. */
1402 amd64_linux_record_tdep.ioctl_TCGETS = 0x5401;
1403 amd64_linux_record_tdep.ioctl_TCSETS = 0x5402;
1404 amd64_linux_record_tdep.ioctl_TCSETSW = 0x5403;
1405 amd64_linux_record_tdep.ioctl_TCSETSF = 0x5404;
1406 amd64_linux_record_tdep.ioctl_TCGETA = 0x5405;
1407 amd64_linux_record_tdep.ioctl_TCSETA = 0x5406;
1408 amd64_linux_record_tdep.ioctl_TCSETAW = 0x5407;
1409 amd64_linux_record_tdep.ioctl_TCSETAF = 0x5408;
1410 amd64_linux_record_tdep.ioctl_TCSBRK = 0x5409;
1411 amd64_linux_record_tdep.ioctl_TCXONC = 0x540A;
1412 amd64_linux_record_tdep.ioctl_TCFLSH = 0x540B;
1413 amd64_linux_record_tdep.ioctl_TIOCEXCL = 0x540C;
1414 amd64_linux_record_tdep.ioctl_TIOCNXCL = 0x540D;
1415 amd64_linux_record_tdep.ioctl_TIOCSCTTY = 0x540E;
1416 amd64_linux_record_tdep.ioctl_TIOCGPGRP = 0x540F;
1417 amd64_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
1418 amd64_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
1419 amd64_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
1420 amd64_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
1421 amd64_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
1422 amd64_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
1423 amd64_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
1424 amd64_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
1425 amd64_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
1426 amd64_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
1427 amd64_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541A;
1428 amd64_linux_record_tdep.ioctl_FIONREAD = 0x541B;
1429 amd64_linux_record_tdep.ioctl_TIOCINQ
1430 = amd64_linux_record_tdep.ioctl_FIONREAD;
1431 amd64_linux_record_tdep.ioctl_TIOCLINUX = 0x541C;
1432 amd64_linux_record_tdep.ioctl_TIOCCONS = 0x541D;
1433 amd64_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541E;
1434 amd64_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541F;
1435 amd64_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
1436 amd64_linux_record_tdep.ioctl_FIONBIO = 0x5421;
1437 amd64_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
1438 amd64_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
1439 amd64_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
1440 amd64_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
1441 amd64_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
1442 amd64_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
1443 amd64_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
1444 amd64_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
1445 amd64_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
1446 amd64_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
1447 amd64_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
1448 amd64_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
1449 amd64_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
1450 amd64_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
1451 amd64_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
1452 amd64_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
1453 amd64_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
1454 amd64_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
1455 amd64_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
1456 amd64_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
1457 amd64_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
1458 amd64_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
1459 amd64_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
1460 amd64_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
1461 amd64_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545A;
1462 amd64_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545B;
1463 amd64_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545C;
1464 amd64_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545D;
1465 amd64_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545E;
1466 amd64_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545F;
1467 amd64_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;
1469 /* These values are the second argument of system call "sys_fcntl"
1470 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1471 amd64_linux_record_tdep.fcntl_F_GETLK = 5;
1472 amd64_linux_record_tdep.fcntl_F_GETLK64 = 12;
1473 amd64_linux_record_tdep.fcntl_F_SETLK64 = 13;
1474 amd64_linux_record_tdep.fcntl_F_SETLKW64 = 14;
1476 amd64_linux_record_tdep.arg1 = AMD64_RDI_REGNUM;
1477 amd64_linux_record_tdep.arg2 = AMD64_RSI_REGNUM;
1478 amd64_linux_record_tdep.arg3 = AMD64_RDX_REGNUM;
1479 amd64_linux_record_tdep.arg4 = AMD64_R10_REGNUM;
1480 amd64_linux_record_tdep.arg5 = AMD64_R8_REGNUM;
1481 amd64_linux_record_tdep.arg6 = AMD64_R9_REGNUM;
1483 tdep->i386_syscall_record = amd64_linux_syscall_record;
1487 /* Provide a prototype to silence -Wmissing-prototypes. */
1488 extern void _initialize_amd64_linux_tdep (void);
1491 _initialize_amd64_linux_tdep (void)
1493 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
1494 GDB_OSABI_LINUX, amd64_linux_init_abi);