From 8e87d340c310c1ce4893cc5517d33aaf848eb808 Mon Sep 17 00:00:00 2001 From: Itamar Date: Sat, 11 Apr 2020 16:38:59 +0300 Subject: [PATCH] strace: Update ptrace() usage ptrace with PT_TRACEME was updated to also stop the traced thread on exit from execve. --- Userland/strace.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Userland/strace.cpp b/Userland/strace.cpp index 30d7bad9b7..b6687cfa58 100644 --- a/Userland/strace.cpp +++ b/Userland/strace.cpp @@ -60,11 +60,14 @@ int main(int argc, char** argv) if (argc == 1) return usage(); + bool spawned_new_process = false; + if (!strcmp(argv[1], "-p")) { if (argc != 3) return usage(); g_pid = atoi(argv[2]); } else { + spawned_new_process = true; int pid = fork(); if (!pid) { if (ptrace(PT_TRACE_ME, 0, 0, 0) == -1) { @@ -100,6 +103,18 @@ int main(int argc, char** argv) return 1; } + if (spawned_new_process) { + + if (ptrace(PT_CONTINUE, g_pid, 0, 0) < 0) { + perror("continue"); + return 1; + } + if (waitpid(g_pid, nullptr, WSTOPPED) != g_pid) { + perror("wait_pid"); + return 1; + } + } + for (;;) { if (ptrace(PT_SYSCALL, g_pid, 0, 0) == -1) { if (errno == ESRCH)