static void inf_ptrace_store_register (int regnum) { CORE_ADDR addr; size_t size; PTRACE_TYPE_RET *buf; int pid, i; /* Cater for systems like GNU/Linux, that implement threads as seperate processes. */ pid = ptid_get_lwp (inferior_ptid); if (pid == 0) pid = ptid_get_pid (inferior_ptid); /* This isn't really an address, but ptrace thinks of it as one. */ addr = inf_ptrace_register_u_offset (regnum); size = register_size (current_gdbarch, regnum); gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0); buf = alloca (size); /* Write the register contents into the inferior a chunk at the time. */ regcache_raw_collect (current_regcache, regnum, buf); for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++) { errno = 0; ptrace (PT_WRITE_U, pid, (PTRACE_TYPE_ARG3)addr, buf[i]); if (errno != 0) error (_("Couldn't write register %s (#%d): %s."), REGISTER_NAME (regnum), regnum, safe_strerror (errno)); addr += sizeof (PTRACE_TYPE_RET); } }
static void inf_ptrace_fetch_register (struct regcache *regcache, int regnum) { struct gdbarch *gdbarch = get_regcache_arch (regcache); CORE_ADDR addr; size_t size; PTRACE_TYPE_RET *buf; int pid, i; /* This isn't really an address, but ptrace thinks of it as one. */ addr = inf_ptrace_register_u_offset (gdbarch, regnum, 0); if (addr == (CORE_ADDR)-1 || gdbarch_cannot_fetch_register (gdbarch, regnum)) { regcache_raw_supply (regcache, regnum, NULL); return; } /* Cater for systems like GNU/Linux, that implement threads as separate processes. */ pid = ptid_get_lwp (inferior_ptid); if (pid == 0) pid = ptid_get_pid (inferior_ptid); size = register_size (gdbarch, regnum); gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0); buf = alloca (size); /* Read the register contents from the inferior a chunk at a time. */ for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++) { errno = 0; buf[i] = ptrace (PT_READ_U, pid, (PTRACE_TYPE_ARG3)(uintptr_t)addr, 0); if (errno != 0) error (_("Couldn't read register %s (#%d): %s."), gdbarch_register_name (gdbarch, regnum), regnum, safe_strerror (errno)); addr += sizeof (PTRACE_TYPE_RET); } regcache_raw_supply (regcache, regnum, buf); }