Skip to content

Commit 5fe407e

Browse files
committed
[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 (cherry picked from commit 2436c57)
1 parent 3129ca5 commit 5fe407e

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

lldb/include/lldb/Core/IOHandler.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,7 @@ class IOHandler {
163163

164164
void WaitForPop();
165165

166-
virtual void PrintAsync(Stream *stream, const char *s, size_t len) {
167-
stream->Write(s, len);
168-
stream->Flush();
169-
}
166+
virtual void PrintAsync(const char *s, size_t len, bool is_stdout);
170167

171168
protected:
172169
Debugger &m_debugger;
@@ -415,7 +412,7 @@ class IOHandlerEditline : public IOHandler {
415412

416413
uint32_t GetCurrentLineIndex() const;
417414

418-
void PrintAsync(Stream *stream, const char *s, size_t len) override;
415+
void PrintAsync(const char *s, size_t len, bool is_stdout) override;
419416

420417
private:
421418
#if LLDB_ENABLE_LIBEDIT
@@ -558,7 +555,7 @@ class IOHandlerStack {
558555
return m_repl_enabled;
559556
}
560557

561-
void PrintAsync(Stream *stream, const char *s, size_t len);
558+
bool PrintAsync(const char *s, size_t len, bool is_stdout);
562559

563560
protected:
564561
void UpdateREPLIsActive() {

lldb/source/Core/Debugger.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,9 +1069,12 @@ bool Debugger::CheckTopIOHandlerTypes(IOHandler::Type top_type,
10691069
}
10701070

10711071
void Debugger::PrintAsync(const char *s, size_t len, bool is_stdout) {
1072-
lldb_private::StreamFile &stream =
1073-
is_stdout ? GetOutputStream() : GetErrorStream();
1074-
m_io_handler_stack.PrintAsync(&stream, s, len);
1072+
bool printed = m_io_handler_stack.PrintAsync(s, len, is_stdout);
1073+
if (!printed) {
1074+
lldb::StreamFileSP stream =
1075+
is_stdout ? m_output_stream_sp : m_error_stream_sp;
1076+
stream->Write(s, len);
1077+
}
10751078
}
10761079

10771080
ConstString Debugger::GetTopIOHandlerControlSequence(char ch) {

lldb/source/Core/IOHandler.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,18 @@ void IOHandler::SetPopped(bool b) { m_popped.SetValue(b, eBroadcastOnChange); }
122122

123123
void IOHandler::WaitForPop() { m_popped.WaitForValueEqualTo(true); }
124124

125-
void IOHandlerStack::PrintAsync(Stream *stream, const char *s, size_t len) {
126-
if (stream) {
127-
std::lock_guard<std::recursive_mutex> guard(m_mutex);
128-
if (m_top)
129-
m_top->PrintAsync(stream, s, len);
130-
else
131-
stream->Write(s, len);
132-
}
125+
void IOHandler::PrintAsync(const char *s, size_t len, bool is_stdout) {
126+
lldb::StreamFileSP stream = is_stdout ? m_output_sp : m_error_sp;
127+
stream->Write(s, len);
128+
stream->Flush();
129+
}
130+
131+
bool IOHandlerStack::PrintAsync(const char *s, size_t len, bool is_stdout) {
132+
std::lock_guard<std::recursive_mutex> guard(m_mutex);
133+
if (!m_top)
134+
return false;
135+
m_top->PrintAsync(s, len, is_stdout);
136+
return true;
133137
}
134138

135139
IOHandlerConfirm::IOHandlerConfirm(Debugger &debugger, llvm::StringRef prompt,
@@ -615,11 +619,12 @@ void IOHandlerEditline::GotEOF() {
615619
#endif
616620
}
617621

618-
void IOHandlerEditline::PrintAsync(Stream *stream, const char *s, size_t len) {
622+
void IOHandlerEditline::PrintAsync(const char *s, size_t len, bool is_stdout) {
619623
#if LLDB_ENABLE_LIBEDIT
620-
if (m_editline_up)
621-
m_editline_up->PrintAsync(stream, s, len);
622-
else
624+
if (m_editline_up) {
625+
lldb::StreamFileSP stream = is_stdout ? m_output_sp : m_error_sp;
626+
m_editline_up->PrintAsync(stream.get(), s, len);
627+
} else
623628
#endif
624629
{
625630
#ifdef _WIN32
@@ -636,7 +641,7 @@ void IOHandlerEditline::PrintAsync(Stream *stream, const char *s, size_t len) {
636641
SetConsoleCursorPosition(console_handle, coord);
637642
}
638643
#endif
639-
IOHandler::PrintAsync(stream, s, len);
644+
IOHandler::PrintAsync(s, len, is_stdout);
640645
#ifdef _WIN32
641646
if (prompt)
642647
IOHandler::PrintAsync(GetOutputStreamFileSP().get(), prompt,

0 commit comments

Comments
 (0)