Skip to content

Commit 2436c57

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
1 parent 250620f commit 2436c57

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
@@ -540,7 +537,7 @@ class IOHandlerStack {
540537
return ((m_top != nullptr) ? m_top->GetHelpPrologue() : nullptr);
541538
}
542539

543-
void PrintAsync(Stream *stream, const char *s, size_t len);
540+
bool PrintAsync(const char *s, size_t len, bool is_stdout);
544541

545542
protected:
546543
typedef std::vector<lldb::IOHandlerSP> collection;

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,
@@ -612,11 +616,12 @@ void IOHandlerEditline::GotEOF() {
612616
#endif
613617
}
614618

615-
void IOHandlerEditline::PrintAsync(Stream *stream, const char *s, size_t len) {
619+
void IOHandlerEditline::PrintAsync(const char *s, size_t len, bool is_stdout) {
616620
#if LLDB_ENABLE_LIBEDIT
617-
if (m_editline_up)
618-
m_editline_up->PrintAsync(stream, s, len);
619-
else
621+
if (m_editline_up) {
622+
lldb::StreamFileSP stream = is_stdout ? m_output_sp : m_error_sp;
623+
m_editline_up->PrintAsync(stream.get(), s, len);
624+
} else
620625
#endif
621626
{
622627
#ifdef _WIN32
@@ -633,7 +638,7 @@ void IOHandlerEditline::PrintAsync(Stream *stream, const char *s, size_t len) {
633638
SetConsoleCursorPosition(console_handle, coord);
634639
}
635640
#endif
636-
IOHandler::PrintAsync(stream, s, len);
641+
IOHandler::PrintAsync(s, len, is_stdout);
637642
#ifdef _WIN32
638643
if (prompt)
639644
IOHandler::PrintAsync(GetOutputStreamFileSP().get(), prompt,

0 commit comments

Comments
 (0)