GDB (API)
|
00001 /* Target-dependent code for GNU/Linux x86-64. 00002 00003 Copyright (C) 2001-2013 Free Software Foundation, Inc. 00004 Contributed by Jiri Smid, SuSE Labs. 00005 00006 This file is part of GDB. 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00020 00021 #include "defs.h" 00022 #include "arch-utils.h" 00023 #include "frame.h" 00024 #include "gdbcore.h" 00025 #include "regcache.h" 00026 #include "osabi.h" 00027 #include "symtab.h" 00028 #include "gdbtypes.h" 00029 #include "reggroups.h" 00030 #include "regset.h" 00031 #include "amd64-linux-tdep.h" 00032 #include "i386-linux-tdep.h" 00033 #include "linux-tdep.h" 00034 #include "i386-xstate.h" 00035 00036 #include "gdb_string.h" 00037 00038 #include "amd64-tdep.h" 00039 #include "solib-svr4.h" 00040 #include "xml-syscall.h" 00041 #include "glibc-tdep.h" 00042 00043 #include "features/i386/amd64-linux.c" 00044 #include "features/i386/amd64-avx-linux.c" 00045 #include "features/i386/x32-linux.c" 00046 #include "features/i386/x32-avx-linux.c" 00047 00048 /* The syscall's XML filename for i386. */ 00049 #define XML_SYSCALL_FILENAME_AMD64 "syscalls/amd64-linux.xml" 00050 00051 #include "record-full.h" 00052 #include "linux-record.h" 00053 00054 /* Supported register note sections. */ 00055 static struct core_regset_section amd64_linux_regset_sections[] = 00056 { 00057 { ".reg", 27 * 8, "general-purpose" }, 00058 { ".reg2", 512, "floating-point" }, 00059 { ".reg-xstate", I386_XSTATE_MAX_SIZE, "XSAVE extended state" }, 00060 { NULL, 0 } 00061 }; 00062 00063 /* Mapping between the general-purpose registers in `struct user' 00064 format and GDB's register cache layout. */ 00065 00066 /* From <sys/reg.h>. */ 00067 int amd64_linux_gregset_reg_offset[] = 00068 { 00069 10 * 8, /* %rax */ 00070 5 * 8, /* %rbx */ 00071 11 * 8, /* %rcx */ 00072 12 * 8, /* %rdx */ 00073 13 * 8, /* %rsi */ 00074 14 * 8, /* %rdi */ 00075 4 * 8, /* %rbp */ 00076 19 * 8, /* %rsp */ 00077 9 * 8, /* %r8 ... */ 00078 8 * 8, 00079 7 * 8, 00080 6 * 8, 00081 3 * 8, 00082 2 * 8, 00083 1 * 8, 00084 0 * 8, /* ... %r15 */ 00085 16 * 8, /* %rip */ 00086 18 * 8, /* %eflags */ 00087 17 * 8, /* %cs */ 00088 20 * 8, /* %ss */ 00089 23 * 8, /* %ds */ 00090 24 * 8, /* %es */ 00091 25 * 8, /* %fs */ 00092 26 * 8, /* %gs */ 00093 -1, -1, -1, -1, -1, -1, -1, -1, 00094 -1, -1, -1, -1, -1, -1, -1, -1, 00095 -1, -1, -1, -1, -1, -1, -1, -1, 00096 -1, -1, -1, -1, -1, -1, -1, -1, -1, 00097 -1, -1, -1, -1, -1, -1, -1, -1, 00098 -1, -1, -1, -1, -1, -1, -1, -1, 00099 15 * 8 /* "orig_rax" */ 00100 }; 00101 00102 00103 /* Support for signal handlers. */ 00104 00105 #define LINUX_SIGTRAMP_INSN0 0x48 /* mov $NNNNNNNN, %rax */ 00106 #define LINUX_SIGTRAMP_OFFSET0 0 00107 #define LINUX_SIGTRAMP_INSN1 0x0f /* syscall */ 00108 #define LINUX_SIGTRAMP_OFFSET1 7 00109 00110 static const gdb_byte amd64_linux_sigtramp_code[] = 00111 { 00112 /* mov $__NR_rt_sigreturn, %rax */ 00113 LINUX_SIGTRAMP_INSN0, 0xc7, 0xc0, 0x0f, 0x00, 0x00, 0x00, 00114 /* syscall */ 00115 LINUX_SIGTRAMP_INSN1, 0x05 00116 }; 00117 00118 static const gdb_byte amd64_x32_linux_sigtramp_code[] = 00119 { 00120 /* mov $__NR_rt_sigreturn, %rax. */ 00121 LINUX_SIGTRAMP_INSN0, 0xc7, 0xc0, 0x01, 0x02, 0x00, 0x40, 00122 /* syscall */ 00123 LINUX_SIGTRAMP_INSN1, 0x05 00124 }; 00125 00126 #define LINUX_SIGTRAMP_LEN (sizeof amd64_linux_sigtramp_code) 00127 00128 /* If PC is in a sigtramp routine, return the address of the start of 00129 the routine. Otherwise, return 0. */ 00130 00131 static CORE_ADDR 00132 amd64_linux_sigtramp_start (struct frame_info *this_frame) 00133 { 00134 struct gdbarch *gdbarch; 00135 const gdb_byte *sigtramp_code; 00136 CORE_ADDR pc = get_frame_pc (this_frame); 00137 gdb_byte buf[LINUX_SIGTRAMP_LEN]; 00138 00139 /* We only recognize a signal trampoline if PC is at the start of 00140 one of the two instructions. We optimize for finding the PC at 00141 the start, as will be the case when the trampoline is not the 00142 first frame on the stack. We assume that in the case where the 00143 PC is not at the start of the instruction sequence, there will be 00144 a few trailing readable bytes on the stack. */ 00145 00146 if (!safe_frame_unwind_memory (this_frame, pc, buf, sizeof buf)) 00147 return 0; 00148 00149 if (buf[0] != LINUX_SIGTRAMP_INSN0) 00150 { 00151 if (buf[0] != LINUX_SIGTRAMP_INSN1) 00152 return 0; 00153 00154 pc -= LINUX_SIGTRAMP_OFFSET1; 00155 if (!safe_frame_unwind_memory (this_frame, pc, buf, sizeof buf)) 00156 return 0; 00157 } 00158 00159 gdbarch = get_frame_arch (this_frame); 00160 if (gdbarch_ptr_bit (gdbarch) == 32) 00161 sigtramp_code = amd64_x32_linux_sigtramp_code; 00162 else 00163 sigtramp_code = amd64_linux_sigtramp_code; 00164 if (memcmp (buf, sigtramp_code, LINUX_SIGTRAMP_LEN) != 0) 00165 return 0; 00166 00167 return pc; 00168 } 00169 00170 /* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp 00171 routine. */ 00172 00173 static int 00174 amd64_linux_sigtramp_p (struct frame_info *this_frame) 00175 { 00176 CORE_ADDR pc = get_frame_pc (this_frame); 00177 const char *name; 00178 00179 find_pc_partial_function (pc, &name, NULL, NULL); 00180 00181 /* If we have NAME, we can optimize the search. The trampoline is 00182 named __restore_rt. However, it isn't dynamically exported from 00183 the shared C library, so the trampoline may appear to be part of 00184 the preceding function. This should always be sigaction, 00185 __sigaction, or __libc_sigaction (all aliases to the same 00186 function). */ 00187 if (name == NULL || strstr (name, "sigaction") != NULL) 00188 return (amd64_linux_sigtramp_start (this_frame) != 0); 00189 00190 return (strcmp ("__restore_rt", name) == 0); 00191 } 00192 00193 /* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */ 00194 #define AMD64_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 40 00195 00196 /* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the 00197 address of the associated sigcontext structure. */ 00198 00199 static CORE_ADDR 00200 amd64_linux_sigcontext_addr (struct frame_info *this_frame) 00201 { 00202 struct gdbarch *gdbarch = get_frame_arch (this_frame); 00203 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00204 CORE_ADDR sp; 00205 gdb_byte buf[8]; 00206 00207 get_frame_register (this_frame, AMD64_RSP_REGNUM, buf); 00208 sp = extract_unsigned_integer (buf, 8, byte_order); 00209 00210 /* The sigcontext structure is part of the user context. A pointer 00211 to the user context is passed as the third argument to the signal 00212 handler, i.e. in %rdx. Unfortunately %rdx isn't preserved across 00213 function calls so we can't use it. Fortunately the user context 00214 is part of the signal frame and the unwound %rsp directly points 00215 at it. */ 00216 return sp + AMD64_LINUX_UCONTEXT_SIGCONTEXT_OFFSET; 00217 } 00218 00219 00220 static LONGEST 00221 amd64_linux_get_syscall_number (struct gdbarch *gdbarch, 00222 ptid_t ptid) 00223 { 00224 struct regcache *regcache = get_thread_regcache (ptid); 00225 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00226 /* The content of a register. */ 00227 gdb_byte buf[8]; 00228 /* The result. */ 00229 LONGEST ret; 00230 00231 /* Getting the system call number from the register. 00232 When dealing with x86_64 architecture, this information 00233 is stored at %rax register. */ 00234 regcache_cooked_read (regcache, AMD64_LINUX_ORIG_RAX_REGNUM, buf); 00235 00236 ret = extract_signed_integer (buf, 8, byte_order); 00237 00238 return ret; 00239 } 00240 00241 00242 /* From <asm/sigcontext.h>. */ 00243 static int amd64_linux_sc_reg_offset[] = 00244 { 00245 13 * 8, /* %rax */ 00246 11 * 8, /* %rbx */ 00247 14 * 8, /* %rcx */ 00248 12 * 8, /* %rdx */ 00249 9 * 8, /* %rsi */ 00250 8 * 8, /* %rdi */ 00251 10 * 8, /* %rbp */ 00252 15 * 8, /* %rsp */ 00253 0 * 8, /* %r8 */ 00254 1 * 8, /* %r9 */ 00255 2 * 8, /* %r10 */ 00256 3 * 8, /* %r11 */ 00257 4 * 8, /* %r12 */ 00258 5 * 8, /* %r13 */ 00259 6 * 8, /* %r14 */ 00260 7 * 8, /* %r15 */ 00261 16 * 8, /* %rip */ 00262 17 * 8, /* %eflags */ 00263 00264 /* FIXME: kettenis/2002030531: The registers %cs, %fs and %gs are 00265 available in `struct sigcontext'. However, they only occupy two 00266 bytes instead of four, which makes using them here rather 00267 difficult. Leave them out for now. */ 00268 -1, /* %cs */ 00269 -1, /* %ss */ 00270 -1, /* %ds */ 00271 -1, /* %es */ 00272 -1, /* %fs */ 00273 -1 /* %gs */ 00274 }; 00275 00276 static int 00277 amd64_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum, 00278 struct reggroup *group) 00279 { 00280 if (regnum == AMD64_LINUX_ORIG_RAX_REGNUM) 00281 return (group == system_reggroup 00282 || group == save_reggroup 00283 || group == restore_reggroup); 00284 return i386_register_reggroup_p (gdbarch, regnum, group); 00285 } 00286 00287 /* Set the program counter for process PTID to PC. */ 00288 00289 static void 00290 amd64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc) 00291 { 00292 regcache_cooked_write_unsigned (regcache, AMD64_RIP_REGNUM, pc); 00293 00294 /* We must be careful with modifying the program counter. If we 00295 just interrupted a system call, the kernel might try to restart 00296 it when we resume the inferior. On restarting the system call, 00297 the kernel will try backing up the program counter even though it 00298 no longer points at the system call. This typically results in a 00299 SIGSEGV or SIGILL. We can prevent this by writing `-1' in the 00300 "orig_rax" pseudo-register. 00301 00302 Note that "orig_rax" is saved when setting up a dummy call frame. 00303 This means that it is properly restored when that frame is 00304 popped, and that the interrupted system call will be restarted 00305 when we resume the inferior on return from a function call from 00306 within GDB. In all other cases the system call will not be 00307 restarted. */ 00308 regcache_cooked_write_unsigned (regcache, AMD64_LINUX_ORIG_RAX_REGNUM, -1); 00309 } 00310 00311 /* Record all registers but IP register for process-record. */ 00312 00313 static int 00314 amd64_all_but_ip_registers_record (struct regcache *regcache) 00315 { 00316 if (record_full_arch_list_add_reg (regcache, AMD64_RAX_REGNUM)) 00317 return -1; 00318 if (record_full_arch_list_add_reg (regcache, AMD64_RCX_REGNUM)) 00319 return -1; 00320 if (record_full_arch_list_add_reg (regcache, AMD64_RDX_REGNUM)) 00321 return -1; 00322 if (record_full_arch_list_add_reg (regcache, AMD64_RBX_REGNUM)) 00323 return -1; 00324 if (record_full_arch_list_add_reg (regcache, AMD64_RSP_REGNUM)) 00325 return -1; 00326 if (record_full_arch_list_add_reg (regcache, AMD64_RBP_REGNUM)) 00327 return -1; 00328 if (record_full_arch_list_add_reg (regcache, AMD64_RSI_REGNUM)) 00329 return -1; 00330 if (record_full_arch_list_add_reg (regcache, AMD64_RDI_REGNUM)) 00331 return -1; 00332 if (record_full_arch_list_add_reg (regcache, AMD64_R8_REGNUM)) 00333 return -1; 00334 if (record_full_arch_list_add_reg (regcache, AMD64_R9_REGNUM)) 00335 return -1; 00336 if (record_full_arch_list_add_reg (regcache, AMD64_R10_REGNUM)) 00337 return -1; 00338 if (record_full_arch_list_add_reg (regcache, AMD64_R11_REGNUM)) 00339 return -1; 00340 if (record_full_arch_list_add_reg (regcache, AMD64_R12_REGNUM)) 00341 return -1; 00342 if (record_full_arch_list_add_reg (regcache, AMD64_R13_REGNUM)) 00343 return -1; 00344 if (record_full_arch_list_add_reg (regcache, AMD64_R14_REGNUM)) 00345 return -1; 00346 if (record_full_arch_list_add_reg (regcache, AMD64_R15_REGNUM)) 00347 return -1; 00348 if (record_full_arch_list_add_reg (regcache, AMD64_EFLAGS_REGNUM)) 00349 return -1; 00350 00351 return 0; 00352 } 00353 00354 /* amd64_canonicalize_syscall maps from the native amd64 Linux set 00355 of syscall ids into a canonical set of syscall ids used by 00356 process record. */ 00357 00358 static enum gdb_syscall 00359 amd64_canonicalize_syscall (enum amd64_syscall syscall_number) 00360 { 00361 switch (syscall_number) { 00362 case amd64_sys_read: 00363 return gdb_sys_read; 00364 00365 case amd64_sys_write: 00366 return gdb_sys_write; 00367 00368 case amd64_sys_open: 00369 return gdb_sys_open; 00370 00371 case amd64_sys_close: 00372 return gdb_sys_close; 00373 00374 case amd64_sys_newstat: 00375 return gdb_sys_newstat; 00376 00377 case amd64_sys_newfstat: 00378 return gdb_sys_newfstat; 00379 00380 case amd64_sys_newlstat: 00381 return gdb_sys_newlstat; 00382 00383 case amd64_sys_poll: 00384 return gdb_sys_poll; 00385 00386 case amd64_sys_lseek: 00387 return gdb_sys_lseek; 00388 00389 case amd64_sys_mmap: 00390 return gdb_sys_mmap2; 00391 00392 case amd64_sys_mprotect: 00393 return gdb_sys_mprotect; 00394 00395 case amd64_sys_munmap: 00396 return gdb_sys_munmap; 00397 00398 case amd64_sys_brk: 00399 return gdb_sys_brk; 00400 00401 case amd64_sys_rt_sigaction: 00402 return gdb_sys_rt_sigaction; 00403 00404 case amd64_sys_rt_sigprocmask: 00405 return gdb_sys_rt_sigprocmask; 00406 00407 case amd64_sys_rt_sigreturn: 00408 return gdb_sys_rt_sigreturn; 00409 00410 case amd64_sys_ioctl: 00411 return gdb_sys_ioctl; 00412 00413 case amd64_sys_pread64: 00414 return gdb_sys_pread64; 00415 00416 case amd64_sys_pwrite64: 00417 return gdb_sys_pwrite64; 00418 00419 case amd64_sys_readv: 00420 return gdb_sys_readv; 00421 00422 case amd64_sys_writev: 00423 return gdb_sys_writev; 00424 00425 case amd64_sys_access: 00426 return gdb_sys_access; 00427 00428 case amd64_sys_pipe: 00429 return gdb_sys_pipe; 00430 00431 case amd64_sys_select: 00432 return gdb_sys_select; 00433 00434 case amd64_sys_sched_yield: 00435 return gdb_sys_sched_yield; 00436 00437 case amd64_sys_mremap: 00438 return gdb_sys_mremap; 00439 00440 case amd64_sys_msync: 00441 return gdb_sys_msync; 00442 00443 case amd64_sys_mincore: 00444 return gdb_sys_mincore; 00445 00446 case amd64_sys_madvise: 00447 return gdb_sys_madvise; 00448 00449 case amd64_sys_shmget: 00450 return gdb_sys_shmget; 00451 00452 case amd64_sys_shmat: 00453 return gdb_sys_shmat; 00454 00455 case amd64_sys_shmctl: 00456 return gdb_sys_shmctl; 00457 00458 case amd64_sys_dup: 00459 return gdb_sys_dup; 00460 00461 case amd64_sys_dup2: 00462 return gdb_sys_dup2; 00463 00464 case amd64_sys_pause: 00465 return gdb_sys_pause; 00466 00467 case amd64_sys_nanosleep: 00468 return gdb_sys_nanosleep; 00469 00470 case amd64_sys_getitimer: 00471 return gdb_sys_getitimer; 00472 00473 case amd64_sys_alarm: 00474 return gdb_sys_alarm; 00475 00476 case amd64_sys_setitimer: 00477 return gdb_sys_setitimer; 00478 00479 case amd64_sys_getpid: 00480 return gdb_sys_getpid; 00481 00482 case amd64_sys_sendfile64: 00483 return gdb_sys_sendfile64; 00484 00485 case amd64_sys_socket: 00486 return gdb_sys_socket; 00487 00488 case amd64_sys_connect: 00489 return gdb_sys_connect; 00490 00491 case amd64_sys_accept: 00492 return gdb_sys_accept; 00493 00494 case amd64_sys_sendto: 00495 return gdb_sys_sendto; 00496 00497 case amd64_sys_recvfrom: 00498 return gdb_sys_recvfrom; 00499 00500 case amd64_sys_sendmsg: 00501 return gdb_sys_sendmsg; 00502 00503 case amd64_sys_recvmsg: 00504 return gdb_sys_recvmsg; 00505 00506 case amd64_sys_shutdown: 00507 return gdb_sys_shutdown; 00508 00509 case amd64_sys_bind: 00510 return gdb_sys_bind; 00511 00512 case amd64_sys_listen: 00513 return gdb_sys_listen; 00514 00515 case amd64_sys_getsockname: 00516 return gdb_sys_getsockname; 00517 00518 case amd64_sys_getpeername: 00519 return gdb_sys_getpeername; 00520 00521 case amd64_sys_socketpair: 00522 return gdb_sys_socketpair; 00523 00524 case amd64_sys_setsockopt: 00525 return gdb_sys_setsockopt; 00526 00527 case amd64_sys_getsockopt: 00528 return gdb_sys_getsockopt; 00529 00530 case amd64_sys_clone: 00531 return gdb_sys_clone; 00532 00533 case amd64_sys_fork: 00534 return gdb_sys_fork; 00535 00536 case amd64_sys_vfork: 00537 return gdb_sys_vfork; 00538 00539 case amd64_sys_execve: 00540 return gdb_sys_execve; 00541 00542 case amd64_sys_exit: 00543 return gdb_sys_exit; 00544 00545 case amd64_sys_wait4: 00546 return gdb_sys_wait4; 00547 00548 case amd64_sys_kill: 00549 return gdb_sys_kill; 00550 00551 case amd64_sys_uname: 00552 return gdb_sys_uname; 00553 00554 case amd64_sys_semget: 00555 return gdb_sys_semget; 00556 00557 case amd64_sys_semop: 00558 return gdb_sys_semop; 00559 00560 case amd64_sys_semctl: 00561 return gdb_sys_semctl; 00562 00563 case amd64_sys_shmdt: 00564 return gdb_sys_shmdt; 00565 00566 case amd64_sys_msgget: 00567 return gdb_sys_msgget; 00568 00569 case amd64_sys_msgsnd: 00570 return gdb_sys_msgsnd; 00571 00572 case amd64_sys_msgrcv: 00573 return gdb_sys_msgrcv; 00574 00575 case amd64_sys_msgctl: 00576 return gdb_sys_msgctl; 00577 00578 case amd64_sys_fcntl: 00579 return gdb_sys_fcntl; 00580 00581 case amd64_sys_flock: 00582 return gdb_sys_flock; 00583 00584 case amd64_sys_fsync: 00585 return gdb_sys_fsync; 00586 00587 case amd64_sys_fdatasync: 00588 return gdb_sys_fdatasync; 00589 00590 case amd64_sys_truncate: 00591 return gdb_sys_truncate; 00592 00593 case amd64_sys_ftruncate: 00594 return gdb_sys_ftruncate; 00595 00596 case amd64_sys_getdents: 00597 return gdb_sys_getdents; 00598 00599 case amd64_sys_getcwd: 00600 return gdb_sys_getcwd; 00601 00602 case amd64_sys_chdir: 00603 return gdb_sys_chdir; 00604 00605 case amd64_sys_fchdir: 00606 return gdb_sys_fchdir; 00607 00608 case amd64_sys_rename: 00609 return gdb_sys_rename; 00610 00611 case amd64_sys_mkdir: 00612 return gdb_sys_mkdir; 00613 00614 case amd64_sys_rmdir: 00615 return gdb_sys_rmdir; 00616 00617 case amd64_sys_creat: 00618 return gdb_sys_creat; 00619 00620 case amd64_sys_link: 00621 return gdb_sys_link; 00622 00623 case amd64_sys_unlink: 00624 return gdb_sys_unlink; 00625 00626 case amd64_sys_symlink: 00627 return gdb_sys_symlink; 00628 00629 case amd64_sys_readlink: 00630 return gdb_sys_readlink; 00631 00632 case amd64_sys_chmod: 00633 return gdb_sys_chmod; 00634 00635 case amd64_sys_fchmod: 00636 return gdb_sys_fchmod; 00637 00638 case amd64_sys_chown: 00639 return gdb_sys_chown; 00640 00641 case amd64_sys_fchown: 00642 return gdb_sys_fchown; 00643 00644 case amd64_sys_lchown: 00645 return gdb_sys_lchown; 00646 00647 case amd64_sys_umask: 00648 return gdb_sys_umask; 00649 00650 case amd64_sys_gettimeofday: 00651 return gdb_sys_gettimeofday; 00652 00653 case amd64_sys_getrlimit: 00654 return gdb_sys_getrlimit; 00655 00656 case amd64_sys_getrusage: 00657 return gdb_sys_getrusage; 00658 00659 case amd64_sys_sysinfo: 00660 return gdb_sys_sysinfo; 00661 00662 case amd64_sys_times: 00663 return gdb_sys_times; 00664 00665 case amd64_sys_ptrace: 00666 return gdb_sys_ptrace; 00667 00668 case amd64_sys_getuid: 00669 return gdb_sys_getuid; 00670 00671 case amd64_sys_syslog: 00672 return gdb_sys_syslog; 00673 00674 case amd64_sys_getgid: 00675 return gdb_sys_getgid; 00676 00677 case amd64_sys_setuid: 00678 return gdb_sys_setuid; 00679 00680 case amd64_sys_setgid: 00681 return gdb_sys_setgid; 00682 00683 case amd64_sys_geteuid: 00684 return gdb_sys_geteuid; 00685 00686 case amd64_sys_getegid: 00687 return gdb_sys_getegid; 00688 00689 case amd64_sys_setpgid: 00690 return gdb_sys_setpgid; 00691 00692 case amd64_sys_getppid: 00693 return gdb_sys_getppid; 00694 00695 case amd64_sys_getpgrp: 00696 return gdb_sys_getpgrp; 00697 00698 case amd64_sys_setsid: 00699 return gdb_sys_setsid; 00700 00701 case amd64_sys_setreuid: 00702 return gdb_sys_setreuid; 00703 00704 case amd64_sys_setregid: 00705 return gdb_sys_setregid; 00706 00707 case amd64_sys_getgroups: 00708 return gdb_sys_getgroups; 00709 00710 case amd64_sys_setgroups: 00711 return gdb_sys_setgroups; 00712 00713 case amd64_sys_setresuid: 00714 return gdb_sys_setresuid; 00715 00716 case amd64_sys_getresuid: 00717 return gdb_sys_getresuid; 00718 00719 case amd64_sys_setresgid: 00720 return gdb_sys_setresgid; 00721 00722 case amd64_sys_getresgid: 00723 return gdb_sys_getresgid; 00724 00725 case amd64_sys_getpgid: 00726 return gdb_sys_getpgid; 00727 00728 case amd64_sys_setfsuid: 00729 return gdb_sys_setfsuid; 00730 00731 case amd64_sys_setfsgid: 00732 return gdb_sys_setfsgid; 00733 00734 case amd64_sys_getsid: 00735 return gdb_sys_getsid; 00736 00737 case amd64_sys_capget: 00738 return gdb_sys_capget; 00739 00740 case amd64_sys_capset: 00741 return gdb_sys_capset; 00742 00743 case amd64_sys_rt_sigpending: 00744 return gdb_sys_rt_sigpending; 00745 00746 case amd64_sys_rt_sigtimedwait: 00747 return gdb_sys_rt_sigtimedwait; 00748 00749 case amd64_sys_rt_sigqueueinfo: 00750 return gdb_sys_rt_sigqueueinfo; 00751 00752 case amd64_sys_rt_sigsuspend: 00753 return gdb_sys_rt_sigsuspend; 00754 00755 case amd64_sys_sigaltstack: 00756 return gdb_sys_sigaltstack; 00757 00758 case amd64_sys_utime: 00759 return gdb_sys_utime; 00760 00761 case amd64_sys_mknod: 00762 return gdb_sys_mknod; 00763 00764 case amd64_sys_personality: 00765 return gdb_sys_personality; 00766 00767 case amd64_sys_ustat: 00768 return gdb_sys_ustat; 00769 00770 case amd64_sys_statfs: 00771 return gdb_sys_statfs; 00772 00773 case amd64_sys_fstatfs: 00774 return gdb_sys_fstatfs; 00775 00776 case amd64_sys_sysfs: 00777 return gdb_sys_sysfs; 00778 00779 case amd64_sys_getpriority: 00780 return gdb_sys_getpriority; 00781 00782 case amd64_sys_setpriority: 00783 return gdb_sys_setpriority; 00784 00785 case amd64_sys_sched_setparam: 00786 return gdb_sys_sched_setparam; 00787 00788 case amd64_sys_sched_getparam: 00789 return gdb_sys_sched_getparam; 00790 00791 case amd64_sys_sched_setscheduler: 00792 return gdb_sys_sched_setscheduler; 00793 00794 case amd64_sys_sched_getscheduler: 00795 return gdb_sys_sched_getscheduler; 00796 00797 case amd64_sys_sched_get_priority_max: 00798 return gdb_sys_sched_get_priority_max; 00799 00800 case amd64_sys_sched_get_priority_min: 00801 return gdb_sys_sched_get_priority_min; 00802 00803 case amd64_sys_sched_rr_get_interval: 00804 return gdb_sys_sched_rr_get_interval; 00805 00806 case amd64_sys_mlock: 00807 return gdb_sys_mlock; 00808 00809 case amd64_sys_munlock: 00810 return gdb_sys_munlock; 00811 00812 case amd64_sys_mlockall: 00813 return gdb_sys_mlockall; 00814 00815 case amd64_sys_munlockall: 00816 return gdb_sys_munlockall; 00817 00818 case amd64_sys_vhangup: 00819 return gdb_sys_vhangup; 00820 00821 case amd64_sys_modify_ldt: 00822 return gdb_sys_modify_ldt; 00823 00824 case amd64_sys_pivot_root: 00825 return gdb_sys_pivot_root; 00826 00827 case amd64_sys_sysctl: 00828 return gdb_sys_sysctl; 00829 00830 case amd64_sys_prctl: 00831 return gdb_sys_prctl; 00832 00833 case amd64_sys_arch_prctl: 00834 return -1; /* Note */ 00835 00836 case amd64_sys_adjtimex: 00837 return gdb_sys_adjtimex; 00838 00839 case amd64_sys_setrlimit: 00840 return gdb_sys_setrlimit; 00841 00842 case amd64_sys_chroot: 00843 return gdb_sys_chroot; 00844 00845 case amd64_sys_sync: 00846 return gdb_sys_sync; 00847 00848 case amd64_sys_acct: 00849 return gdb_sys_acct; 00850 00851 case amd64_sys_settimeofday: 00852 return gdb_sys_settimeofday; 00853 00854 case amd64_sys_mount: 00855 return gdb_sys_mount; 00856 00857 case amd64_sys_umount: 00858 return gdb_sys_umount; 00859 00860 case amd64_sys_swapon: 00861 return gdb_sys_swapon; 00862 00863 case amd64_sys_swapoff: 00864 return gdb_sys_swapoff; 00865 00866 case amd64_sys_reboot: 00867 return gdb_sys_reboot; 00868 00869 case amd64_sys_sethostname: 00870 return gdb_sys_sethostname; 00871 00872 case amd64_sys_setdomainname: 00873 return gdb_sys_setdomainname; 00874 00875 case amd64_sys_iopl: 00876 return gdb_sys_iopl; 00877 00878 case amd64_sys_ioperm: 00879 return gdb_sys_ioperm; 00880 00881 case amd64_sys_init_module: 00882 return gdb_sys_init_module; 00883 00884 case amd64_sys_delete_module: 00885 return gdb_sys_delete_module; 00886 00887 case amd64_sys_quotactl: 00888 return gdb_sys_quotactl; 00889 00890 case amd64_sys_nfsservctl: 00891 return gdb_sys_nfsservctl; 00892 00893 case amd64_sys_gettid: 00894 return gdb_sys_gettid; 00895 00896 case amd64_sys_readahead: 00897 return gdb_sys_readahead; 00898 00899 case amd64_sys_setxattr: 00900 return gdb_sys_setxattr; 00901 00902 case amd64_sys_lsetxattr: 00903 return gdb_sys_lsetxattr; 00904 00905 case amd64_sys_fsetxattr: 00906 return gdb_sys_fsetxattr; 00907 00908 case amd64_sys_getxattr: 00909 return gdb_sys_getxattr; 00910 00911 case amd64_sys_lgetxattr: 00912 return gdb_sys_lgetxattr; 00913 00914 case amd64_sys_fgetxattr: 00915 return gdb_sys_fgetxattr; 00916 00917 case amd64_sys_listxattr: 00918 return gdb_sys_listxattr; 00919 00920 case amd64_sys_llistxattr: 00921 return gdb_sys_llistxattr; 00922 00923 case amd64_sys_flistxattr: 00924 return gdb_sys_flistxattr; 00925 00926 case amd64_sys_removexattr: 00927 return gdb_sys_removexattr; 00928 00929 case amd64_sys_lremovexattr: 00930 return gdb_sys_lremovexattr; 00931 00932 case amd64_sys_fremovexattr: 00933 return gdb_sys_fremovexattr; 00934 00935 case amd64_sys_tkill: 00936 return gdb_sys_tkill; 00937 00938 case amd64_sys_time: 00939 return gdb_sys_time; 00940 00941 case amd64_sys_futex: 00942 return gdb_sys_futex; 00943 00944 case amd64_sys_sched_setaffinity: 00945 return gdb_sys_sched_setaffinity; 00946 00947 case amd64_sys_sched_getaffinity: 00948 return gdb_sys_sched_getaffinity; 00949 00950 case amd64_sys_io_setup: 00951 return gdb_sys_io_setup; 00952 00953 case amd64_sys_io_destroy: 00954 return gdb_sys_io_destroy; 00955 00956 case amd64_sys_io_getevents: 00957 return gdb_sys_io_getevents; 00958 00959 case amd64_sys_io_submit: 00960 return gdb_sys_io_submit; 00961 00962 case amd64_sys_io_cancel: 00963 return gdb_sys_io_cancel; 00964 00965 case amd64_sys_lookup_dcookie: 00966 return gdb_sys_lookup_dcookie; 00967 00968 case amd64_sys_epoll_create: 00969 return gdb_sys_epoll_create; 00970 00971 case amd64_sys_remap_file_pages: 00972 return gdb_sys_remap_file_pages; 00973 00974 case amd64_sys_getdents64: 00975 return gdb_sys_getdents64; 00976 00977 case amd64_sys_set_tid_address: 00978 return gdb_sys_set_tid_address; 00979 00980 case amd64_sys_restart_syscall: 00981 return gdb_sys_restart_syscall; 00982 00983 case amd64_sys_semtimedop: 00984 return gdb_sys_semtimedop; 00985 00986 case amd64_sys_fadvise64: 00987 return gdb_sys_fadvise64; 00988 00989 case amd64_sys_timer_create: 00990 return gdb_sys_timer_create; 00991 00992 case amd64_sys_timer_settime: 00993 return gdb_sys_timer_settime; 00994 00995 case amd64_sys_timer_gettime: 00996 return gdb_sys_timer_gettime; 00997 00998 case amd64_sys_timer_getoverrun: 00999 return gdb_sys_timer_getoverrun; 01000 01001 case amd64_sys_timer_delete: 01002 return gdb_sys_timer_delete; 01003 01004 case amd64_sys_clock_settime: 01005 return gdb_sys_clock_settime; 01006 01007 case amd64_sys_clock_gettime: 01008 return gdb_sys_clock_gettime; 01009 01010 case amd64_sys_clock_getres: 01011 return gdb_sys_clock_getres; 01012 01013 case amd64_sys_clock_nanosleep: 01014 return gdb_sys_clock_nanosleep; 01015 01016 case amd64_sys_exit_group: 01017 return gdb_sys_exit_group; 01018 01019 case amd64_sys_epoll_wait: 01020 return gdb_sys_epoll_wait; 01021 01022 case amd64_sys_epoll_ctl: 01023 return gdb_sys_epoll_ctl; 01024 01025 case amd64_sys_tgkill: 01026 return gdb_sys_tgkill; 01027 01028 case amd64_sys_utimes: 01029 return gdb_sys_utimes; 01030 01031 case amd64_sys_mbind: 01032 return gdb_sys_mbind; 01033 01034 case amd64_sys_set_mempolicy: 01035 return gdb_sys_set_mempolicy; 01036 01037 case amd64_sys_get_mempolicy: 01038 return gdb_sys_get_mempolicy; 01039 01040 case amd64_sys_mq_open: 01041 return gdb_sys_mq_open; 01042 01043 case amd64_sys_mq_unlink: 01044 return gdb_sys_mq_unlink; 01045 01046 case amd64_sys_mq_timedsend: 01047 return gdb_sys_mq_timedsend; 01048 01049 case amd64_sys_mq_timedreceive: 01050 return gdb_sys_mq_timedreceive; 01051 01052 case amd64_sys_mq_notify: 01053 return gdb_sys_mq_notify; 01054 01055 case amd64_sys_mq_getsetattr: 01056 return gdb_sys_mq_getsetattr; 01057 01058 case amd64_sys_kexec_load: 01059 return gdb_sys_kexec_load; 01060 01061 case amd64_sys_waitid: 01062 return gdb_sys_waitid; 01063 01064 case amd64_sys_add_key: 01065 return gdb_sys_add_key; 01066 01067 case amd64_sys_request_key: 01068 return gdb_sys_request_key; 01069 01070 case amd64_sys_keyctl: 01071 return gdb_sys_keyctl; 01072 01073 case amd64_sys_ioprio_set: 01074 return gdb_sys_ioprio_set; 01075 01076 case amd64_sys_ioprio_get: 01077 return gdb_sys_ioprio_get; 01078 01079 case amd64_sys_inotify_init: 01080 return gdb_sys_inotify_init; 01081 01082 case amd64_sys_inotify_add_watch: 01083 return gdb_sys_inotify_add_watch; 01084 01085 case amd64_sys_inotify_rm_watch: 01086 return gdb_sys_inotify_rm_watch; 01087 01088 case amd64_sys_migrate_pages: 01089 return gdb_sys_migrate_pages; 01090 01091 case amd64_sys_openat: 01092 return gdb_sys_openat; 01093 01094 case amd64_sys_mkdirat: 01095 return gdb_sys_mkdirat; 01096 01097 case amd64_sys_mknodat: 01098 return gdb_sys_mknodat; 01099 01100 case amd64_sys_fchownat: 01101 return gdb_sys_fchownat; 01102 01103 case amd64_sys_futimesat: 01104 return gdb_sys_futimesat; 01105 01106 case amd64_sys_newfstatat: 01107 return gdb_sys_newfstatat; 01108 01109 case amd64_sys_unlinkat: 01110 return gdb_sys_unlinkat; 01111 01112 case amd64_sys_renameat: 01113 return gdb_sys_renameat; 01114 01115 case amd64_sys_linkat: 01116 return gdb_sys_linkat; 01117 01118 case amd64_sys_symlinkat: 01119 return gdb_sys_symlinkat; 01120 01121 case amd64_sys_readlinkat: 01122 return gdb_sys_readlinkat; 01123 01124 case amd64_sys_fchmodat: 01125 return gdb_sys_fchmodat; 01126 01127 case amd64_sys_faccessat: 01128 return gdb_sys_faccessat; 01129 01130 case amd64_sys_pselect6: 01131 return gdb_sys_pselect6; 01132 01133 case amd64_sys_ppoll: 01134 return gdb_sys_ppoll; 01135 01136 case amd64_sys_unshare: 01137 return gdb_sys_unshare; 01138 01139 case amd64_sys_set_robust_list: 01140 return gdb_sys_set_robust_list; 01141 01142 case amd64_sys_get_robust_list: 01143 return gdb_sys_get_robust_list; 01144 01145 case amd64_sys_splice: 01146 return gdb_sys_splice; 01147 01148 case amd64_sys_tee: 01149 return gdb_sys_tee; 01150 01151 case amd64_sys_sync_file_range: 01152 return gdb_sys_sync_file_range; 01153 01154 case amd64_sys_vmsplice: 01155 return gdb_sys_vmsplice; 01156 01157 case amd64_sys_move_pages: 01158 return gdb_sys_move_pages; 01159 01160 default: 01161 return -1; 01162 } 01163 } 01164 01165 /* Parse the arguments of current system call instruction and record 01166 the values of the registers and memory that will be changed into 01167 "record_full_arch_list". This instruction is "syscall". 01168 01169 Return -1 if something wrong. */ 01170 01171 static struct linux_record_tdep amd64_linux_record_tdep; 01172 01173 #define RECORD_ARCH_GET_FS 0x1003 01174 #define RECORD_ARCH_GET_GS 0x1004 01175 01176 static int 01177 amd64_linux_syscall_record (struct regcache *regcache) 01178 { 01179 int ret; 01180 ULONGEST syscall_native; 01181 enum gdb_syscall syscall_gdb = -1; 01182 01183 regcache_raw_read_unsigned (regcache, AMD64_RAX_REGNUM, &syscall_native); 01184 01185 switch (syscall_native) 01186 { 01187 case amd64_sys_rt_sigreturn: 01188 if (amd64_all_but_ip_registers_record (regcache)) 01189 return -1; 01190 return 0; 01191 break; 01192 01193 case amd64_sys_arch_prctl: 01194 { 01195 ULONGEST arg3; 01196 01197 regcache_raw_read_unsigned (regcache, amd64_linux_record_tdep.arg3, 01198 &arg3); 01199 if (arg3 == RECORD_ARCH_GET_FS || arg3 == RECORD_ARCH_GET_GS) 01200 { 01201 CORE_ADDR addr; 01202 01203 regcache_raw_read_unsigned (regcache, 01204 amd64_linux_record_tdep.arg2, 01205 &addr); 01206 if (record_full_arch_list_add_mem 01207 (addr, amd64_linux_record_tdep.size_ulong)) 01208 return -1; 01209 } 01210 goto record_regs; 01211 } 01212 break; 01213 } 01214 01215 syscall_gdb = amd64_canonicalize_syscall (syscall_native); 01216 01217 if (syscall_gdb < 0) 01218 { 01219 printf_unfiltered (_("Process record and replay target doesn't " 01220 "support syscall number %s\n"), 01221 pulongest (syscall_native)); 01222 return -1; 01223 } 01224 else 01225 { 01226 ret = record_linux_system_call (syscall_gdb, regcache, 01227 &amd64_linux_record_tdep); 01228 if (ret) 01229 return ret; 01230 } 01231 01232 record_regs: 01233 /* Record the return value of the system call. */ 01234 if (record_full_arch_list_add_reg (regcache, AMD64_RCX_REGNUM)) 01235 return -1; 01236 if (record_full_arch_list_add_reg (regcache, AMD64_R11_REGNUM)) 01237 return -1; 01238 01239 return 0; 01240 } 01241 01242 #define AMD64_LINUX_redzone 128 01243 #define AMD64_LINUX_xstate 512 01244 #define AMD64_LINUX_frame_size 560 01245 01246 static int 01247 amd64_linux_record_signal (struct gdbarch *gdbarch, 01248 struct regcache *regcache, 01249 enum gdb_signal signal) 01250 { 01251 ULONGEST rsp; 01252 01253 if (amd64_all_but_ip_registers_record (regcache)) 01254 return -1; 01255 01256 if (record_full_arch_list_add_reg (regcache, AMD64_RIP_REGNUM)) 01257 return -1; 01258 01259 /* Record the change in the stack. */ 01260 regcache_raw_read_unsigned (regcache, AMD64_RSP_REGNUM, &rsp); 01261 /* redzone 01262 sp -= 128; */ 01263 rsp -= AMD64_LINUX_redzone; 01264 /* This is for xstate. 01265 sp -= sizeof (struct _fpstate); */ 01266 rsp -= AMD64_LINUX_xstate; 01267 /* This is for frame_size. 01268 sp -= sizeof (struct rt_sigframe); */ 01269 rsp -= AMD64_LINUX_frame_size; 01270 if (record_full_arch_list_add_mem (rsp, AMD64_LINUX_redzone 01271 + AMD64_LINUX_xstate 01272 + AMD64_LINUX_frame_size)) 01273 return -1; 01274 01275 if (record_full_arch_list_add_end ()) 01276 return -1; 01277 01278 return 0; 01279 } 01280 01281 /* Get Linux/x86 target description from core dump. */ 01282 01283 static const struct target_desc * 01284 amd64_linux_core_read_description (struct gdbarch *gdbarch, 01285 struct target_ops *target, 01286 bfd *abfd) 01287 { 01288 /* Linux/x86-64. */ 01289 uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd); 01290 switch ((xcr0 & I386_XSTATE_AVX_MASK)) 01291 { 01292 case I386_XSTATE_AVX_MASK: 01293 if (gdbarch_ptr_bit (gdbarch) == 32) 01294 return tdesc_x32_avx_linux; 01295 else 01296 return tdesc_amd64_avx_linux; 01297 default: 01298 if (gdbarch_ptr_bit (gdbarch) == 32) 01299 return tdesc_x32_linux; 01300 else 01301 return tdesc_amd64_linux; 01302 } 01303 } 01304 01305 static void 01306 amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch) 01307 { 01308 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 01309 01310 linux_init_abi (info, gdbarch); 01311 01312 tdep->sigtramp_p = amd64_linux_sigtramp_p; 01313 tdep->sigcontext_addr = amd64_linux_sigcontext_addr; 01314 tdep->sc_reg_offset = amd64_linux_sc_reg_offset; 01315 tdep->sc_num_regs = ARRAY_SIZE (amd64_linux_sc_reg_offset); 01316 01317 tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET; 01318 01319 /* Add the %orig_rax register used for syscall restarting. */ 01320 set_gdbarch_write_pc (gdbarch, amd64_linux_write_pc); 01321 01322 tdep->register_reggroup_p = amd64_linux_register_reggroup_p; 01323 01324 /* Functions for 'catch syscall'. */ 01325 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_AMD64); 01326 set_gdbarch_get_syscall_number (gdbarch, 01327 amd64_linux_get_syscall_number); 01328 01329 /* Enable TLS support. */ 01330 set_gdbarch_fetch_tls_load_module_address (gdbarch, 01331 svr4_fetch_objfile_link_map); 01332 01333 /* GNU/Linux uses SVR4-style shared libraries. */ 01334 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); 01335 01336 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */ 01337 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver); 01338 01339 /* Install supported register note sections. */ 01340 set_gdbarch_core_regset_sections (gdbarch, amd64_linux_regset_sections); 01341 01342 set_gdbarch_core_read_description (gdbarch, 01343 amd64_linux_core_read_description); 01344 01345 /* Displaced stepping. */ 01346 set_gdbarch_displaced_step_copy_insn (gdbarch, 01347 amd64_displaced_step_copy_insn); 01348 set_gdbarch_displaced_step_fixup (gdbarch, amd64_displaced_step_fixup); 01349 set_gdbarch_displaced_step_free_closure (gdbarch, 01350 simple_displaced_step_free_closure); 01351 set_gdbarch_displaced_step_location (gdbarch, 01352 displaced_step_at_entry_point); 01353 01354 set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type); 01355 01356 set_gdbarch_process_record (gdbarch, i386_process_record); 01357 set_gdbarch_process_record_signal (gdbarch, amd64_linux_record_signal); 01358 01359 /* Initialize the amd64_linux_record_tdep. */ 01360 /* These values are the size of the type that will be used in a system 01361 call. They are obtained from Linux Kernel source. */ 01362 amd64_linux_record_tdep.size_pointer 01363 = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT; 01364 amd64_linux_record_tdep.size__old_kernel_stat = 32; 01365 amd64_linux_record_tdep.size_tms = 32; 01366 amd64_linux_record_tdep.size_loff_t = 8; 01367 amd64_linux_record_tdep.size_flock = 32; 01368 amd64_linux_record_tdep.size_oldold_utsname = 45; 01369 amd64_linux_record_tdep.size_ustat = 32; 01370 /* ADM64 doesn't need this size because it doesn't have sys_sigaction 01371 but sys_rt_sigaction. */ 01372 amd64_linux_record_tdep.size_old_sigaction = 152; 01373 /* ADM64 doesn't need this size because it doesn't have sys_sigpending 01374 but sys_rt_sigpending. */ 01375 amd64_linux_record_tdep.size_old_sigset_t = 128; 01376 amd64_linux_record_tdep.size_rlimit = 16; 01377 amd64_linux_record_tdep.size_rusage = 144; 01378 amd64_linux_record_tdep.size_timeval = 16; 01379 amd64_linux_record_tdep.size_timezone = 8; 01380 /* ADM64 doesn't need this size because it doesn't have sys_getgroups16 01381 but sys_getgroups. */ 01382 amd64_linux_record_tdep.size_old_gid_t = 2; 01383 /* ADM64 doesn't need this size because it doesn't have sys_getresuid16 01384 but sys_getresuid. */ 01385 amd64_linux_record_tdep.size_old_uid_t = 2; 01386 amd64_linux_record_tdep.size_fd_set = 128; 01387 amd64_linux_record_tdep.size_dirent = 280; 01388 amd64_linux_record_tdep.size_dirent64 = 280; 01389 amd64_linux_record_tdep.size_statfs = 120; 01390 amd64_linux_record_tdep.size_statfs64 = 120; 01391 amd64_linux_record_tdep.size_sockaddr = 16; 01392 amd64_linux_record_tdep.size_int 01393 = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT; 01394 amd64_linux_record_tdep.size_long 01395 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT; 01396 amd64_linux_record_tdep.size_ulong 01397 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT; 01398 amd64_linux_record_tdep.size_msghdr = 56; 01399 amd64_linux_record_tdep.size_itimerval = 32; 01400 amd64_linux_record_tdep.size_stat = 144; 01401 amd64_linux_record_tdep.size_old_utsname = 325; 01402 amd64_linux_record_tdep.size_sysinfo = 112; 01403 amd64_linux_record_tdep.size_msqid_ds = 120; 01404 amd64_linux_record_tdep.size_shmid_ds = 112; 01405 amd64_linux_record_tdep.size_new_utsname = 390; 01406 amd64_linux_record_tdep.size_timex = 208; 01407 amd64_linux_record_tdep.size_mem_dqinfo = 24; 01408 amd64_linux_record_tdep.size_if_dqblk = 72; 01409 amd64_linux_record_tdep.size_fs_quota_stat = 80; 01410 amd64_linux_record_tdep.size_timespec = 16; 01411 amd64_linux_record_tdep.size_pollfd = 8; 01412 amd64_linux_record_tdep.size_NFS_FHSIZE = 32; 01413 amd64_linux_record_tdep.size_knfsd_fh = 132; 01414 amd64_linux_record_tdep.size_TASK_COMM_LEN = 16; 01415 amd64_linux_record_tdep.size_sigaction = 152; 01416 amd64_linux_record_tdep.size_sigset_t = 128; 01417 amd64_linux_record_tdep.size_siginfo_t = 128; 01418 amd64_linux_record_tdep.size_cap_user_data_t = 8; 01419 amd64_linux_record_tdep.size_stack_t = 24; 01420 amd64_linux_record_tdep.size_off_t = 8; 01421 amd64_linux_record_tdep.size_stat64 = 144; 01422 amd64_linux_record_tdep.size_gid_t = 4; 01423 amd64_linux_record_tdep.size_uid_t = 4; 01424 amd64_linux_record_tdep.size_PAGE_SIZE = 4096; 01425 amd64_linux_record_tdep.size_flock64 = 32; 01426 amd64_linux_record_tdep.size_user_desc = 16; 01427 amd64_linux_record_tdep.size_io_event = 32; 01428 amd64_linux_record_tdep.size_iocb = 64; 01429 amd64_linux_record_tdep.size_epoll_event = 12; 01430 amd64_linux_record_tdep.size_itimerspec = 32; 01431 amd64_linux_record_tdep.size_mq_attr = 64; 01432 amd64_linux_record_tdep.size_siginfo = 128; 01433 amd64_linux_record_tdep.size_termios = 60; 01434 amd64_linux_record_tdep.size_termios2 = 44; 01435 amd64_linux_record_tdep.size_pid_t = 4; 01436 amd64_linux_record_tdep.size_winsize = 8; 01437 amd64_linux_record_tdep.size_serial_struct = 72; 01438 amd64_linux_record_tdep.size_serial_icounter_struct = 80; 01439 amd64_linux_record_tdep.size_hayes_esp_config = 12; 01440 amd64_linux_record_tdep.size_size_t = 8; 01441 amd64_linux_record_tdep.size_iovec = 16; 01442 01443 /* These values are the second argument of system call "sys_ioctl". 01444 They are obtained from Linux Kernel source. */ 01445 amd64_linux_record_tdep.ioctl_TCGETS = 0x5401; 01446 amd64_linux_record_tdep.ioctl_TCSETS = 0x5402; 01447 amd64_linux_record_tdep.ioctl_TCSETSW = 0x5403; 01448 amd64_linux_record_tdep.ioctl_TCSETSF = 0x5404; 01449 amd64_linux_record_tdep.ioctl_TCGETA = 0x5405; 01450 amd64_linux_record_tdep.ioctl_TCSETA = 0x5406; 01451 amd64_linux_record_tdep.ioctl_TCSETAW = 0x5407; 01452 amd64_linux_record_tdep.ioctl_TCSETAF = 0x5408; 01453 amd64_linux_record_tdep.ioctl_TCSBRK = 0x5409; 01454 amd64_linux_record_tdep.ioctl_TCXONC = 0x540A; 01455 amd64_linux_record_tdep.ioctl_TCFLSH = 0x540B; 01456 amd64_linux_record_tdep.ioctl_TIOCEXCL = 0x540C; 01457 amd64_linux_record_tdep.ioctl_TIOCNXCL = 0x540D; 01458 amd64_linux_record_tdep.ioctl_TIOCSCTTY = 0x540E; 01459 amd64_linux_record_tdep.ioctl_TIOCGPGRP = 0x540F; 01460 amd64_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410; 01461 amd64_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411; 01462 amd64_linux_record_tdep.ioctl_TIOCSTI = 0x5412; 01463 amd64_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413; 01464 amd64_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414; 01465 amd64_linux_record_tdep.ioctl_TIOCMGET = 0x5415; 01466 amd64_linux_record_tdep.ioctl_TIOCMBIS = 0x5416; 01467 amd64_linux_record_tdep.ioctl_TIOCMBIC = 0x5417; 01468 amd64_linux_record_tdep.ioctl_TIOCMSET = 0x5418; 01469 amd64_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419; 01470 amd64_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541A; 01471 amd64_linux_record_tdep.ioctl_FIONREAD = 0x541B; 01472 amd64_linux_record_tdep.ioctl_TIOCINQ 01473 = amd64_linux_record_tdep.ioctl_FIONREAD; 01474 amd64_linux_record_tdep.ioctl_TIOCLINUX = 0x541C; 01475 amd64_linux_record_tdep.ioctl_TIOCCONS = 0x541D; 01476 amd64_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541E; 01477 amd64_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541F; 01478 amd64_linux_record_tdep.ioctl_TIOCPKT = 0x5420; 01479 amd64_linux_record_tdep.ioctl_FIONBIO = 0x5421; 01480 amd64_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422; 01481 amd64_linux_record_tdep.ioctl_TIOCSETD = 0x5423; 01482 amd64_linux_record_tdep.ioctl_TIOCGETD = 0x5424; 01483 amd64_linux_record_tdep.ioctl_TCSBRKP = 0x5425; 01484 amd64_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426; 01485 amd64_linux_record_tdep.ioctl_TIOCSBRK = 0x5427; 01486 amd64_linux_record_tdep.ioctl_TIOCCBRK = 0x5428; 01487 amd64_linux_record_tdep.ioctl_TIOCGSID = 0x5429; 01488 amd64_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a; 01489 amd64_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b; 01490 amd64_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c; 01491 amd64_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d; 01492 amd64_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430; 01493 amd64_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431; 01494 amd64_linux_record_tdep.ioctl_FIONCLEX = 0x5450; 01495 amd64_linux_record_tdep.ioctl_FIOCLEX = 0x5451; 01496 amd64_linux_record_tdep.ioctl_FIOASYNC = 0x5452; 01497 amd64_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453; 01498 amd64_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454; 01499 amd64_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455; 01500 amd64_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456; 01501 amd64_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457; 01502 amd64_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458; 01503 amd64_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459; 01504 amd64_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545A; 01505 amd64_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545B; 01506 amd64_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545C; 01507 amd64_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545D; 01508 amd64_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545E; 01509 amd64_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545F; 01510 amd64_linux_record_tdep.ioctl_FIOQSIZE = 0x5460; 01511 01512 /* These values are the second argument of system call "sys_fcntl" 01513 and "sys_fcntl64". They are obtained from Linux Kernel source. */ 01514 amd64_linux_record_tdep.fcntl_F_GETLK = 5; 01515 amd64_linux_record_tdep.fcntl_F_GETLK64 = 12; 01516 amd64_linux_record_tdep.fcntl_F_SETLK64 = 13; 01517 amd64_linux_record_tdep.fcntl_F_SETLKW64 = 14; 01518 01519 amd64_linux_record_tdep.arg1 = AMD64_RDI_REGNUM; 01520 amd64_linux_record_tdep.arg2 = AMD64_RSI_REGNUM; 01521 amd64_linux_record_tdep.arg3 = AMD64_RDX_REGNUM; 01522 amd64_linux_record_tdep.arg4 = AMD64_R10_REGNUM; 01523 amd64_linux_record_tdep.arg5 = AMD64_R8_REGNUM; 01524 amd64_linux_record_tdep.arg6 = AMD64_R9_REGNUM; 01525 01526 tdep->i386_syscall_record = amd64_linux_syscall_record; 01527 } 01528 01529 static void 01530 amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) 01531 { 01532 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 01533 const struct target_desc *tdesc = info.target_desc; 01534 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info; 01535 const struct tdesc_feature *feature; 01536 int valid_p; 01537 01538 gdb_assert (tdesc_data); 01539 01540 tdep->gregset_reg_offset = amd64_linux_gregset_reg_offset; 01541 tdep->gregset_num_regs = ARRAY_SIZE (amd64_linux_gregset_reg_offset); 01542 tdep->sizeof_gregset = 27 * 8; 01543 01544 amd64_init_abi (info, gdbarch); 01545 01546 /* Reserve a number for orig_rax. */ 01547 set_gdbarch_num_regs (gdbarch, AMD64_LINUX_NUM_REGS); 01548 01549 if (! tdesc_has_registers (tdesc)) 01550 tdesc = tdesc_amd64_linux; 01551 tdep->tdesc = tdesc; 01552 01553 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux"); 01554 if (feature == NULL) 01555 return; 01556 01557 valid_p = tdesc_numbered_register (feature, tdesc_data, 01558 AMD64_LINUX_ORIG_RAX_REGNUM, 01559 "orig_rax"); 01560 if (!valid_p) 01561 return; 01562 01563 amd64_linux_init_abi_common (info, gdbarch); 01564 01565 /* GNU/Linux uses SVR4-style shared libraries. */ 01566 set_solib_svr4_fetch_link_map_offsets 01567 (gdbarch, svr4_lp64_fetch_link_map_offsets); 01568 } 01569 01570 static void 01571 amd64_x32_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch) 01572 { 01573 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 01574 const struct target_desc *tdesc = info.target_desc; 01575 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info; 01576 const struct tdesc_feature *feature; 01577 int valid_p; 01578 01579 gdb_assert (tdesc_data); 01580 01581 tdep->gregset_reg_offset = amd64_linux_gregset_reg_offset; 01582 tdep->gregset_num_regs = ARRAY_SIZE (amd64_linux_gregset_reg_offset); 01583 tdep->sizeof_gregset = 27 * 8; 01584 01585 amd64_x32_init_abi (info, gdbarch); 01586 01587 /* Reserve a number for orig_rax. */ 01588 set_gdbarch_num_regs (gdbarch, AMD64_LINUX_NUM_REGS); 01589 01590 if (! tdesc_has_registers (tdesc)) 01591 tdesc = tdesc_x32_linux; 01592 tdep->tdesc = tdesc; 01593 01594 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux"); 01595 if (feature == NULL) 01596 return; 01597 01598 valid_p = tdesc_numbered_register (feature, tdesc_data, 01599 AMD64_LINUX_ORIG_RAX_REGNUM, 01600 "orig_rax"); 01601 if (!valid_p) 01602 return; 01603 01604 amd64_linux_init_abi_common (info, gdbarch); 01605 01606 /* GNU/Linux uses SVR4-style shared libraries. */ 01607 set_solib_svr4_fetch_link_map_offsets 01608 (gdbarch, svr4_ilp32_fetch_link_map_offsets); 01609 } 01610 01611 01612 /* Provide a prototype to silence -Wmissing-prototypes. */ 01613 extern void _initialize_amd64_linux_tdep (void); 01614 01615 void 01616 _initialize_amd64_linux_tdep (void) 01617 { 01618 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, 01619 GDB_OSABI_LINUX, amd64_linux_init_abi); 01620 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x64_32, 01621 GDB_OSABI_LINUX, amd64_x32_linux_init_abi); 01622 01623 /* Initialize the Linux target description. */ 01624 initialize_tdesc_amd64_linux (); 01625 initialize_tdesc_amd64_avx_linux (); 01626 initialize_tdesc_x32_linux (); 01627 initialize_tdesc_x32_avx_linux (); 01628 }