Author: Dmitry Vasilyev
Date: 2024-07-31T17:51:06+04:00
New Revision: 93fecc2577ece0329f3bbe2719bbc5b4b9b30010

URL: 
https://github.com/llvm/llvm-project/commit/93fecc2577ece0329f3bbe2719bbc5b4b9b30010
DIFF: 
https://github.com/llvm/llvm-project/commit/93fecc2577ece0329f3bbe2719bbc5b4b9b30010.diff

LOG: [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.

Added: 
    

Modified: 
    lldb/tools/lldb-server/LLDBServerUtilities.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/tools/lldb-server/LLDBServerUtilities.cpp 
b/lldb/tools/lldb-server/LLDBServerUtilities.cpp
index c3a8df19e969e..5facfbf3105e9 100644
--- a/lldb/tools/lldb-server/LLDBServerUtilities.cpp
+++ b/lldb/tools/lldb-server/LLDBServerUtilities.cpp
@@ -27,11 +27,13 @@ class TestLogHandler : public LogHandler {
       : 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;
 };
 


        
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to