Skip to content

Commit 990d0c7

Browse files
committed
[lldb] Print diagnostic prefixes (error, warning) in color
Print diagnostic prefixes (error, warning) in their respective colors when colors are enabled.
1 parent 12e137a commit 990d0c7

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

lldb/include/lldb/Core/StreamAsynchronousIO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Debugger;
2020

2121
class StreamAsynchronousIO : public Stream {
2222
public:
23-
StreamAsynchronousIO(Debugger &debugger, bool for_stdout);
23+
StreamAsynchronousIO(Debugger &debugger, bool for_stdout, bool colors);
2424

2525
~StreamAsynchronousIO() override;
2626

lldb/source/Core/Debugger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,11 +1201,11 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) {
12011201
}
12021202

12031203
StreamSP Debugger::GetAsyncOutputStream() {
1204-
return std::make_shared<StreamAsynchronousIO>(*this, true);
1204+
return std::make_shared<StreamAsynchronousIO>(*this, true, GetUseColor());
12051205
}
12061206

12071207
StreamSP Debugger::GetAsyncErrorStream() {
1208-
return std::make_shared<StreamAsynchronousIO>(*this, false);
1208+
return std::make_shared<StreamAsynchronousIO>(*this, false, GetUseColor());
12091209
}
12101210

12111211
size_t Debugger::GetNumDebuggers() {

lldb/source/Core/DebuggerEvents.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/Core/DebuggerEvents.h"
10+
#include "llvm/Support/WithColor.h"
1011

1112
using namespace lldb_private;
1213

@@ -56,7 +57,12 @@ llvm::StringRef DiagnosticEventData::GetPrefix() const {
5657
}
5758

5859
void DiagnosticEventData::Dump(Stream *s) const {
59-
*s << GetPrefix() << ": " << GetMessage() << '\n';
60+
llvm::HighlightColor color = m_type == Type::Warning
61+
? llvm::HighlightColor::Warning
62+
: llvm::HighlightColor::Error;
63+
llvm::WithColor(s->AsRawOstream(), color, llvm::ColorMode::Enable)
64+
<< GetPrefix();
65+
*s << ": " << GetMessage() << '\n';
6066
s->Flush();
6167
}
6268

lldb/source/Core/StreamAsynchronousIO.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
using namespace lldb;
1515
using namespace lldb_private;
1616

17-
StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout)
18-
: Stream(0, 4, eByteOrderBig), m_debugger(debugger), m_data(),
17+
StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout,
18+
bool colors)
19+
: Stream(0, 4, eByteOrderBig, colors), m_debugger(debugger), m_data(),
1920
m_for_stdout(for_stdout) {}
2021

2122
StreamAsynchronousIO::~StreamAsynchronousIO() {

0 commit comments

Comments
 (0)