Author: Jonas Devlieghere Date: 2022-03-14T10:11:50-07:00 New Revision: 2436c5703e6a33be1d002d3acebc6cbc1bfe678e
URL: https://github.com/llvm/llvm-project/commit/2436c5703e6a33be1d002d3acebc6cbc1bfe678e DIFF: https://github.com/llvm/llvm-project/commit/2436c5703e6a33be1d002d3acebc6cbc1bfe678e.diff LOG: [lldb] Use the IOHandler's stream instead of the debugger's in PrintAsync PrintAsync is relying on the IOHandler to print to the output/error stream. In that context it doesn't make much sense that this is using the debugger's streams rather than the one from the IOHandler. Differential revision: https://reviews.llvm.org/D121536 Added: Modified: lldb/include/lldb/Core/IOHandler.h lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Core/IOHandler.h b/lldb/include/lldb/Core/IOHandler.h index c717d1d872564..d58ad68a099c6 100644 --- a/lldb/include/lldb/Core/IOHandler.h +++ b/lldb/include/lldb/Core/IOHandler.h @@ -163,10 +163,7 @@ class IOHandler { void WaitForPop(); - virtual void PrintAsync(Stream *stream, const char *s, size_t len) { - stream->Write(s, len); - stream->Flush(); - } + virtual void PrintAsync(const char *s, size_t len, bool is_stdout); protected: Debugger &m_debugger; @@ -415,7 +412,7 @@ class IOHandlerEditline : public IOHandler { uint32_t GetCurrentLineIndex() const; - void PrintAsync(Stream *stream, const char *s, size_t len) override; + void PrintAsync(const char *s, size_t len, bool is_stdout) override; private: #if LLDB_ENABLE_LIBEDIT @@ -540,7 +537,7 @@ class IOHandlerStack { return ((m_top != nullptr) ? m_top->GetHelpPrologue() : nullptr); } - void PrintAsync(Stream *stream, const char *s, size_t len); + bool PrintAsync(const char *s, size_t len, bool is_stdout); protected: typedef std::vector<lldb::IOHandlerSP> collection; diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index d59c1e0891050..9764b0bc88c5f 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -1069,9 +1069,12 @@ bool Debugger::CheckTopIOHandlerTypes(IOHandler::Type top_type, } void Debugger::PrintAsync(const char *s, size_t len, bool is_stdout) { - lldb_private::StreamFile &stream = - is_stdout ? GetOutputStream() : GetErrorStream(); - m_io_handler_stack.PrintAsync(&stream, s, len); + bool printed = m_io_handler_stack.PrintAsync(s, len, is_stdout); + if (!printed) { + lldb::StreamFileSP stream = + is_stdout ? m_output_stream_sp : m_error_stream_sp; + stream->Write(s, len); + } } ConstString Debugger::GetTopIOHandlerControlSequence(char ch) { diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index 179b60c3586e7..86104d949685a 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -122,14 +122,18 @@ void IOHandler::SetPopped(bool b) { m_popped.SetValue(b, eBroadcastOnChange); } void IOHandler::WaitForPop() { m_popped.WaitForValueEqualTo(true); } -void IOHandlerStack::PrintAsync(Stream *stream, const char *s, size_t len) { - if (stream) { - std::lock_guard<std::recursive_mutex> guard(m_mutex); - if (m_top) - m_top->PrintAsync(stream, s, len); - else - stream->Write(s, len); - } +void IOHandler::PrintAsync(const char *s, size_t len, bool is_stdout) { + lldb::StreamFileSP stream = is_stdout ? m_output_sp : m_error_sp; + stream->Write(s, len); + stream->Flush(); +} + +bool IOHandlerStack::PrintAsync(const char *s, size_t len, bool is_stdout) { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + if (!m_top) + return false; + m_top->PrintAsync(s, len, is_stdout); + return true; } IOHandlerConfirm::IOHandlerConfirm(Debugger &debugger, llvm::StringRef prompt, @@ -612,11 +616,12 @@ void IOHandlerEditline::GotEOF() { #endif } -void IOHandlerEditline::PrintAsync(Stream *stream, const char *s, size_t len) { +void IOHandlerEditline::PrintAsync(const char *s, size_t len, bool is_stdout) { #if LLDB_ENABLE_LIBEDIT - if (m_editline_up) - m_editline_up->PrintAsync(stream, s, len); - else + if (m_editline_up) { + lldb::StreamFileSP stream = is_stdout ? m_output_sp : m_error_sp; + m_editline_up->PrintAsync(stream.get(), s, len); + } else #endif { #ifdef _WIN32 @@ -633,7 +638,7 @@ void IOHandlerEditline::PrintAsync(Stream *stream, const char *s, size_t len) { SetConsoleCursorPosition(console_handle, coord); } #endif - IOHandler::PrintAsync(stream, s, len); + IOHandler::PrintAsync(s, len, is_stdout); #ifdef _WIN32 if (prompt) IOHandler::PrintAsync(GetOutputStreamFileSP().get(), prompt, _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits