Author: Martin Storsjö Date: 2022-09-26T11:05:42+03:00 New Revision: 8a3597d73c8f694ca8c991d8cb4bb97a4ac8ba8c
URL: https://github.com/llvm/llvm-project/commit/8a3597d73c8f694ca8c991d8cb4bb97a4ac8ba8c DIFF: https://github.com/llvm/llvm-project/commit/8a3597d73c8f694ca8c991d8cb4bb97a4ac8ba8c.diff LOG: [lldb] Fix CommandInterpreter::DidProcessStopAbnormally() with multiple threads If a process has multiple threads, the thread with the stop info might not be the first one in the thread list. On Windows, under certain circumstances, processes seem to have one or more extra threads that haven't been launched by the executable itself, waiting in NtWaitForWorkViaWorkerFactory. If the main (stopped) thread isn't the first one in the list (the order seems nondeterministic), DidProcessStopAbnormally() would return false prematurely, instead of inspecting later threads. The main observable effect of DidProcessStopAbnormally() erroneously returning false, is when running lldb with multiple "-o" parameters to specify multiple commands to execute on the command line. After an abnormal stop, lldb would stop executing "-o" parameters and execute "-k" parameters instead - but due to this issue, it would instead keep executing "-o" parameters as if there was no abnormal stop. (If multiple parameters are specified via a script file via the "-s" option, all of the commands in that file are executed regardless of whether there's an abnormal stop inbetween.) Differential Revision: https://reviews.llvm.org/D134037 Added: lldb/test/Shell/Driver/CommandOnCrashMultiThreaded.test lldb/test/Shell/Driver/Inputs/CommandOnCrashMultiThreaded.cpp Modified: lldb/source/Interpreter/CommandInterpreter.cpp Removed: ################################################################################ diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index fa6511635e287..5c11b87dcbe03 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -2471,8 +2471,12 @@ bool CommandInterpreter::DidProcessStopAbnormally() const { for (const auto &thread_sp : process_sp->GetThreadList().Threads()) { StopInfoSP stop_info = thread_sp->GetStopInfo(); - if (!stop_info) - return false; + if (!stop_info) { + // If there's no stop_info, keep iterating through the other threads; + // it's enough that any thread has got a stop_info that indicates + // an abnormal stop, to consider the process to be stopped abnormally. + continue; + } const StopReason reason = stop_info->GetStopReason(); if (reason == eStopReasonException || diff --git a/lldb/test/Shell/Driver/CommandOnCrashMultiThreaded.test b/lldb/test/Shell/Driver/CommandOnCrashMultiThreaded.test new file mode 100644 index 0000000000000..b16cfc5763715 --- /dev/null +++ b/lldb/test/Shell/Driver/CommandOnCrashMultiThreaded.test @@ -0,0 +1,5 @@ +# REQUIRES: native && (target-x86 || target-x86_64) +# RUN: %clangxx_host %p/Inputs/CommandOnCrashMultiThreaded.cpp -o %t -pthread +# RUN: %lldb -b -o "process launch" -k "process continue" -k "exit" %t | FileCheck %s + +# CHECK: Process {{[0-9]+}} exited with status = 0 diff --git a/lldb/test/Shell/Driver/Inputs/CommandOnCrashMultiThreaded.cpp b/lldb/test/Shell/Driver/Inputs/CommandOnCrashMultiThreaded.cpp new file mode 100644 index 0000000000000..f469d82fbbef9 --- /dev/null +++ b/lldb/test/Shell/Driver/Inputs/CommandOnCrashMultiThreaded.cpp @@ -0,0 +1,13 @@ +#include <thread> + +void t_func() { + asm volatile( + "int3\n\t" + ); +} + +int main() { + std::thread t(t_func); + t.join(); + return 0; +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits