[Lldb-commits] [lldb] a335f33 - [lldb] Always lock in StreamLogHandler::Write (#205771)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Jun 26 03:22:27 PDT 2026
Author: Raphael Isemann
Date: 2026-06-26T11:22:21+01:00
New Revision: a335f334f512be44ac02a07ffae27468d246a07d
URL: https://github.com/llvm/llvm-project/commit/a335f334f512be44ac02a07ffae27468d246a07d
DIFF: https://github.com/llvm/llvm-project/commit/a335f334f512be44ac02a07ffae27468d246a07d.diff
LOG: [lldb] Always lock in StreamLogHandler::Write (#205771)
This code assumes that writing to an unbuffered raw_fd_ostream from
multiple threads is somehow safe. raw_fd_ostream doesn't make any
guarantees about this from what I can see.
The current raw_fd_ostream implementation also uses a looping write call
to write the content in chunks, and doing this from multiple threads
leads to interleaving log messages.
This patch unconditionally make us aquire the stream lock.
Added:
Modified:
lldb/source/Utility/Log.cpp
Removed:
################################################################################
diff --git a/lldb/source/Utility/Log.cpp b/lldb/source/Utility/Log.cpp
index 1921573996196..6b077a3766e9f 100644
--- a/lldb/source/Utility/Log.cpp
+++ b/lldb/source/Utility/Log.cpp
@@ -378,12 +378,8 @@ void StreamLogHandler::Flush() {
}
void StreamLogHandler::Emit(llvm::StringRef message) {
- if (m_stream.GetBufferSize() > 0) {
- std::lock_guard<std::mutex> guard(m_mutex);
- m_stream << message;
- } else {
- m_stream << message;
- }
+ std::lock_guard<std::mutex> guard(m_mutex);
+ m_stream << message;
}
CallbackLogHandler::CallbackLogHandler(lldb::LogOutputCallback callback,
More information about the lldb-commits
mailing list