[Lldb-commits] [lldb] a630ca6 - [lldb][breakpoint] Grey out disabled breakpoints (#91404)

via lldb-commits lldb-commits at lists.llvm.org
Wed Jun 18 13:06:24 PDT 2025


Author: Chelsea Cassanova
Date: 2025-06-18T13:06:20-07:00
New Revision: a630ca6f6c4727d852d60076d1179c3e9830ca2f

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

LOG: [lldb][breakpoint] Grey out disabled breakpoints (#91404)

This commit adds colour settings to the list of breakpoints in order to
grey out breakpoints that have been disabled.

Added: 
    lldb/test/API/terminal/TestDisabledBreakpoints.py

Modified: 
    lldb/include/lldb/Core/Debugger.h
    lldb/source/Breakpoint/Breakpoint.cpp
    lldb/source/Core/CoreProperties.td
    lldb/source/Core/Debugger.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index d73aba1e3ce58..2087ef2a11562 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -307,6 +307,10 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
 
   llvm::StringRef GetShowProgressAnsiSuffix() const;
 
+  llvm::StringRef GetDisabledAnsiPrefix() const;
+
+  llvm::StringRef GetDisabledAnsiSuffix() const;
+
   bool GetUseAutosuggestion() const;
 
   llvm::StringRef GetAutosuggestionAnsiPrefix() const;

diff  --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp
index 337c1a4ac401f..2ed0c9314e3e1 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"
@@ -838,6 +840,13 @@ void Breakpoint::GetDescription(Stream *s, lldb::DescriptionLevel level,
                                 bool show_locations) {
   assert(s != nullptr);
 
+  const bool dim_breakpoint_description =
+      !IsEnabled() && s->AsRawOstream().colors_enabled();
+  if (dim_breakpoint_description)
+    s->Printf("%s", ansi::FormatAnsiTerminalCodes(
+                        GetTarget().GetDebugger().GetDisabledAnsiPrefix())
+                        .c_str());
+
   if (!m_kind_description.empty()) {
     if (level == eDescriptionLevelBrief) {
       s->PutCString(GetBreakpointKind());
@@ -934,6 +943,12 @@ void Breakpoint::GetDescription(Stream *s, lldb::DescriptionLevel level,
     }
     s->IndentLess();
   }
+
+  // Reset the colors back to normal if they were previously greyed out.
+  if (dim_breakpoint_description)
+    s->Printf("%s", ansi::FormatAnsiTerminalCodes(
+                        GetTarget().GetDebugger().GetDisabledAnsiSuffix())
+                        .c_str());
 }
 
 void Breakpoint::GetResolverDescription(Stream *s) {

diff  --git a/lldb/source/Core/CoreProperties.td b/lldb/source/Core/CoreProperties.td
index 4d1ea5dfec2eb..53dd333f045c9 100644
--- a/lldb/source/Core/CoreProperties.td
+++ b/lldb/source/Core/CoreProperties.td
@@ -191,6 +191,22 @@ let Definition = "debugger" in {
             "${separator}${thread.stop-reason}}{ "
             "${separator}{${progress.count} }${progress.message}}">,
         Desc<"The default statusline format string.">;
+
+  def ShowDisabledAnsiPrefix
+      : Property<"disable-ansi-prefix", "String">,
+        Global,
+        DefaultStringValue<"${ansi.faint}">,
+        Desc<"If something has been disabled in a color-enabled terminal, use "
+             "the ANSI terminal code specified immediately before whatever has "
+             "been disabled.">;
+  def ShowDisabledAnsiSuffix
+      : Property<"disable-ansi-suffix", "String">,
+        Global,
+        DefaultStringValue<"${ansi.normal}">,
+        Desc<"When somehing has been disabled in a color-enabled terminal, use "
+             "the ANSI terminal code specified immediately after whatever has "
+             "been disabled.">;
+
   def UseSourceCache: Property<"use-source-cache", "Boolean">,
     Global,
     DefaultTrue,

diff  --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 81037d3def811..c9935f2d745fa 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -510,6 +510,18 @@ llvm::StringRef Debugger::GetSeparator() const {
       idx, g_debugger_properties[idx].default_cstr_value);
 }
 
+llvm::StringRef Debugger::GetDisabledAnsiPrefix() const {
+  const uint32_t idx = ePropertyShowDisabledAnsiPrefix;
+  return GetPropertyAtIndexAs<llvm::StringRef>(
+      idx, g_debugger_properties[idx].default_cstr_value);
+}
+
+llvm::StringRef Debugger::GetDisabledAnsiSuffix() const {
+  const uint32_t idx = ePropertyShowDisabledAnsiSuffix;
+  return GetPropertyAtIndexAs<llvm::StringRef>(
+      idx, g_debugger_properties[idx].default_cstr_value);
+}
+
 bool Debugger::SetSeparator(llvm::StringRef s) {
   constexpr uint32_t idx = ePropertySeparator;
   bool ret = SetPropertyAtIndex(idx, s);

diff  --git a/lldb/test/API/terminal/TestDisabledBreakpoints.py b/lldb/test/API/terminal/TestDisabledBreakpoints.py
new file mode 100644
index 0000000000000..a644c94c8a178
--- /dev/null
+++ b/lldb/test/API/terminal/TestDisabledBreakpoints.py
@@ -0,0 +1,25 @@
+"""
+Test that disabling breakpoints and viewing them in a list uses the correct ANSI color settings when colors are enabled and disabled.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test.lldbpexpect import PExpectTest
+
+import io
+
+
+class DisabledBreakpointsTest(PExpectTest):
+    @add_test_categories(["pexpect"])
+    def test_disabling_breakpoints_with_color(self):
+        """Test that disabling a breakpoint and viewing the breakpoints list uses the specified ANSI color prefix."""
+        ansi_red_color_code = "\x1b[31m"
+
+        self.launch(use_colors=True, dimensions=(100, 100))
+        self.expect('settings set disable-ansi-prefix "${ansi.fg.red}"')
+        self.expect("b main")
+        self.expect("br dis")
+        self.expect("br l", substrs=[ansi_red_color_code + "1:"])
+        self.quit()


        


More information about the lldb-commits mailing list