From 4fcd8546573ddc0b933378f7aa8530103cf76910 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 14 May 2025 17:54:06 -0700 Subject: [PATCH] QTest::CrashHandler: switch to execvp() instead of execlp() There will be variable options. Change-Id: Ie633615daeac87e8bd2cfffd962666a85d91d5cd Reviewed-by: Ahmad Samir Reviewed-by: Edward Welbourne --- src/testlib/qtestcrashhandler_unix.cpp | 29 +++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/testlib/qtestcrashhandler_unix.cpp b/src/testlib/qtestcrashhandler_unix.cpp index 9bc0fd2fa9b..15ba4bb1c7f 100644 --- a/src/testlib/qtestcrashhandler_unix.cpp +++ b/src/testlib/qtestcrashhandler_unix.cpp @@ -383,20 +383,39 @@ void generateStackTrace() // child process (void) dup2(STDERR_FILENO, STDOUT_FILENO); // redirect stdout to stderr + struct Args { + std::array argv; + int count = 0; + Args &operator<<(const char *arg) + { + Q_ASSERT(count < int(argv.size())); + argv[count++] = arg; + return *this; + } + operator char **() const { return const_cast(argv.data()); } + } argv; + switch (debugger) { case None: Q_UNREACHABLE(); break; case Gdb: - execlp("gdb", "gdb", "--nx", "--batch", "-ex", "thread apply all bt", - "-ex", "info proc mappings", - "--pid", pidbuffer.array.data(), nullptr); + argv << "gdb" << "--nx" << "--batch" + << "-ex" << "thread apply all bt" + << "-ex" << "printf \"\\n\"" + << "-ex" << "info proc mappings" + << "--pid"; break; case Lldb: - execlp("lldb", "lldb", "--no-lldbinit", "--batch", "-o", "bt all", - "--attach-pid", pidbuffer.array.data(), nullptr); + argv << "lldb" << "--no-lldbinit" << "--batch" + << "-o" << "bt all" + << "--attach-pid"; break; } + if (argv.count) { + argv << pidbuffer.array.data() << nullptr; + execvp(argv.argv[0], argv); + } _exit(1); } else if (pid < 0) { writeToStderr("Failed to start debugger.\n");