static void amd64bsd_fetch_inferior_registers (struct target_ops *ops, struct regcache *regcache, int regnum) { struct gdbarch *gdbarch = get_regcache_arch (regcache); if (regnum == -1 || amd64_native_gregset_supplies_p (gdbarch, regnum)) { struct reg regs; if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), (PTRACE_TYPE_ARG3) ®s, 0) == -1) perror_with_name (_("Couldn't get registers")); amd64_supply_native_gregset (regcache, ®s, -1); if (regnum != -1) return; } if (regnum == -1 || !amd64_native_gregset_supplies_p (gdbarch, regnum)) { struct fpreg fpregs; if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid), (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) perror_with_name (_("Couldn't get floating point status")); amd64_supply_fxsave (regcache, -1, &fpregs); } }
static void amd64_linux_fetch_inferior_registers (int regnum) { int tid; /* GNU/Linux LWP ID's are process ID's. */ tid = TIDGET (inferior_ptid); if (tid == 0) tid = PIDGET (inferior_ptid); /* Not a threaded program. */ if (regnum == -1 || amd64_native_gregset_supplies_p (regnum)) { elf_gregset_t regs; if (ptrace (PTRACE_GETREGS, tid, 0, (long) ®s) < 0) perror_with_name (_("Couldn't get registers")); amd64_supply_native_gregset (current_regcache, ®s, -1); if (regnum != -1) return; } if (regnum == -1 || !amd64_native_gregset_supplies_p (regnum)) { elf_fpregset_t fpregs; if (ptrace (PTRACE_GETFPREGS, tid, 0, (long) &fpregs) < 0) perror_with_name (_("Couldn't get floating point status")); amd64_supply_fxsave (current_regcache, -1, &fpregs); } }
static void amd64bsd_store_inferior_registers (struct target_ops *ops, struct regcache *regcache, int regnum) { struct gdbarch *gdbarch = get_regcache_arch (regcache); if (regnum == -1 || amd64_native_gregset_supplies_p (gdbarch, regnum)) { struct reg regs; if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid), (PTRACE_TYPE_ARG3) ®s, 0) == -1) perror_with_name (_("Couldn't get registers")); amd64_collect_native_gregset (regcache, ®s, regnum); if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid), (PTRACE_TYPE_ARG3) ®s, 0) == -1) perror_with_name (_("Couldn't write registers")); if (regnum != -1) return; } if (regnum == -1 || !amd64_native_gregset_supplies_p (gdbarch, regnum)) { struct fpreg fpregs; #ifdef PT_GETXSTATE_INFO void *xstateregs; if (x86bsd_xsave_len != 0) { xstateregs = alloca (x86bsd_xsave_len); if (ptrace (PT_GETXSTATE, get_ptrace_pid (inferior_ptid), (PTRACE_TYPE_ARG3) xstateregs, 0) == -1) perror_with_name (_("Couldn't get extended state status")); amd64_collect_xsave (regcache, regnum, xstateregs, 0); if (ptrace (PT_SETXSTATE, get_ptrace_pid (inferior_ptid), (PTRACE_TYPE_ARG3) xstateregs, x86bsd_xsave_len) == -1) perror_with_name (_("Couldn't write extended state status")); return; } #endif if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid), (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) perror_with_name (_("Couldn't get floating point status")); amd64_collect_fxsave (regcache, regnum, &fpregs); if (ptrace (PT_SETFPREGS, get_ptrace_pid (inferior_ptid), (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) perror_with_name (_("Couldn't write floating point status")); } }
static void amd64_linux_fetch_inferior_registers (struct target_ops *ops, struct regcache *regcache, int regnum) { struct gdbarch *gdbarch = get_regcache_arch (regcache); int tid; /* GNU/Linux LWP ID's are process ID's. */ tid = ptid_get_lwp (inferior_ptid); if (tid == 0) tid = ptid_get_pid (inferior_ptid); /* Not a threaded program. */ if (regnum == -1 || amd64_native_gregset_supplies_p (gdbarch, regnum)) { elf_gregset_t regs; if (ptrace (PTRACE_GETREGS, tid, 0, (long) ®s) < 0) perror_with_name (_("Couldn't get registers")); amd64_supply_native_gregset (regcache, ®s, -1); if (regnum != -1) return; } if (regnum == -1 || !amd64_native_gregset_supplies_p (gdbarch, regnum)) { elf_fpregset_t fpregs; if (have_ptrace_getregset) { char xstateregs[I386_XSTATE_MAX_SIZE]; struct iovec iov; iov.iov_base = xstateregs; iov.iov_len = sizeof (xstateregs); if (ptrace (PTRACE_GETREGSET, tid, (unsigned int) NT_X86_XSTATE, (long) &iov) < 0) perror_with_name (_("Couldn't get extended state status")); amd64_supply_xsave (regcache, -1, xstateregs); } else { if (ptrace (PTRACE_GETFPREGS, tid, 0, (long) &fpregs) < 0) perror_with_name (_("Couldn't get floating point status")); amd64_supply_fxsave (regcache, -1, &fpregs); } } }
void fetch_inferior_registers (int regnum) { if (regnum == -1 || amd64_native_gregset_supplies_p (regnum)) { struct reg regs; if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), (PTRACE_ARG3_TYPE) ®s, 0) == -1) perror_with_name ("Couldn't get registers"); amd64_supply_native_gregset (current_regcache, ®s, -1); if (regnum != -1) return; } if (regnum == -1 || regnum >= AMD64_ST0_REGNUM) { struct fpreg fpregs; if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) perror_with_name ("Couldn't get floating point status"); amd64_supply_fxsave (current_regcache, -1, &fpregs); } }
diff --git gdb/amd64bsd-nat.c gdb/amd64bsd-nat.c index 66d4289..b1d4a0e 100644 --- gdb/amd64bsd-nat.c +++ gdb/amd64bsd-nat.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <sys/ptrace.h> #include <machine/reg.h> +#include <machine/psl.h> #include "amd64-tdep.h" #include "amd64-nat.h" @@ -98,14 +99,24 @@ amd64bsd_store_inferior_registers (struct target_ops *ops, if (regnum == -1 || amd64_native_gregset_supplies_p (gdbarch, regnum)) { - struct reg regs; + struct reg regs, oldregs; + memset( ®s, 0, sizeof(struct reg)); + memset( &oldregs, 0, sizeof(struct reg)); if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), (PTRACE_TYPE_ARG3) ®s, 0) == -1) perror_with_name (_("Couldn't get registers")); + ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), + (PTRACE_TYPE_ARG3) &oldregs, 0); amd64_collect_native_gregset (regcache, ®s, regnum); + if( (regs.r_rflags ^ oldregs.r_rflags ) & ~PSL_USERCHANGE) { + //printf("regs.r_rflags = 0x%8.8lX\n", regs.r_rflags );
void amd64bsd_fetch_inferior_registers (struct regcache *regcache, int regnum) { struct gdbarch *gdbarch = regcache->arch (); pid_t pid = get_ptrace_pid (regcache->ptid ()); if (regnum == -1 || amd64_native_gregset_supplies_p (gdbarch, regnum)) { struct reg regs; if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1) perror_with_name (_("Couldn't get registers")); amd64_supply_native_gregset (regcache, ®s, -1); if (regnum != -1) return; } #ifdef PT_GETFSBASE if (regnum == -1 || regnum == AMD64_FSBASE_REGNUM) { register_t base; if (ptrace (PT_GETFSBASE, pid, (PTRACE_TYPE_ARG3) &base, 0) == -1) perror_with_name (_("Couldn't get segment register fs_base")); regcache->raw_supply (AMD64_FSBASE_REGNUM, &base); if (regnum != -1) return; } #endif #ifdef PT_GETGSBASE if (regnum == -1 || regnum == AMD64_GSBASE_REGNUM) { register_t base; if (ptrace (PT_GETGSBASE, pid, (PTRACE_TYPE_ARG3) &base, 0) == -1) perror_with_name (_("Couldn't get segment register gs_base")); regcache->raw_supply (AMD64_GSBASE_REGNUM, &base); if (regnum != -1) return; } #endif if (regnum == -1 || !amd64_native_gregset_supplies_p (gdbarch, regnum)) { struct fpreg fpregs; #ifdef PT_GETXSTATE_INFO void *xstateregs; if (x86bsd_xsave_len != 0) { xstateregs = alloca (x86bsd_xsave_len); if (ptrace (PT_GETXSTATE, pid, (PTRACE_TYPE_ARG3) xstateregs, 0) == -1) perror_with_name (_("Couldn't get extended state status")); amd64_supply_xsave (regcache, -1, xstateregs); return; } #endif if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) perror_with_name (_("Couldn't get floating point status")); amd64_supply_fxsave (regcache, -1, &fpregs); } }
/* Read register values from the inferior process. If REGNO is -1, do this for all registers. Otherwise, REGNO specifies which register (so we can save time). */ static void i386_darwin_fetch_inferior_registers (struct target_ops *ops, struct regcache *regcache, int regno) { thread_t current_thread = ptid_get_tid (inferior_ptid); int fetched = 0; struct gdbarch *gdbarch = get_regcache_arch (regcache); #ifdef BFD64 if (gdbarch_ptr_bit (gdbarch) == 64) { if (regno == -1 || amd64_native_gregset_supplies_p (gdbarch, regno)) { x86_thread_state_t gp_regs; unsigned int gp_count = x86_THREAD_STATE_COUNT; kern_return_t ret; ret = thread_get_state (current_thread, x86_THREAD_STATE, (thread_state_t) & gp_regs, &gp_count); if (ret != KERN_SUCCESS) { printf_unfiltered (_("Error calling thread_get_state for " "GP registers for thread 0x%ulx"), current_thread); MACH_CHECK_ERROR (ret); } amd64_supply_native_gregset (regcache, &gp_regs.uts, -1); fetched++; } if (regno == -1 || !amd64_native_gregset_supplies_p (gdbarch, regno)) { x86_float_state_t fp_regs; unsigned int fp_count = x86_FLOAT_STATE_COUNT; kern_return_t ret; ret = thread_get_state (current_thread, x86_FLOAT_STATE, (thread_state_t) & fp_regs, &fp_count); if (ret != KERN_SUCCESS) { printf_unfiltered (_("Error calling thread_get_state for " "float registers for thread 0x%ulx"), current_thread); MACH_CHECK_ERROR (ret); } amd64_supply_fxsave (regcache, -1, &fp_regs.ufs.fs64.__fpu_fcw); fetched++; } } else #endif { if (regno == -1 || regno < I386_NUM_GREGS) { i386_thread_state_t gp_regs; unsigned int gp_count = i386_THREAD_STATE_COUNT; kern_return_t ret; int i; ret = thread_get_state (current_thread, i386_THREAD_STATE, (thread_state_t) & gp_regs, &gp_count); if (ret != KERN_SUCCESS) { printf_unfiltered (_("Error calling thread_get_state for " "GP registers for thread 0x%ulx"), current_thread); MACH_CHECK_ERROR (ret); } for (i = 0; i < I386_NUM_GREGS; i++) regcache_raw_supply (regcache, i, (char *)&gp_regs + i386_darwin_thread_state_reg_offset[i]); fetched++; } if (regno == -1 || (regno >= I386_ST0_REGNUM && regno < I386_SSE_NUM_REGS)) { i386_float_state_t fp_regs; unsigned int fp_count = i386_FLOAT_STATE_COUNT; kern_return_t ret; ret = thread_get_state (current_thread, i386_FLOAT_STATE, (thread_state_t) & fp_regs, &fp_count); if (ret != KERN_SUCCESS) { printf_unfiltered (_("Error calling thread_get_state for " "float registers for thread 0x%ulx"), current_thread); MACH_CHECK_ERROR (ret); } i387_supply_fxsave (regcache, -1, &fp_regs.__fpu_fcw); fetched++; } } if (! fetched) { warning (_("unknown register %d"), regno); regcache_raw_supply (regcache, regno, NULL); } }
static void i386_darwin_store_inferior_registers (struct target_ops *ops, struct regcache *regcache, int regno) { thread_t current_thread = ptid_get_tid (inferior_ptid); struct gdbarch *gdbarch = get_regcache_arch (regcache); #ifdef BFD64 if (gdbarch_ptr_bit (gdbarch) == 64) { if (regno == -1 || amd64_native_gregset_supplies_p (gdbarch, regno)) { x86_thread_state_t gp_regs; kern_return_t ret; unsigned int gp_count = x86_THREAD_STATE_COUNT; ret = thread_get_state (current_thread, x86_THREAD_STATE, (thread_state_t) &gp_regs, &gp_count); MACH_CHECK_ERROR (ret); gdb_assert (gp_regs.tsh.flavor == x86_THREAD_STATE64); gdb_assert (gp_regs.tsh.count == x86_THREAD_STATE64_COUNT); amd64_collect_native_gregset (regcache, &gp_regs.uts, regno); ret = thread_set_state (current_thread, x86_THREAD_STATE, (thread_state_t) &gp_regs, x86_THREAD_STATE_COUNT); MACH_CHECK_ERROR (ret); } if (regno == -1 || !amd64_native_gregset_supplies_p (gdbarch, regno)) { x86_float_state_t fp_regs; kern_return_t ret; unsigned int fp_count = x86_FLOAT_STATE_COUNT; ret = thread_get_state (current_thread, x86_FLOAT_STATE, (thread_state_t) & fp_regs, &fp_count); MACH_CHECK_ERROR (ret); gdb_assert (fp_regs.fsh.flavor == x86_FLOAT_STATE64); gdb_assert (fp_regs.fsh.count == x86_FLOAT_STATE64_COUNT); amd64_collect_fxsave (regcache, regno, &fp_regs.ufs.fs64.__fpu_fcw); ret = thread_set_state (current_thread, x86_FLOAT_STATE, (thread_state_t) & fp_regs, x86_FLOAT_STATE_COUNT); MACH_CHECK_ERROR (ret); } } else #endif { if (regno == -1 || regno < I386_NUM_GREGS) { i386_thread_state_t gp_regs; kern_return_t ret; unsigned int gp_count = i386_THREAD_STATE_COUNT; int i; ret = thread_get_state (current_thread, i386_THREAD_STATE, (thread_state_t) & gp_regs, &gp_count); MACH_CHECK_ERROR (ret); for (i = 0; i < I386_NUM_GREGS; i++) if (regno == -1 || regno == i) regcache_raw_collect (regcache, i, (char *)&gp_regs + i386_darwin_thread_state_reg_offset[i]); ret = thread_set_state (current_thread, i386_THREAD_STATE, (thread_state_t) & gp_regs, i386_THREAD_STATE_COUNT); MACH_CHECK_ERROR (ret); } if (regno == -1 || (regno >= I386_ST0_REGNUM && regno < I386_SSE_NUM_REGS)) { i386_float_state_t fp_regs; unsigned int fp_count = i386_FLOAT_STATE_COUNT; kern_return_t ret; ret = thread_get_state (current_thread, i386_FLOAT_STATE, (thread_state_t) & fp_regs, &fp_count); MACH_CHECK_ERROR (ret); i387_collect_fxsave (regcache, regno, &fp_regs.__fpu_fcw); ret = thread_set_state (current_thread, i386_FLOAT_STATE, (thread_state_t) & fp_regs, i386_FLOAT_STATE_COUNT); MACH_CHECK_ERROR (ret); } } }