tools/test/ptrace: update scescx to do remote getpid(2) on each SCX event

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37590
This commit is contained in:
Konstantin Belousov 2022-12-02 03:26:13 +02:00
parent a98613f238
commit 6403a14024

View File

@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h> #include <sys/types.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
#include <sys/syscall.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <assert.h> #include <assert.h>
@ -213,9 +214,13 @@ wait_info(int pid, int status, struct ptrace_lwpinfo *lwpinfo)
printf("\n"); printf("\n");
} }
static int trace_syscalls = 1;
static int remote_getpid = 0;
static int static int
trace_sc(int pid) trace_sc(int pid)
{ {
struct ptrace_sc_remote pscr;
struct ptrace_lwpinfo lwpinfo; struct ptrace_lwpinfo lwpinfo;
int status; int status;
@ -269,6 +274,24 @@ trace_sc(int pid)
wait_info(pid, status, &lwpinfo); wait_info(pid, status, &lwpinfo);
assert(lwpinfo.pl_flags & PL_FLAG_SCX); assert(lwpinfo.pl_flags & PL_FLAG_SCX);
if (remote_getpid) {
memset(&pscr, 0, sizeof(pscr));
pscr.pscr_syscall = SYS_getpid;
pscr.pscr_nargs = 0;
if (ptrace(PT_SC_REMOTE, pid, (caddr_t)&pscr,
sizeof(pscr)) < 0) {
perror("PT_SC_REMOTE");
ptrace(PT_KILL, pid, NULL, 0);
return (-1);
} else {
printf(TRACE "remote getpid %ld errno %d\n",
pscr.pscr_ret.sr_retval[0], pscr.pscr_ret.sr_error);
if (waitpid(pid, &status, 0) == -1) {
perror("waitpid");
return (-1);
}
}
}
if (lwpinfo.pl_flags & PL_FLAG_EXEC) if (lwpinfo.pl_flags & PL_FLAG_EXEC)
get_pathname(pid); get_pathname(pid);
@ -322,8 +345,6 @@ trace_cont(int pid)
return (0); return (0);
} }
static int trace_syscalls = 1;
static int static int
trace(pid_t pid) trace(pid_t pid)
{ {
@ -340,12 +361,16 @@ main(int argc, char *argv[])
pid_t pid, pid1; pid_t pid, pid1;
trace_syscalls = 1; trace_syscalls = 1;
remote_getpid = 0;
use_vfork = 0; use_vfork = 0;
while ((c = getopt(argc, argv, "csv")) != -1) { while ((c = getopt(argc, argv, "crsv")) != -1) {
switch (c) { switch (c) {
case 'c': case 'c':
trace_syscalls = 0; trace_syscalls = 0;
break; break;
case 'r':
remote_getpid = 1;
break;
case 's': case 's':
trace_syscalls = 1; trace_syscalls = 1;
break; break;
@ -354,7 +379,8 @@ main(int argc, char *argv[])
break; break;
default: default:
case '?': case '?':
fprintf(stderr, "Usage: %s [-c] [-s] [-v]\n", argv[0]); fprintf(stderr, "Usage: %s [-c] [-r] [-s] [-v]\n",
argv[0]);
return (2); return (2);
} }
} }