[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.
This commit is contained in:
Chelsea Cassanova
2025-06-18 13:06:20 -07:00
committed by GitHub
parent 23b8f11b27
commit a630ca6f6c
5 changed files with 72 additions and 0 deletions

View File

@@ -307,6 +307,10 @@ public:
llvm::StringRef GetShowProgressAnsiSuffix() const;
llvm::StringRef GetDisabledAnsiPrefix() const;
llvm::StringRef GetDisabledAnsiSuffix() const;
bool GetUseAutosuggestion() const;
llvm::StringRef GetAutosuggestionAnsiPrefix() const;

View File

@@ -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) {

View File

@@ -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,

View File

@@ -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);

View File

@@ -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()