diff options
author | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2023-08-09 10:14:04 +0200 |
---|---|---|
committer | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2023-08-10 08:14:29 +0000 |
commit | f13d9cc736aa3d62018fa596231255f5617fff51 (patch) | |
tree | 0f4c98572e434deedc2587d9af5c27135f3e47b6 | |
parent | d1deeb2c0d2c3f22be7d970e5e0f166f5101667b (diff) |
ProcessStub: Wait for detach to finish
Without calling waitpid() after detaching from the inferior
a race condition could occur where the ptrace(...) call would
finish before it was actually detached, leading to the following
gdb to fail attaching as the stub was still attached to it.
Calling waitpid here solves the race condition.
Fixes: QTCREATORBUG-29463
Change-Id: Ia1d79a18a96078bbf72589bebbc7d7ac027dea0d
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
-rw-r--r-- | src/tools/process_stub/main.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/tools/process_stub/main.cpp b/src/tools/process_stub/main.cpp index 00312b833f..dfd9ce5613 100644 --- a/src/tools/process_stub/main.cpp +++ b/src/tools/process_stub/main.cpp @@ -24,6 +24,7 @@ #ifdef Q_OS_LINUX #include <sys/ptrace.h> +#include <sys/wait.h> #endif #include <iostream> @@ -221,7 +222,23 @@ void onInferiorStarted() if (!debugMode) sendPid(inferiorId); #else + qCInfo(log) << "Detaching ..."; ptrace(PTRACE_DETACH, inferiorId, 0, SIGSTOP); + + // Wait until the process actually finished detaching + int status = 0; + waitpid(inferiorId, &status, WUNTRACED); + if (log().isInfoEnabled()) { + if (WIFEXITED(status)) + qCInfo(log) << "inferior exited, status=" << WEXITSTATUS(status); + else if (WIFSIGNALED(status)) + qCInfo(log) << "inferior killed by signal" << WTERMSIG(status); + else if (WIFSTOPPED(status)) + qCInfo(log) << "inferior stopped by signal" << WSTOPSIG(status); + else if (WIFCONTINUED(status)) + qCInfo(log) << "inferior continued"; + } + sendPid(inferiorId); #endif } |