From 075876e8b2377d89ddf2a6c43b503d61b6fde5b9 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 5 Oct 2024 03:27:02 +0200 Subject: [PATCH] ProcessStub: limit ptrace only to Linux The current code tries to use Linux ptrace on any OSes different than Windows and macOS, leading to build failure on other non-Linux OSes. Fix this in a couple of places: - in onInferiorStarted(), create a new Linux block for the code not run on Windows and macOS - in onInferiorStarted(), add a new block for any other OS to do the needed sendPid() call - in setupUnixInferior(), drop the global !Q_OS_WIN, and limit the setChildProcessModifier() call with ptrace calls to Linux Change-Id: Idfde3ee890eb94c6972343b70d0fe639a36343ae Reviewed-by: Marcus Tillmanns --- src/tools/process_stub/main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/tools/process_stub/main.cpp b/src/tools/process_stub/main.cpp index 3749333e460..1ab190b652d 100644 --- a/src/tools/process_stub/main.cpp +++ b/src/tools/process_stub/main.cpp @@ -254,8 +254,7 @@ void onInferiorStarted() // In debug mode we use the poll timer to send the pid. if (!debugMode) sendPid(inferiorId); -#else - +#elif defined(Q_OS_LINUX) if (debugMode) { qCInfo(log) << "Waiting for SIGTRAP from inferiors execve ..."; if (!waitFor(SIGTRAP)) @@ -271,12 +270,13 @@ void onInferiorStarted() qCInfo(log) << "Sending pid:" << inferiorId; sendPid(inferiorId); +#else + sendPid(inferiorId); #endif } void setupUnixInferior() { -#ifndef Q_OS_WIN if (debugMode) { qCInfo(log) << "Debug mode enabled"; #ifdef Q_OS_DARWIN @@ -287,7 +287,7 @@ void setupUnixInferior() // Suspend ourselves ... raise(SIGSTOP); }); -#else +#elif defined(Q_OS_LINUX) // PTRACE_TRACEME will stop execution of the child process as soon as execve is called. inferiorProcess.setChildProcessModifier([] { ptrace(PTRACE_TRACEME, 0, 0, 0); @@ -296,7 +296,6 @@ void setupUnixInferior() }); #endif } -#endif } void setupWindowsInferior()