8307955: Prefer to PTRACE_GETREGSET instead of PTRACE_GETREGS in method 'ps_proc.c::process_get_lwp_regs'

Reviewed-by: rehn
Backport-of: 2f1c65486b1e584f9c4a2eb7af2414d032a02748
This commit is contained in:
Ludovic Henry 2024-01-23 07:59:25 +00:00 committed by Robbin Ehn
parent a6135d783d
commit 8162425079
1 changed files with 11 additions and 15 deletions

View File

@ -125,10 +125,6 @@ static bool process_write_data(struct ps_prochandle* ph,
static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct user_regs_struct *user) {
// we have already attached to all thread 'pid's, just use ptrace call
// to get regset now. Note that we don't cache regset upfront for processes.
// Linux on x86 and sparc are different. On x86 ptrace(PTRACE_GETREGS, ...)
// uses pointer from 4th argument and ignores 3rd argument. On sparc it uses
// pointer from 3rd argument and ignores 4th argument
#define ptrace_getregs(request, pid, addr, data) ptrace(request, pid, data, addr)
#if defined(_LP64) && defined(PTRACE_GETREGS64)
#define PTRACE_GETREGS_REQ PTRACE_GETREGS64
@ -138,14 +134,7 @@ static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct use
#define PTRACE_GETREGS_REQ PT_GETREGS
#endif
#ifdef PTRACE_GETREGS_REQ
if (ptrace_getregs(PTRACE_GETREGS_REQ, pid, user, NULL) < 0) {
print_debug("ptrace(PTRACE_GETREGS, ...) failed for lwp(%d) errno(%d) \"%s\"\n", pid,
errno, strerror(errno));
return false;
}
return true;
#elif defined(PTRACE_GETREGSET)
#if defined(PTRACE_GETREGSET)
struct iovec iov;
iov.iov_base = user;
iov.iov_len = sizeof(*user);
@ -154,6 +143,13 @@ static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct use
return false;
}
return true;
#elif defined(PTRACE_GETREGS_REQ)
if (ptrace(PTRACE_GETREGS_REQ, pid, NULL, user) < 0) {
print_debug("ptrace(PTRACE_GETREGS, ...) failed for lwp(%d) errno(%d) \"%s\"\n", pid,
errno, strerror(errno));
return false;
}
return true;
#else
print_debug("ptrace(PTRACE_GETREGS, ...) not supported\n");
return false;