Index: lldb/include/lldb/Utility/Stream.h =================================================================== --- lldb/include/lldb/Utility/Stream.h +++ lldb/include/lldb/Utility/Stream.h @@ -19,6 +19,7 @@ #include #include #include +#include #include namespace lldb_private { @@ -44,7 +45,6 @@ Stream *m_stream; /// Bytes we have written so far when ByteDelta was created. size_t m_start; - public: ByteDelta(Stream &s) : m_stream(&s), m_start(s.GetWrittenBytes()) {} /// Returns the number of bytes written to the given Stream since this @@ -412,6 +412,26 @@ RawOstreamForward m_forwarder; }; +template class LockableStream : public T { +public: + using T::T; + ~LockableStream() = default; + + void Flush() override { + std::lock_guard guard(m_mutex); + T::Flush(); + } + +protected: + size_t WriteImpl(const void *s, size_t length) override { + std::lock_guard guard(m_mutex); + return T::WriteImpl(s, length); + } + +private: + M m_mutex; +}; + /// Output an address value to this stream. /// /// Put an address \a addr out to the stream with optional \a prefix and \a Index: lldb/source/Core/Debugger.cpp =================================================================== --- lldb/source/Core/Debugger.cpp +++ lldb/source/Core/Debugger.cpp @@ -733,8 +733,10 @@ : UserID(g_unique_id++), Properties(std::make_shared()), m_input_file_sp(std::make_shared(stdin, false)), - m_output_stream_sp(std::make_shared(stdout, false)), - m_error_stream_sp(std::make_shared(stderr, false)), + m_output_stream_sp( + std::make_shared>(stdout, false)), + m_error_stream_sp( + std::make_shared>(stderr, false)), m_input_recorder(nullptr), m_broadcaster_manager_sp(BroadcasterManager::MakeBroadcasterManager()), m_terminal_state(), m_target_list(*this), m_platform_list(),