diff options
author | Dmitry Vasilyev <dvassiliev@accesssoftek.com> | 2024-07-31 17:51:06 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-31 17:51:06 +0400 |
commit | 93fecc2577ece0329f3bbe2719bbc5b4b9b30010 (patch) | |
tree | cefe307988e7de70bc03a518e2f15c1b77f30fe5 | |
parent | 569d8ce11f25aeb1596bd791905b16e73359470e (diff) | |
download | llvm-93fecc2577ece0329f3bbe2719bbc5b4b9b30010.zip llvm-93fecc2577ece0329f3bbe2719bbc5b4b9b30010.tar.gz llvm-93fecc2577ece0329f3bbe2719bbc5b4b9b30010.tar.bz2 |
[lldb] Fixed lldb-server crash (TestLogHandler was not thread safe) (#101326)
Host::LaunchProcess() requires to SetMonitorProcessCallback. This
callback is called from the child process monitor thread. We cannot
control this thread anyway. lldb-server may crash if there is a logging
around this callback because TestLogHandler is not thread safe. I faced
this issue debugging 100 simultaneous child processes. Note
StreamLogHandler::Emit() in lldb/source/Utility/Log.cpp already contains
the similar mutex.
-rw-r--r-- | lldb/tools/lldb-server/LLDBServerUtilities.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lldb/tools/lldb-server/LLDBServerUtilities.cpp b/lldb/tools/lldb-server/LLDBServerUtilities.cpp index c3a8df1..5facfbf 100644 --- a/lldb/tools/lldb-server/LLDBServerUtilities.cpp +++ b/lldb/tools/lldb-server/LLDBServerUtilities.cpp @@ -27,11 +27,13 @@ public: : m_stream_sp(stream_sp) {} void Emit(llvm::StringRef message) override { + std::lock_guard<std::mutex> guard(m_mutex); (*m_stream_sp) << message; m_stream_sp->flush(); } private: + std::mutex m_mutex; std::shared_ptr<raw_ostream> m_stream_sp; }; |