1 /* Target-dependent code for GNU/Linux x86-64.
3 Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009
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"
40 #include "linux-record.h"
42 /* Mapping between the general-purpose registers in `struct user'
43 format and GDB's register cache layout. */
45 /* From <sys/reg.h>. */
46 static int amd64_linux_gregset_reg_offset
[] =
75 /* Support for signal handlers. */
77 #define LINUX_SIGTRAMP_INSN0 0x48 /* mov $NNNNNNNN, %rax */
78 #define LINUX_SIGTRAMP_OFFSET0 0
79 #define LINUX_SIGTRAMP_INSN1 0x0f /* syscall */
80 #define LINUX_SIGTRAMP_OFFSET1 7
82 static const gdb_byte linux_sigtramp_code
[] =
84 /* mov $__NR_rt_sigreturn, %rax */
85 LINUX_SIGTRAMP_INSN0
, 0xc7, 0xc0, 0x0f, 0x00, 0x00, 0x00,
87 LINUX_SIGTRAMP_INSN1
, 0x05
90 #define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
92 /* If PC is in a sigtramp routine, return the address of the start of
93 the routine. Otherwise, return 0. */
96 amd64_linux_sigtramp_start (struct frame_info
*this_frame
)
98 CORE_ADDR pc
= get_frame_pc (this_frame
);
99 gdb_byte buf
[LINUX_SIGTRAMP_LEN
];
101 /* We only recognize a signal trampoline if PC is at the start of
102 one of the two instructions. We optimize for finding the PC at
103 the start, as will be the case when the trampoline is not the
104 first frame on the stack. We assume that in the case where the
105 PC is not at the start of the instruction sequence, there will be
106 a few trailing readable bytes on the stack. */
108 if (!safe_frame_unwind_memory (this_frame
, pc
, buf
, sizeof buf
))
111 if (buf
[0] != LINUX_SIGTRAMP_INSN0
)
113 if (buf
[0] != LINUX_SIGTRAMP_INSN1
)
116 pc
-= LINUX_SIGTRAMP_OFFSET1
;
117 if (!safe_frame_unwind_memory (this_frame
, pc
, buf
, sizeof buf
))
121 if (memcmp (buf
, linux_sigtramp_code
, LINUX_SIGTRAMP_LEN
) != 0)
127 /* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
131 amd64_linux_sigtramp_p (struct frame_info
*this_frame
)
133 CORE_ADDR pc
= get_frame_pc (this_frame
);
136 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
138 /* If we have NAME, we can optimize the search. The trampoline is
139 named __restore_rt. However, it isn't dynamically exported from
140 the shared C library, so the trampoline may appear to be part of
141 the preceding function. This should always be sigaction,
142 __sigaction, or __libc_sigaction (all aliases to the same
144 if (name
== NULL
|| strstr (name
, "sigaction") != NULL
)
145 return (amd64_linux_sigtramp_start (this_frame
) != 0);
147 return (strcmp ("__restore_rt", name
) == 0);
150 /* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
151 #define AMD64_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 40
153 /* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
154 address of the associated sigcontext structure. */
157 amd64_linux_sigcontext_addr (struct frame_info
*this_frame
)
159 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
160 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
164 get_frame_register (this_frame
, AMD64_RSP_REGNUM
, buf
);
165 sp
= extract_unsigned_integer (buf
, 8, byte_order
);
167 /* The sigcontext structure is part of the user context. A pointer
168 to the user context is passed as the third argument to the signal
169 handler, i.e. in %rdx. Unfortunately %rdx isn't preserved across
170 function calls so we can't use it. Fortunately the user context
171 is part of the signal frame and the unwound %rsp directly points
173 return sp
+ AMD64_LINUX_UCONTEXT_SIGCONTEXT_OFFSET
;
177 /* From <asm/sigcontext.h>. */
178 static int amd64_linux_sc_reg_offset
[] =
197 17 * 8, /* %eflags */
199 /* FIXME: kettenis/2002030531: The registers %cs, %fs and %gs are
200 available in `struct sigcontext'. However, they only occupy two
201 bytes instead of four, which makes using them here rather
202 difficult. Leave them out for now. */
211 /* Replacement register functions which know about %orig_rax. */
214 amd64_linux_register_name (struct gdbarch
*gdbarch
, int reg
)
216 if (reg
== AMD64_LINUX_ORIG_RAX_REGNUM
)
219 return amd64_register_name (gdbarch
, reg
);
223 amd64_linux_register_type (struct gdbarch
*gdbarch
, int reg
)
225 if (reg
== AMD64_LINUX_ORIG_RAX_REGNUM
)
226 return builtin_type (gdbarch
)->builtin_int64
;
228 return amd64_register_type (gdbarch
, reg
);
232 amd64_linux_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
233 struct reggroup
*group
)
235 if (regnum
== AMD64_LINUX_ORIG_RAX_REGNUM
)
236 return (group
== system_reggroup
237 || group
== save_reggroup
238 || group
== restore_reggroup
);
239 return default_register_reggroup_p (gdbarch
, regnum
, group
);
242 /* Set the program counter for process PTID to PC. */
245 amd64_linux_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
247 regcache_cooked_write_unsigned (regcache
, AMD64_RIP_REGNUM
, pc
);
249 /* We must be careful with modifying the program counter. If we
250 just interrupted a system call, the kernel might try to restart
251 it when we resume the inferior. On restarting the system call,
252 the kernel will try backing up the program counter even though it
253 no longer points at the system call. This typically results in a
254 SIGSEGV or SIGILL. We can prevent this by writing `-1' in the
255 "orig_rax" pseudo-register.
257 Note that "orig_rax" is saved when setting up a dummy call frame.
258 This means that it is properly restored when that frame is
259 popped, and that the interrupted system call will be restarted
260 when we resume the inferior on return from a function call from
261 within GDB. In all other cases the system call will not be
263 regcache_cooked_write_unsigned (regcache
, AMD64_LINUX_ORIG_RAX_REGNUM
, -1);
266 /* Parse the arguments of current system call instruction and record
267 the values of the registers and memory that will be changed into
268 "record_arch_list". This instruction is "syscall".
270 Return -1 if something wrong. */
272 static struct linux_record_tdep amd64_linux_record_tdep
;
274 #define RECORD_ARCH_GET_FS 0x1003
275 #define RECORD_ARCH_GET_GS 0x1004
277 /* amd64_canonicalize_syscall maps from the native amd64 Linux set
278 of syscall ids into a canonical set of syscall ids used by
281 static enum gdb_syscall
282 amd64_canonicalize_syscall (enum amd64_syscall syscall
)
288 case amd64_sys_write
:
289 return gdb_sys_write
;
294 case amd64_sys_close
:
295 return gdb_sys_close
;
297 case amd64_sys_newstat
:
298 return gdb_sys_newstat
;
300 case amd64_sys_newfstat
:
301 return gdb_sys_newfstat
;
303 case amd64_sys_newlstat
:
304 return gdb_sys_newlstat
;
309 case amd64_sys_lseek
:
310 return gdb_sys_lseek
;
313 return gdb_sys_mmap2
;
315 case amd64_sys_mprotect
:
316 return gdb_sys_mprotect
;
318 case amd64_sys_munmap
:
319 return gdb_sys_munmap
;
324 case amd64_sys_rt_sigaction
:
325 return gdb_sys_rt_sigaction
;
327 case amd64_sys_rt_sigprocmask
:
328 return gdb_sys_rt_sigprocmask
;
330 case amd64_sys_rt_sigreturn
:
331 return gdb_sys_rt_sigreturn
;
333 case amd64_sys_ioctl
:
334 return gdb_sys_ioctl
;
336 case amd64_sys_pread64
:
337 return gdb_sys_pread64
;
339 case amd64_sys_pwrite64
:
340 return gdb_sys_pwrite64
;
342 case amd64_sys_readv
:
343 return gdb_sys_readv
;
345 case amd64_sys_writev
:
346 return gdb_sys_writev
;
348 case amd64_sys_access
:
349 return gdb_sys_access
;
354 case amd64_sys_select
:
355 return gdb_sys_select
;
357 case amd64_sys_sched_yield
:
358 return gdb_sys_sched_yield
;
360 case amd64_sys_mremap
:
361 return gdb_sys_mremap
;
363 case amd64_sys_msync
:
364 return gdb_sys_msync
;
366 case amd64_sys_mincore
:
367 return gdb_sys_mincore
;
369 case amd64_sys_madvise
:
370 return gdb_sys_madvise
;
372 case amd64_sys_shmget
:
373 return gdb_sys_shmget
;
375 case amd64_sys_shmat
:
376 return gdb_sys_shmat
;
378 case amd64_sys_shmctl
:
379 return gdb_sys_shmctl
;
387 case amd64_sys_pause
:
388 return gdb_sys_pause
;
390 case amd64_sys_nanosleep
:
391 return gdb_sys_nanosleep
;
393 case amd64_sys_getitimer
:
394 return gdb_sys_getitimer
;
396 case amd64_sys_alarm
:
397 return gdb_sys_alarm
;
399 case amd64_sys_setitimer
:
400 return gdb_sys_setitimer
;
402 case amd64_sys_getpid
:
403 return gdb_sys_getpid
;
405 case amd64_sys_sendfile64
:
406 return gdb_sys_sendfile64
;
408 case amd64_sys_socket
:
409 return gdb_sys_socket
;
411 case amd64_sys_connect
:
412 return gdb_sys_connect
;
414 case amd64_sys_accept
:
415 return gdb_sys_accept
;
417 case amd64_sys_sendto
:
418 return gdb_sys_sendto
;
420 case amd64_sys_recvfrom
:
421 return gdb_sys_recvfrom
;
423 case amd64_sys_sendmsg
:
424 return gdb_sys_sendmsg
;
426 case amd64_sys_recvmsg
:
427 return gdb_sys_recvmsg
;
429 case amd64_sys_shutdown
:
430 return gdb_sys_shutdown
;
435 case amd64_sys_listen
:
436 return gdb_sys_listen
;
438 case amd64_sys_getsockname
:
439 return gdb_sys_getsockname
;
441 case amd64_sys_getpeername
:
442 return gdb_sys_getpeername
;
444 case amd64_sys_socketpair
:
445 return gdb_sys_socketpair
;
447 case amd64_sys_setsockopt
:
448 return gdb_sys_setsockopt
;
450 case amd64_sys_getsockopt
:
451 return gdb_sys_getsockopt
;
453 case amd64_sys_clone
:
454 return gdb_sys_clone
;
459 case amd64_sys_vfork
:
460 return gdb_sys_vfork
;
462 case amd64_sys_execve
:
463 return gdb_sys_execve
;
468 case amd64_sys_wait4
:
469 return gdb_sys_wait4
;
474 case amd64_sys_uname
:
475 return gdb_sys_uname
;
477 case amd64_sys_semget
:
478 return gdb_sys_semget
;
480 case amd64_sys_semop
:
481 return gdb_sys_semop
;
483 case amd64_sys_semctl
:
484 return gdb_sys_semctl
;
486 case amd64_sys_shmdt
:
487 return gdb_sys_shmdt
;
489 case amd64_sys_msgget
:
490 return gdb_sys_msgget
;
492 case amd64_sys_msgsnd
:
493 return gdb_sys_msgsnd
;
495 case amd64_sys_msgrcv
:
496 return gdb_sys_msgrcv
;
498 case amd64_sys_msgctl
:
499 return gdb_sys_msgctl
;
501 case amd64_sys_fcntl
:
502 return gdb_sys_fcntl
;
504 case amd64_sys_flock
:
505 return gdb_sys_flock
;
507 case amd64_sys_fsync
:
508 return gdb_sys_fsync
;
510 case amd64_sys_fdatasync
:
511 return gdb_sys_fdatasync
;
513 case amd64_sys_truncate
:
514 return gdb_sys_truncate
;
516 case amd64_sys_ftruncate
:
517 return gdb_sys_ftruncate
;
519 case amd64_sys_getdents
:
520 return gdb_sys_getdents
;
522 case amd64_sys_getcwd
:
523 return gdb_sys_getcwd
;
525 case amd64_sys_chdir
:
526 return gdb_sys_chdir
;
528 case amd64_sys_fchdir
:
529 return gdb_sys_fchdir
;
531 case amd64_sys_rename
:
532 return gdb_sys_rename
;
534 case amd64_sys_mkdir
:
535 return gdb_sys_mkdir
;
537 case amd64_sys_rmdir
:
538 return gdb_sys_rmdir
;
540 case amd64_sys_creat
:
541 return gdb_sys_creat
;
546 case amd64_sys_unlink
:
547 return gdb_sys_unlink
;
549 case amd64_sys_symlink
:
550 return gdb_sys_symlink
;
552 case amd64_sys_readlink
:
553 return gdb_sys_readlink
;
555 case amd64_sys_chmod
:
556 return gdb_sys_chmod
;
558 case amd64_sys_fchmod
:
559 return gdb_sys_fchmod
;
561 case amd64_sys_chown
:
562 return gdb_sys_chown
;
564 case amd64_sys_fchown
:
565 return gdb_sys_fchown
;
567 case amd64_sys_lchown
:
568 return gdb_sys_lchown
;
570 case amd64_sys_umask
:
571 return gdb_sys_umask
;
573 case amd64_sys_gettimeofday
:
574 return gdb_sys_gettimeofday
;
576 case amd64_sys_getrlimit
:
577 return gdb_sys_getrlimit
;
579 case amd64_sys_getrusage
:
580 return gdb_sys_getrusage
;
582 case amd64_sys_sysinfo
:
583 return gdb_sys_sysinfo
;
585 case amd64_sys_times
:
586 return gdb_sys_times
;
588 case amd64_sys_ptrace
:
589 return gdb_sys_ptrace
;
591 case amd64_sys_getuid
:
592 return gdb_sys_getuid
;
594 case amd64_sys_syslog
:
595 return gdb_sys_syslog
;
597 case amd64_sys_getgid
:
598 return gdb_sys_getgid
;
600 case amd64_sys_setuid
:
601 return gdb_sys_setuid
;
603 case amd64_sys_setgid
:
604 return gdb_sys_setgid
;
606 case amd64_sys_geteuid
:
607 return gdb_sys_geteuid
;
609 case amd64_sys_getegid
:
610 return gdb_sys_getegid
;
612 case amd64_sys_setpgid
:
613 return gdb_sys_setpgid
;
615 case amd64_sys_getppid
:
616 return gdb_sys_getppid
;
618 case amd64_sys_getpgrp
:
619 return gdb_sys_getpgrp
;
621 case amd64_sys_setsid
:
622 return gdb_sys_setsid
;
624 case amd64_sys_setreuid
:
625 return gdb_sys_setreuid
;
627 case amd64_sys_setregid
:
628 return gdb_sys_setregid
;
630 case amd64_sys_getgroups
:
631 return gdb_sys_getgroups
;
633 case amd64_sys_setgroups
:
634 return gdb_sys_setgroups
;
636 case amd64_sys_setresuid
:
637 return gdb_sys_setresuid
;
639 case amd64_sys_getresuid
:
640 return gdb_sys_getresuid
;
642 case amd64_sys_setresgid
:
643 return gdb_sys_setresgid
;
645 case amd64_sys_getresgid
:
646 return gdb_sys_getresgid
;
648 case amd64_sys_getpgid
:
649 return gdb_sys_getpgid
;
651 case amd64_sys_setfsuid
:
652 return gdb_sys_setfsuid
;
654 case amd64_sys_setfsgid
:
655 return gdb_sys_setfsgid
;
657 case amd64_sys_getsid
:
658 return gdb_sys_getsid
;
660 case amd64_sys_capget
:
661 return gdb_sys_capget
;
663 case amd64_sys_capset
:
664 return gdb_sys_capset
;
666 case amd64_sys_rt_sigpending
:
667 return gdb_sys_rt_sigpending
;
669 case amd64_sys_rt_sigtimedwait
:
670 return gdb_sys_rt_sigtimedwait
;
672 case amd64_sys_rt_sigqueueinfo
:
673 return gdb_sys_rt_sigqueueinfo
;
675 case amd64_sys_rt_sigsuspend
:
676 return gdb_sys_rt_sigsuspend
;
678 case amd64_sys_sigaltstack
:
679 return gdb_sys_sigaltstack
;
681 case amd64_sys_utime
:
682 return gdb_sys_utime
;
684 case amd64_sys_mknod
:
685 return gdb_sys_mknod
;
687 case amd64_sys_personality
:
688 return gdb_sys_personality
;
690 case amd64_sys_ustat
:
691 return gdb_sys_ustat
;
693 case amd64_sys_statfs
:
694 return gdb_sys_statfs
;
696 case amd64_sys_fstatfs
:
697 return gdb_sys_fstatfs
;
699 case amd64_sys_sysfs
:
700 return gdb_sys_sysfs
;
702 case amd64_sys_getpriority
:
703 return gdb_sys_getpriority
;
705 case amd64_sys_setpriority
:
706 return gdb_sys_setpriority
;
708 case amd64_sys_sched_setparam
:
709 return gdb_sys_sched_setparam
;
711 case amd64_sys_sched_getparam
:
712 return gdb_sys_sched_getparam
;
714 case amd64_sys_sched_setscheduler
:
715 return gdb_sys_sched_setscheduler
;
717 case amd64_sys_sched_getscheduler
:
718 return gdb_sys_sched_getscheduler
;
720 case amd64_sys_sched_get_priority_max
:
721 return gdb_sys_sched_get_priority_max
;
723 case amd64_sys_sched_get_priority_min
:
724 return gdb_sys_sched_get_priority_min
;
726 case amd64_sys_sched_rr_get_interval
:
727 return gdb_sys_sched_rr_get_interval
;
729 case amd64_sys_mlock
:
730 return gdb_sys_mlock
;
732 case amd64_sys_munlock
:
733 return gdb_sys_munlock
;
735 case amd64_sys_mlockall
:
736 return gdb_sys_mlockall
;
738 case amd64_sys_munlockall
:
739 return gdb_sys_munlockall
;
741 case amd64_sys_vhangup
:
742 return gdb_sys_vhangup
;
744 case amd64_sys_modify_ldt
:
745 return gdb_sys_modify_ldt
;
747 case amd64_sys_pivot_root
:
748 return gdb_sys_pivot_root
;
750 case amd64_sys_sysctl
:
751 return gdb_sys_sysctl
;
753 case amd64_sys_prctl
:
754 return gdb_sys_prctl
;
756 case amd64_sys_arch_prctl
:
757 return -1; /* Note */
759 case amd64_sys_adjtimex
:
760 return gdb_sys_adjtimex
;
762 case amd64_sys_setrlimit
:
763 return gdb_sys_setrlimit
;
765 case amd64_sys_chroot
:
766 return gdb_sys_chroot
;
774 case amd64_sys_settimeofday
:
775 return gdb_sys_settimeofday
;
777 case amd64_sys_mount
:
778 return gdb_sys_mount
;
780 case amd64_sys_umount
:
781 return gdb_sys_umount
;
783 case amd64_sys_swapon
:
784 return gdb_sys_swapon
;
786 case amd64_sys_swapoff
:
787 return gdb_sys_swapoff
;
789 case amd64_sys_reboot
:
790 return gdb_sys_reboot
;
792 case amd64_sys_sethostname
:
793 return gdb_sys_sethostname
;
795 case amd64_sys_setdomainname
:
796 return gdb_sys_setdomainname
;
801 case amd64_sys_ioperm
:
802 return gdb_sys_ioperm
;
804 case amd64_sys_init_module
:
805 return gdb_sys_init_module
;
807 case amd64_sys_delete_module
:
808 return gdb_sys_delete_module
;
810 case amd64_sys_quotactl
:
811 return gdb_sys_quotactl
;
813 case amd64_sys_nfsservctl
:
814 return gdb_sys_nfsservctl
;
816 case amd64_sys_gettid
:
817 return gdb_sys_gettid
;
819 case amd64_sys_readahead
:
820 return gdb_sys_readahead
;
822 case amd64_sys_setxattr
:
823 return gdb_sys_setxattr
;
825 case amd64_sys_lsetxattr
:
826 return gdb_sys_lsetxattr
;
828 case amd64_sys_fsetxattr
:
829 return gdb_sys_fsetxattr
;
831 case amd64_sys_getxattr
:
832 return gdb_sys_getxattr
;
834 case amd64_sys_lgetxattr
:
835 return gdb_sys_lgetxattr
;
837 case amd64_sys_fgetxattr
:
838 return gdb_sys_fgetxattr
;
840 case amd64_sys_listxattr
:
841 return gdb_sys_listxattr
;
843 case amd64_sys_llistxattr
:
844 return gdb_sys_llistxattr
;
846 case amd64_sys_flistxattr
:
847 return gdb_sys_flistxattr
;
849 case amd64_sys_removexattr
:
850 return gdb_sys_removexattr
;
852 case amd64_sys_lremovexattr
:
853 return gdb_sys_lremovexattr
;
855 case amd64_sys_fremovexattr
:
856 return gdb_sys_fremovexattr
;
858 case amd64_sys_tkill
:
859 return gdb_sys_tkill
;
864 case amd64_sys_futex
:
865 return gdb_sys_futex
;
867 case amd64_sys_sched_setaffinity
:
868 return gdb_sys_sched_setaffinity
;
870 case amd64_sys_sched_getaffinity
:
871 return gdb_sys_sched_getaffinity
;
873 case amd64_sys_io_setup
:
874 return gdb_sys_io_setup
;
876 case amd64_sys_io_destroy
:
877 return gdb_sys_io_destroy
;
879 case amd64_sys_io_getevents
:
880 return gdb_sys_io_getevents
;
882 case amd64_sys_io_submit
:
883 return gdb_sys_io_submit
;
885 case amd64_sys_io_cancel
:
886 return gdb_sys_io_cancel
;
888 case amd64_sys_lookup_dcookie
:
889 return gdb_sys_lookup_dcookie
;
891 case amd64_sys_epoll_create
:
892 return gdb_sys_epoll_create
;
894 case amd64_sys_remap_file_pages
:
895 return gdb_sys_remap_file_pages
;
897 case amd64_sys_getdents64
:
898 return gdb_sys_getdents64
;
900 case amd64_sys_set_tid_address
:
901 return gdb_sys_set_tid_address
;
903 case amd64_sys_restart_syscall
:
904 return gdb_sys_restart_syscall
;
906 case amd64_sys_semtimedop
:
907 return gdb_sys_semtimedop
;
909 case amd64_sys_fadvise64
:
910 return gdb_sys_fadvise64
;
912 case amd64_sys_timer_create
:
913 return gdb_sys_timer_create
;
915 case amd64_sys_timer_settime
:
916 return gdb_sys_timer_settime
;
918 case amd64_sys_timer_gettime
:
919 return gdb_sys_timer_gettime
;
921 case amd64_sys_timer_getoverrun
:
922 return gdb_sys_timer_getoverrun
;
924 case amd64_sys_timer_delete
:
925 return gdb_sys_timer_delete
;
927 case amd64_sys_clock_settime
:
928 return gdb_sys_clock_settime
;
930 case amd64_sys_clock_gettime
:
931 return gdb_sys_clock_gettime
;
933 case amd64_sys_clock_getres
:
934 return gdb_sys_clock_getres
;
936 case amd64_sys_clock_nanosleep
:
937 return gdb_sys_clock_nanosleep
;
939 case amd64_sys_exit_group
:
940 return gdb_sys_exit_group
;
942 case amd64_sys_epoll_wait
:
943 return gdb_sys_epoll_wait
;
945 case amd64_sys_epoll_ctl
:
946 return gdb_sys_epoll_ctl
;
948 case amd64_sys_tgkill
:
949 return gdb_sys_tgkill
;
951 case amd64_sys_utimes
:
952 return gdb_sys_utimes
;
954 case amd64_sys_mbind
:
955 return gdb_sys_mbind
;
957 case amd64_sys_set_mempolicy
:
958 return gdb_sys_set_mempolicy
;
960 case amd64_sys_get_mempolicy
:
961 return gdb_sys_get_mempolicy
;
963 case amd64_sys_mq_open
:
964 return gdb_sys_mq_open
;
966 case amd64_sys_mq_unlink
:
967 return gdb_sys_mq_unlink
;
969 case amd64_sys_mq_timedsend
:
970 return gdb_sys_mq_timedsend
;
972 case amd64_sys_mq_timedreceive
:
973 return gdb_sys_mq_timedreceive
;
975 case amd64_sys_mq_notify
:
976 return gdb_sys_mq_notify
;
978 case amd64_sys_mq_getsetattr
:
979 return gdb_sys_mq_getsetattr
;
981 case amd64_sys_kexec_load
:
982 return gdb_sys_kexec_load
;
984 case amd64_sys_waitid
:
985 return gdb_sys_waitid
;
987 case amd64_sys_add_key
:
988 return gdb_sys_add_key
;
990 case amd64_sys_request_key
:
991 return gdb_sys_request_key
;
993 case amd64_sys_keyctl
:
994 return gdb_sys_keyctl
;
996 case amd64_sys_ioprio_set
:
997 return gdb_sys_ioprio_set
;
999 case amd64_sys_ioprio_get
:
1000 return gdb_sys_ioprio_get
;
1002 case amd64_sys_inotify_init
:
1003 return gdb_sys_inotify_init
;
1005 case amd64_sys_inotify_add_watch
:
1006 return gdb_sys_inotify_add_watch
;
1008 case amd64_sys_inotify_rm_watch
:
1009 return gdb_sys_inotify_rm_watch
;
1011 case amd64_sys_migrate_pages
:
1012 return gdb_sys_migrate_pages
;
1014 case amd64_sys_openat
:
1015 return gdb_sys_openat
;
1017 case amd64_sys_mkdirat
:
1018 return gdb_sys_mkdirat
;
1020 case amd64_sys_mknodat
:
1021 return gdb_sys_mknodat
;
1023 case amd64_sys_fchownat
:
1024 return gdb_sys_fchownat
;
1026 case amd64_sys_futimesat
:
1027 return gdb_sys_futimesat
;
1029 case amd64_sys_newfstatat
:
1030 return gdb_sys_newfstatat
;
1032 case amd64_sys_unlinkat
:
1033 return gdb_sys_unlinkat
;
1035 case amd64_sys_renameat
:
1036 return gdb_sys_renameat
;
1038 case amd64_sys_linkat
:
1039 return gdb_sys_linkat
;
1041 case amd64_sys_symlinkat
:
1042 return gdb_sys_symlinkat
;
1044 case amd64_sys_readlinkat
:
1045 return gdb_sys_readlinkat
;
1047 case amd64_sys_fchmodat
:
1048 return gdb_sys_fchmodat
;
1050 case amd64_sys_faccessat
:
1051 return gdb_sys_faccessat
;
1053 case amd64_sys_pselect6
:
1054 return gdb_sys_pselect6
;
1056 case amd64_sys_ppoll
:
1057 return gdb_sys_ppoll
;
1059 case amd64_sys_unshare
:
1060 return gdb_sys_unshare
;
1062 case amd64_sys_set_robust_list
:
1063 return gdb_sys_set_robust_list
;
1065 case amd64_sys_get_robust_list
:
1066 return gdb_sys_get_robust_list
;
1068 case amd64_sys_splice
:
1069 return gdb_sys_splice
;
1074 case amd64_sys_sync_file_range
:
1075 return gdb_sys_sync_file_range
;
1077 case amd64_sys_vmsplice
:
1078 return gdb_sys_vmsplice
;
1080 case amd64_sys_move_pages
:
1081 return gdb_sys_move_pages
;
1089 amd64_linux_syscall_record (struct regcache
*regcache
)
1092 ULONGEST syscall_native
;
1093 enum gdb_syscall syscall_gdb
= -1;
1095 regcache_raw_read_unsigned (regcache
, AMD64_RAX_REGNUM
, &syscall_native
);
1097 syscall_gdb
= amd64_canonicalize_syscall (syscall_native
);
1099 if (syscall_native
== amd64_sys_arch_prctl
)
1103 regcache_raw_read_unsigned (regcache
, amd64_linux_record_tdep
.arg3
,
1105 if (arg3
== RECORD_ARCH_GET_FS
|| arg3
== RECORD_ARCH_GET_GS
)
1109 regcache_raw_read_unsigned (regcache
, amd64_linux_record_tdep
.arg2
,
1111 if (record_arch_list_add_mem (addr
,
1112 amd64_linux_record_tdep
.size_ulong
))
1118 if (syscall_gdb
< 0)
1120 printf_unfiltered (_("Process record and replay target doesn't "
1121 "support syscall number %s\n"),
1122 pulongest (syscall_native
));
1127 ret
= record_linux_system_call (syscall_gdb
, regcache
,
1128 &amd64_linux_record_tdep
);
1134 /* Record the return value of the system call. */
1135 if (record_arch_list_add_reg (regcache
, AMD64_RCX_REGNUM
))
1137 if (record_arch_list_add_reg (regcache
, AMD64_R11_REGNUM
))
1145 amd64_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1147 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1149 tdep
->gregset_reg_offset
= amd64_linux_gregset_reg_offset
;
1150 tdep
->gregset_num_regs
= ARRAY_SIZE (amd64_linux_gregset_reg_offset
);
1151 tdep
->sizeof_gregset
= 27 * 8;
1153 amd64_init_abi (info
, gdbarch
);
1155 tdep
->sigtramp_p
= amd64_linux_sigtramp_p
;
1156 tdep
->sigcontext_addr
= amd64_linux_sigcontext_addr
;
1157 tdep
->sc_reg_offset
= amd64_linux_sc_reg_offset
;
1158 tdep
->sc_num_regs
= ARRAY_SIZE (amd64_linux_sc_reg_offset
);
1160 /* GNU/Linux uses SVR4-style shared libraries. */
1161 set_solib_svr4_fetch_link_map_offsets
1162 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
1164 /* Add the %orig_rax register used for syscall restarting. */
1165 set_gdbarch_write_pc (gdbarch
, amd64_linux_write_pc
);
1166 set_gdbarch_num_regs (gdbarch
, AMD64_LINUX_NUM_REGS
);
1167 set_gdbarch_register_name (gdbarch
, amd64_linux_register_name
);
1168 set_gdbarch_register_type (gdbarch
, amd64_linux_register_type
);
1169 set_gdbarch_register_reggroup_p (gdbarch
, amd64_linux_register_reggroup_p
);
1171 /* Enable TLS support. */
1172 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
1173 svr4_fetch_objfile_link_map
);
1175 /* GNU/Linux uses SVR4-style shared libraries. */
1176 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
1178 /* Displaced stepping. */
1179 set_gdbarch_displaced_step_copy_insn (gdbarch
,
1180 amd64_displaced_step_copy_insn
);
1181 set_gdbarch_displaced_step_fixup (gdbarch
, amd64_displaced_step_fixup
);
1182 set_gdbarch_displaced_step_free_closure (gdbarch
,
1183 simple_displaced_step_free_closure
);
1184 set_gdbarch_displaced_step_location (gdbarch
,
1185 displaced_step_at_entry_point
);
1187 set_gdbarch_get_siginfo_type (gdbarch
, linux_get_siginfo_type
);
1189 set_gdbarch_process_record (gdbarch
, i386_process_record
);
1191 /* Initialize the amd64_linux_record_tdep. */
1192 /* These values are the size of the type that will be used in a system
1193 call. They are obtained from Linux Kernel source. */
1194 amd64_linux_record_tdep
.size_pointer
1195 = gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
;
1196 amd64_linux_record_tdep
.size__old_kernel_stat
= 32;
1197 amd64_linux_record_tdep
.size_tms
= 32;
1198 amd64_linux_record_tdep
.size_loff_t
= 8;
1199 amd64_linux_record_tdep
.size_flock
= 32;
1200 amd64_linux_record_tdep
.size_oldold_utsname
= 45;
1201 amd64_linux_record_tdep
.size_ustat
= 32;
1202 /* ADM64 doesn't need this size because it doesn't have sys_sigaction
1203 but sys_rt_sigaction. */
1204 amd64_linux_record_tdep
.size_old_sigaction
= 152;
1205 /* ADM64 doesn't need this size because it doesn't have sys_sigpending
1206 but sys_rt_sigpending. */
1207 amd64_linux_record_tdep
.size_old_sigset_t
= 128;
1208 amd64_linux_record_tdep
.size_rlimit
= 16;
1209 amd64_linux_record_tdep
.size_rusage
= 144;
1210 amd64_linux_record_tdep
.size_timeval
= 16;
1211 amd64_linux_record_tdep
.size_timezone
= 8;
1212 /* ADM64 doesn't need this size because it doesn't have sys_getgroups16
1213 but sys_getgroups. */
1214 amd64_linux_record_tdep
.size_old_gid_t
= 2;
1215 /* ADM64 doesn't need this size because it doesn't have sys_getresuid16
1216 but sys_getresuid. */
1217 amd64_linux_record_tdep
.size_old_uid_t
= 2;
1218 amd64_linux_record_tdep
.size_fd_set
= 128;
1219 amd64_linux_record_tdep
.size_dirent
= 280;
1220 amd64_linux_record_tdep
.size_dirent64
= 280;
1221 amd64_linux_record_tdep
.size_statfs
= 120;
1222 amd64_linux_record_tdep
.size_statfs64
= 120;
1223 amd64_linux_record_tdep
.size_sockaddr
= 16;
1224 amd64_linux_record_tdep
.size_int
1225 = gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
;
1226 amd64_linux_record_tdep
.size_long
1227 = gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
;
1228 amd64_linux_record_tdep
.size_ulong
1229 = gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
;
1230 amd64_linux_record_tdep
.size_msghdr
= 56;
1231 amd64_linux_record_tdep
.size_itimerval
= 32;
1232 amd64_linux_record_tdep
.size_stat
= 144;
1233 amd64_linux_record_tdep
.size_old_utsname
= 325;
1234 amd64_linux_record_tdep
.size_sysinfo
= 112;
1235 amd64_linux_record_tdep
.size_msqid_ds
= 120;
1236 amd64_linux_record_tdep
.size_shmid_ds
= 112;
1237 amd64_linux_record_tdep
.size_new_utsname
= 390;
1238 amd64_linux_record_tdep
.size_timex
= 208;
1239 amd64_linux_record_tdep
.size_mem_dqinfo
= 24;
1240 amd64_linux_record_tdep
.size_if_dqblk
= 72;
1241 amd64_linux_record_tdep
.size_fs_quota_stat
= 80;
1242 amd64_linux_record_tdep
.size_timespec
= 16;
1243 amd64_linux_record_tdep
.size_pollfd
= 8;
1244 amd64_linux_record_tdep
.size_NFS_FHSIZE
= 32;
1245 amd64_linux_record_tdep
.size_knfsd_fh
= 132;
1246 amd64_linux_record_tdep
.size_TASK_COMM_LEN
= 16;
1247 amd64_linux_record_tdep
.size_sigaction
= 152;
1248 amd64_linux_record_tdep
.size_sigset_t
= 128;
1249 amd64_linux_record_tdep
.size_siginfo_t
= 128;
1250 amd64_linux_record_tdep
.size_cap_user_data_t
= 8;
1251 amd64_linux_record_tdep
.size_stack_t
= 24;
1252 amd64_linux_record_tdep
.size_off_t
= 8;
1253 amd64_linux_record_tdep
.size_stat64
= 144;
1254 amd64_linux_record_tdep
.size_gid_t
= 4;
1255 amd64_linux_record_tdep
.size_uid_t
= 4;
1256 amd64_linux_record_tdep
.size_PAGE_SIZE
= 4096;
1257 amd64_linux_record_tdep
.size_flock64
= 32;
1258 amd64_linux_record_tdep
.size_user_desc
= 16;
1259 amd64_linux_record_tdep
.size_io_event
= 32;
1260 amd64_linux_record_tdep
.size_iocb
= 64;
1261 amd64_linux_record_tdep
.size_epoll_event
= 12;
1262 amd64_linux_record_tdep
.size_itimerspec
= 32;
1263 amd64_linux_record_tdep
.size_mq_attr
= 64;
1264 amd64_linux_record_tdep
.size_siginfo
= 128;
1265 amd64_linux_record_tdep
.size_termios
= 60;
1266 amd64_linux_record_tdep
.size_termios2
= 44;
1267 amd64_linux_record_tdep
.size_pid_t
= 4;
1268 amd64_linux_record_tdep
.size_winsize
= 8;
1269 amd64_linux_record_tdep
.size_serial_struct
= 72;
1270 amd64_linux_record_tdep
.size_serial_icounter_struct
= 80;
1271 amd64_linux_record_tdep
.size_hayes_esp_config
= 12;
1272 amd64_linux_record_tdep
.size_size_t
= 8;
1273 amd64_linux_record_tdep
.size_iovec
= 16;
1275 /* These values are the second argument of system call "sys_ioctl".
1276 They are obtained from Linux Kernel source. */
1277 amd64_linux_record_tdep
.ioctl_TCGETS
= 0x5401;
1278 amd64_linux_record_tdep
.ioctl_TCSETS
= 0x5402;
1279 amd64_linux_record_tdep
.ioctl_TCSETSW
= 0x5403;
1280 amd64_linux_record_tdep
.ioctl_TCSETSF
= 0x5404;
1281 amd64_linux_record_tdep
.ioctl_TCGETA
= 0x5405;
1282 amd64_linux_record_tdep
.ioctl_TCSETA
= 0x5406;
1283 amd64_linux_record_tdep
.ioctl_TCSETAW
= 0x5407;
1284 amd64_linux_record_tdep
.ioctl_TCSETAF
= 0x5408;
1285 amd64_linux_record_tdep
.ioctl_TCSBRK
= 0x5409;
1286 amd64_linux_record_tdep
.ioctl_TCXONC
= 0x540A;
1287 amd64_linux_record_tdep
.ioctl_TCFLSH
= 0x540B;
1288 amd64_linux_record_tdep
.ioctl_TIOCEXCL
= 0x540C;
1289 amd64_linux_record_tdep
.ioctl_TIOCNXCL
= 0x540D;
1290 amd64_linux_record_tdep
.ioctl_TIOCSCTTY
= 0x540E;
1291 amd64_linux_record_tdep
.ioctl_TIOCGPGRP
= 0x540F;
1292 amd64_linux_record_tdep
.ioctl_TIOCSPGRP
= 0x5410;
1293 amd64_linux_record_tdep
.ioctl_TIOCOUTQ
= 0x5411;
1294 amd64_linux_record_tdep
.ioctl_TIOCSTI
= 0x5412;
1295 amd64_linux_record_tdep
.ioctl_TIOCGWINSZ
= 0x5413;
1296 amd64_linux_record_tdep
.ioctl_TIOCSWINSZ
= 0x5414;
1297 amd64_linux_record_tdep
.ioctl_TIOCMGET
= 0x5415;
1298 amd64_linux_record_tdep
.ioctl_TIOCMBIS
= 0x5416;
1299 amd64_linux_record_tdep
.ioctl_TIOCMBIC
= 0x5417;
1300 amd64_linux_record_tdep
.ioctl_TIOCMSET
= 0x5418;
1301 amd64_linux_record_tdep
.ioctl_TIOCGSOFTCAR
= 0x5419;
1302 amd64_linux_record_tdep
.ioctl_TIOCSSOFTCAR
= 0x541A;
1303 amd64_linux_record_tdep
.ioctl_FIONREAD
= 0x541B;
1304 amd64_linux_record_tdep
.ioctl_TIOCINQ
1305 = amd64_linux_record_tdep
.ioctl_FIONREAD
;
1306 amd64_linux_record_tdep
.ioctl_TIOCLINUX
= 0x541C;
1307 amd64_linux_record_tdep
.ioctl_TIOCCONS
= 0x541D;
1308 amd64_linux_record_tdep
.ioctl_TIOCGSERIAL
= 0x541E;
1309 amd64_linux_record_tdep
.ioctl_TIOCSSERIAL
= 0x541F;
1310 amd64_linux_record_tdep
.ioctl_TIOCPKT
= 0x5420;
1311 amd64_linux_record_tdep
.ioctl_FIONBIO
= 0x5421;
1312 amd64_linux_record_tdep
.ioctl_TIOCNOTTY
= 0x5422;
1313 amd64_linux_record_tdep
.ioctl_TIOCSETD
= 0x5423;
1314 amd64_linux_record_tdep
.ioctl_TIOCGETD
= 0x5424;
1315 amd64_linux_record_tdep
.ioctl_TCSBRKP
= 0x5425;
1316 amd64_linux_record_tdep
.ioctl_TIOCTTYGSTRUCT
= 0x5426;
1317 amd64_linux_record_tdep
.ioctl_TIOCSBRK
= 0x5427;
1318 amd64_linux_record_tdep
.ioctl_TIOCCBRK
= 0x5428;
1319 amd64_linux_record_tdep
.ioctl_TIOCGSID
= 0x5429;
1320 amd64_linux_record_tdep
.ioctl_TCGETS2
= 0x802c542a;
1321 amd64_linux_record_tdep
.ioctl_TCSETS2
= 0x402c542b;
1322 amd64_linux_record_tdep
.ioctl_TCSETSW2
= 0x402c542c;
1323 amd64_linux_record_tdep
.ioctl_TCSETSF2
= 0x402c542d;
1324 amd64_linux_record_tdep
.ioctl_TIOCGPTN
= 0x80045430;
1325 amd64_linux_record_tdep
.ioctl_TIOCSPTLCK
= 0x40045431;
1326 amd64_linux_record_tdep
.ioctl_FIONCLEX
= 0x5450;
1327 amd64_linux_record_tdep
.ioctl_FIOCLEX
= 0x5451;
1328 amd64_linux_record_tdep
.ioctl_FIOASYNC
= 0x5452;
1329 amd64_linux_record_tdep
.ioctl_TIOCSERCONFIG
= 0x5453;
1330 amd64_linux_record_tdep
.ioctl_TIOCSERGWILD
= 0x5454;
1331 amd64_linux_record_tdep
.ioctl_TIOCSERSWILD
= 0x5455;
1332 amd64_linux_record_tdep
.ioctl_TIOCGLCKTRMIOS
= 0x5456;
1333 amd64_linux_record_tdep
.ioctl_TIOCSLCKTRMIOS
= 0x5457;
1334 amd64_linux_record_tdep
.ioctl_TIOCSERGSTRUCT
= 0x5458;
1335 amd64_linux_record_tdep
.ioctl_TIOCSERGETLSR
= 0x5459;
1336 amd64_linux_record_tdep
.ioctl_TIOCSERGETMULTI
= 0x545A;
1337 amd64_linux_record_tdep
.ioctl_TIOCSERSETMULTI
= 0x545B;
1338 amd64_linux_record_tdep
.ioctl_TIOCMIWAIT
= 0x545C;
1339 amd64_linux_record_tdep
.ioctl_TIOCGICOUNT
= 0x545D;
1340 amd64_linux_record_tdep
.ioctl_TIOCGHAYESESP
= 0x545E;
1341 amd64_linux_record_tdep
.ioctl_TIOCSHAYESESP
= 0x545F;
1342 amd64_linux_record_tdep
.ioctl_FIOQSIZE
= 0x5460;
1344 /* These values are the second argument of system call "sys_fcntl"
1345 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1346 amd64_linux_record_tdep
.fcntl_F_GETLK
= 5;
1347 amd64_linux_record_tdep
.fcntl_F_GETLK64
= 12;
1348 amd64_linux_record_tdep
.fcntl_F_SETLK64
= 13;
1349 amd64_linux_record_tdep
.fcntl_F_SETLKW64
= 14;
1351 amd64_linux_record_tdep
.arg1
= AMD64_RDI_REGNUM
;
1352 amd64_linux_record_tdep
.arg2
= AMD64_RSI_REGNUM
;
1353 amd64_linux_record_tdep
.arg3
= AMD64_RDX_REGNUM
;
1354 amd64_linux_record_tdep
.arg4
= AMD64_R10_REGNUM
;
1355 amd64_linux_record_tdep
.arg5
= AMD64_R8_REGNUM
;
1356 amd64_linux_record_tdep
.arg6
= AMD64_R9_REGNUM
;
1358 tdep
->i386_syscall_record
= amd64_linux_syscall_record
;
1362 /* Provide a prototype to silence -Wmissing-prototypes. */
1363 extern void _initialize_amd64_linux_tdep (void);
1366 _initialize_amd64_linux_tdep (void)
1368 gdbarch_register_osabi (bfd_arch_i386
, bfd_mach_x86_64
,
1369 GDB_OSABI_LINUX
, amd64_linux_init_abi
);