https://github.com/chelcassanova updated 
https://github.com/llvm/llvm-project/pull/91404

>From 5724d6c77d29ad80e9ca03ce7ac1c3e6ed33afc0 Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova <chelsea_cassan...@apple.com>
Date: Thu, 9 May 2024 11:08:29 -0700
Subject: [PATCH] [lldb][breakpoint] Grey out disabled breakpoints

This commit adds colour settings to the list of breakpoints in order to
grey out breakpoints that have been disabled.
---
 lldb/include/lldb/API/SBStream.h      |  5 +++++
 lldb/include/lldb/Utility/Stream.h    |  8 ++++++++
 lldb/source/API/SBStream.cpp          | 10 ++++++++++
 lldb/source/Breakpoint/Breakpoint.cpp |  9 +++++++++
 lldb/source/Utility/Stream.cpp        |  8 ++++++++
 5 files changed, 40 insertions(+)

diff --git a/lldb/include/lldb/API/SBStream.h b/lldb/include/lldb/API/SBStream.h
index 0e33f05b69916..108ddc38b4028 100644
--- a/lldb/include/lldb/API/SBStream.h
+++ b/lldb/include/lldb/API/SBStream.h
@@ -12,6 +12,7 @@
 #include <cstdio>
 
 #include "lldb/API/SBDefines.h"
+#include "llvm/ADT/StringRef.h"
 
 namespace lldb {
 
@@ -43,6 +44,10 @@ class LLDB_API SBStream {
 
   void Print(const char *str);
 
+  bool HasColor();
+
+  void FormatAnsiTerminalCodes(llvm::StringRef format);
+
   void RedirectToFile(const char *path, bool append);
 
   void RedirectToFile(lldb::SBFile file);
diff --git a/lldb/include/lldb/Utility/Stream.h 
b/lldb/include/lldb/Utility/Stream.h
index 37bcdc9924171..1ab590202cd69 100644
--- a/lldb/include/lldb/Utility/Stream.h
+++ b/lldb/include/lldb/Utility/Stream.h
@@ -309,6 +309,12 @@ class Stream {
   ///     The current indentation level.
   unsigned GetIndentLevel() const;
 
+  /// Whether or not the stream is using color.
+  ///
+  /// \return
+  ///     The color setting of the stream.
+  bool HasColor();
+
   /// Indent the current line in the stream.
   ///
   /// Indent the current line using the current indentation level and print an
@@ -366,6 +372,8 @@ class Stream {
   ///     The optional C string format that can be overridden.
   void QuotedCString(const char *cstr, const char *format = "\"%s\"");
 
+  void FormatAnsiTerminalCodes(llvm::StringRef format);
+
   /// Set the address size in bytes.
   ///
   /// \param[in] addr_size
diff --git a/lldb/source/API/SBStream.cpp b/lldb/source/API/SBStream.cpp
index fc8f09a7bb9ae..bc0f3356d4753 100644
--- a/lldb/source/API/SBStream.cpp
+++ b/lldb/source/API/SBStream.cpp
@@ -11,6 +11,7 @@
 #include "lldb/API/SBFile.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/StreamFile.h"
+#include "lldb/Utility/AnsiTerminal.h"
 #include "lldb/Utility/Instrumentation.h"
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/Status.h"
@@ -77,6 +78,15 @@ void SBStream::Printf(const char *format, ...) {
   va_end(args);
 }
 
+bool SBStream::HasColor() {
+  return m_opaque_up->AsRawOstream().colors_enabled();
+}
+
+void SBStream::FormatAnsiTerminalCodes(llvm::StringRef format) {
+  if (HasColor())
+    Printf("%s", ansi::FormatAnsiTerminalCodes(format).c_str());
+}
+
 void SBStream::RedirectToFile(const char *path, bool append) {
   LLDB_INSTRUMENT_VA(this, path, append);
 
diff --git a/lldb/source/Breakpoint/Breakpoint.cpp 
b/lldb/source/Breakpoint/Breakpoint.cpp
index ae845e92762b9..95624f4ae3ad5 100644
--- a/lldb/source/Breakpoint/Breakpoint.cpp
+++ b/lldb/source/Breakpoint/Breakpoint.cpp
@@ -15,6 +15,7 @@
 #include "lldb/Breakpoint/BreakpointResolver.h"
 #include "lldb/Breakpoint/BreakpointResolverFileLine.h"
 #include "lldb/Core/Address.h"
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/SearchFilter.h"
@@ -26,6 +27,7 @@
 #include "lldb/Target/SectionLoadList.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/ThreadSpec.h"
+#include "lldb/Utility/AnsiTerminal.h"
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Stream.h"
@@ -837,6 +839,10 @@ void Breakpoint::GetDescription(Stream *s, 
lldb::DescriptionLevel level,
                                 bool show_locations) {
   assert(s != nullptr);
 
+  // Grey out any disabled breakpoints in the list of breakpoints.
+  if (!IsEnabled())
+    s->FormatAnsiTerminalCodes("${ansi.faint}");
+
   if (!m_kind_description.empty()) {
     if (level == eDescriptionLevelBrief) {
       s->PutCString(GetBreakpointKind());
@@ -933,6 +939,9 @@ void Breakpoint::GetDescription(Stream *s, 
lldb::DescriptionLevel level,
     }
     s->IndentLess();
   }
+
+  // Reset the colors back to normal if they were previously greyed out.
+  s->FormatAnsiTerminalCodes("${ansi.normal}");
 }
 
 void Breakpoint::GetResolverDescription(Stream *s) {
diff --git a/lldb/source/Utility/Stream.cpp b/lldb/source/Utility/Stream.cpp
index 89dce9fb0e1f7..e4ca9ad5a1f14 100644
--- a/lldb/source/Utility/Stream.cpp
+++ b/lldb/source/Utility/Stream.cpp
@@ -103,6 +103,11 @@ void Stream::QuotedCString(const char *cstr, const char 
*format) {
   Printf(format, cstr);
 }
 
+void Stream::FormatAnsiTerminalCodes(llvm::StringRef format) {
+  if (HasColor())
+    Printf("%s", ansi::FormatAnsiTerminalCodes(format).c_str());
+}
+
 // Put an address "addr" out to the stream with optional prefix and suffix
 // strings.
 void lldb_private::DumpAddress(llvm::raw_ostream &s, uint64_t addr,
@@ -186,6 +191,9 @@ Stream &Stream::operator<<(const void *p) {
 // Get the current indentation level
 unsigned Stream::GetIndentLevel() const { return m_indent_level; }
 
+// Get the color setting of the stream.
+bool Stream::HasColor() { return m_forwarder.colors_enabled(); }
+
 // Set the current indentation level
 void Stream::SetIndentLevel(unsigned indent_level) {
   m_indent_level = indent_level;

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to