[Lldb-commits] [lldb] [lldb][breakpoint] Grey out disabled breakpoints (PR #91404)
Chelsea Cassanova via lldb-commits
lldb-commits at lists.llvm.org
Fri Jun 13 16:56:30 PDT 2025
https://github.com/chelcassanova updated https://github.com/llvm/llvm-project/pull/91404
>From 8608a949e6579f9ee69961ceabf8158a6b91b208 Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova <chelsea_cassanova at 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/Core/Debugger.h | 4 +++
lldb/source/Breakpoint/Breakpoint.cpp | 15 +++++++++++
lldb/source/Core/CoreProperties.td | 16 ++++++++++++
lldb/source/Core/Debugger.cpp | 12 +++++++++
.../API/terminal/TestDisabledBreakpoints.py | 25 +++++++++++++++++++
5 files changed, 72 insertions(+)
create mode 100644 lldb/test/API/terminal/TestDisabledBreakpoints.py
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index 0595125b1813d..0fd4545e8425d 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -302,6 +302,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..d48520b02f9e0 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);
+ // Grey out any disabled breakpoints in the list of breakpoints.
+ if (!IsEnabled())
+ if (s->AsRawOstream().colors_enabled())
+ 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 (s->AsRawOstream().colors_enabled())
+ 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 a1a4e994c3b9c..20421360e93c4 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 1a0723a2f3b3f..b195798482601 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