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 <marcus.tillmanns@qt.io>
This commit is contained in:
Pino Toscano
2024-10-05 03:27:02 +02:00
parent cd85bed2f7
commit 075876e8b2

View File

@@ -254,8 +254,7 @@ void onInferiorStarted()
// In debug mode we use the poll timer to send the pid. // In debug mode we use the poll timer to send the pid.
if (!debugMode) if (!debugMode)
sendPid(inferiorId); sendPid(inferiorId);
#else #elif defined(Q_OS_LINUX)
if (debugMode) { if (debugMode) {
qCInfo(log) << "Waiting for SIGTRAP from inferiors execve ..."; qCInfo(log) << "Waiting for SIGTRAP from inferiors execve ...";
if (!waitFor(SIGTRAP)) if (!waitFor(SIGTRAP))
@@ -271,12 +270,13 @@ void onInferiorStarted()
qCInfo(log) << "Sending pid:" << inferiorId; qCInfo(log) << "Sending pid:" << inferiorId;
sendPid(inferiorId); sendPid(inferiorId);
#else
sendPid(inferiorId);
#endif #endif
} }
void setupUnixInferior() void setupUnixInferior()
{ {
#ifndef Q_OS_WIN
if (debugMode) { if (debugMode) {
qCInfo(log) << "Debug mode enabled"; qCInfo(log) << "Debug mode enabled";
#ifdef Q_OS_DARWIN #ifdef Q_OS_DARWIN
@@ -287,7 +287,7 @@ void setupUnixInferior()
// Suspend ourselves ... // Suspend ourselves ...
raise(SIGSTOP); raise(SIGSTOP);
}); });
#else #elif defined(Q_OS_LINUX)
// PTRACE_TRACEME will stop execution of the child process as soon as execve is called. // PTRACE_TRACEME will stop execution of the child process as soon as execve is called.
inferiorProcess.setChildProcessModifier([] { inferiorProcess.setChildProcessModifier([] {
ptrace(PTRACE_TRACEME, 0, 0, 0); ptrace(PTRACE_TRACEME, 0, 0, 0);
@@ -296,7 +296,6 @@ void setupUnixInferior()
}); });
#endif #endif
} }
#endif
} }
void setupWindowsInferior() void setupWindowsInferior()