[Lldb-commits] [lldb] 990d0c7 - [lldb] Print diagnostic prefixes (error, warning) in color

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 12 20:28:35 PDT 2022


Author: Jonas Devlieghere
Date: 2022-04-12T20:28:29-07:00
New Revision: 990d0c71090836fb117e72c262d6d19b76f346cc

URL: https://github.com/llvm/llvm-project/commit/990d0c71090836fb117e72c262d6d19b76f346cc
DIFF: https://github.com/llvm/llvm-project/commit/990d0c71090836fb117e72c262d6d19b76f346cc.diff

LOG: [lldb] Print diagnostic prefixes (error, warning) in color

Print diagnostic prefixes (error, warning) in their respective colors
when colors are enabled.

Added: 
    

Modified: 
    lldb/include/lldb/Core/StreamAsynchronousIO.h
    lldb/source/Core/Debugger.cpp
    lldb/source/Core/DebuggerEvents.cpp
    lldb/source/Core/StreamAsynchronousIO.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Core/StreamAsynchronousIO.h b/lldb/include/lldb/Core/StreamAsynchronousIO.h
index 30eff55b2e51a..b7adbc42096ce 100644
--- a/lldb/include/lldb/Core/StreamAsynchronousIO.h
+++ b/lldb/include/lldb/Core/StreamAsynchronousIO.h
@@ -20,7 +20,7 @@ class Debugger;
 
 class StreamAsynchronousIO : public Stream {
 public:
-  StreamAsynchronousIO(Debugger &debugger, bool for_stdout);
+  StreamAsynchronousIO(Debugger &debugger, bool for_stdout, bool colors);
 
   ~StreamAsynchronousIO() override;
 

diff  --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index a812848c7e8b1..e7d3d6bd8b9ac 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -1201,11 +1201,11 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) {
 }
 
 StreamSP Debugger::GetAsyncOutputStream() {
-  return std::make_shared<StreamAsynchronousIO>(*this, true);
+  return std::make_shared<StreamAsynchronousIO>(*this, true, GetUseColor());
 }
 
 StreamSP Debugger::GetAsyncErrorStream() {
-  return std::make_shared<StreamAsynchronousIO>(*this, false);
+  return std::make_shared<StreamAsynchronousIO>(*this, false, GetUseColor());
 }
 
 size_t Debugger::GetNumDebuggers() {

diff  --git a/lldb/source/Core/DebuggerEvents.cpp b/lldb/source/Core/DebuggerEvents.cpp
index fdf55f68ce8e7..19693e91ab233 100644
--- a/lldb/source/Core/DebuggerEvents.cpp
+++ b/lldb/source/Core/DebuggerEvents.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Core/DebuggerEvents.h"
+#include "llvm/Support/WithColor.h"
 
 using namespace lldb_private;
 
@@ -56,7 +57,12 @@ llvm::StringRef DiagnosticEventData::GetPrefix() const {
 }
 
 void DiagnosticEventData::Dump(Stream *s) const {
-  *s << GetPrefix() << ": " << GetMessage() << '\n';
+  llvm::HighlightColor color = m_type == Type::Warning
+                                   ? llvm::HighlightColor::Warning
+                                   : llvm::HighlightColor::Error;
+  llvm::WithColor(s->AsRawOstream(), color, llvm::ColorMode::Enable)
+      << GetPrefix();
+  *s << ": " << GetMessage() << '\n';
   s->Flush();
 }
 

diff  --git a/lldb/source/Core/StreamAsynchronousIO.cpp b/lldb/source/Core/StreamAsynchronousIO.cpp
index 04195a6d13ea5..c2c64b61ab726 100644
--- a/lldb/source/Core/StreamAsynchronousIO.cpp
+++ b/lldb/source/Core/StreamAsynchronousIO.cpp
@@ -14,8 +14,9 @@
 using namespace lldb;
 using namespace lldb_private;
 
-StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout)
-    : Stream(0, 4, eByteOrderBig), m_debugger(debugger), m_data(),
+StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout,
+                                           bool colors)
+    : Stream(0, 4, eByteOrderBig, colors), m_debugger(debugger), m_data(),
       m_for_stdout(for_stdout) {}
 
 StreamAsynchronousIO::~StreamAsynchronousIO() {


        


More information about the lldb-commits mailing list