Skip to content

Commit a630ca6

Browse files
[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.
1 parent 23b8f11 commit a630ca6

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
307307

308308
llvm::StringRef GetShowProgressAnsiSuffix() const;
309309

310+
llvm::StringRef GetDisabledAnsiPrefix() const;
311+
312+
llvm::StringRef GetDisabledAnsiSuffix() const;
313+
310314
bool GetUseAutosuggestion() const;
311315

312316
llvm::StringRef GetAutosuggestionAnsiPrefix() const;

lldb/source/Breakpoint/Breakpoint.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "lldb/Breakpoint/BreakpointResolver.h"
1616
#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
1717
#include "lldb/Core/Address.h"
18+
#include "lldb/Core/Debugger.h"
1819
#include "lldb/Core/Module.h"
1920
#include "lldb/Core/ModuleList.h"
2021
#include "lldb/Core/SearchFilter.h"
@@ -26,6 +27,7 @@
2627
#include "lldb/Target/SectionLoadList.h"
2728
#include "lldb/Target/Target.h"
2829
#include "lldb/Target/ThreadSpec.h"
30+
#include "lldb/Utility/AnsiTerminal.h"
2931
#include "lldb/Utility/LLDBLog.h"
3032
#include "lldb/Utility/Log.h"
3133
#include "lldb/Utility/Stream.h"
@@ -838,6 +840,13 @@ void Breakpoint::GetDescription(Stream *s, lldb::DescriptionLevel level,
838840
bool show_locations) {
839841
assert(s != nullptr);
840842

843+
const bool dim_breakpoint_description =
844+
!IsEnabled() && s->AsRawOstream().colors_enabled();
845+
if (dim_breakpoint_description)
846+
s->Printf("%s", ansi::FormatAnsiTerminalCodes(
847+
GetTarget().GetDebugger().GetDisabledAnsiPrefix())
848+
.c_str());
849+
841850
if (!m_kind_description.empty()) {
842851
if (level == eDescriptionLevelBrief) {
843852
s->PutCString(GetBreakpointKind());
@@ -934,6 +943,12 @@ void Breakpoint::GetDescription(Stream *s, lldb::DescriptionLevel level,
934943
}
935944
s->IndentLess();
936945
}
946+
947+
// Reset the colors back to normal if they were previously greyed out.
948+
if (dim_breakpoint_description)
949+
s->Printf("%s", ansi::FormatAnsiTerminalCodes(
950+
GetTarget().GetDebugger().GetDisabledAnsiSuffix())
951+
.c_str());
937952
}
938953

939954
void Breakpoint::GetResolverDescription(Stream *s) {

lldb/source/Core/CoreProperties.td

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,22 @@ let Definition = "debugger" in {
191191
"${separator}${thread.stop-reason}}{ "
192192
"${separator}{${progress.count} }${progress.message}}">,
193193
Desc<"The default statusline format string.">;
194+
195+
def ShowDisabledAnsiPrefix
196+
: Property<"disable-ansi-prefix", "String">,
197+
Global,
198+
DefaultStringValue<"${ansi.faint}">,
199+
Desc<"If something has been disabled in a color-enabled terminal, use "
200+
"the ANSI terminal code specified immediately before whatever has "
201+
"been disabled.">;
202+
def ShowDisabledAnsiSuffix
203+
: Property<"disable-ansi-suffix", "String">,
204+
Global,
205+
DefaultStringValue<"${ansi.normal}">,
206+
Desc<"When somehing has been disabled in a color-enabled terminal, use "
207+
"the ANSI terminal code specified immediately after whatever has "
208+
"been disabled.">;
209+
194210
def UseSourceCache: Property<"use-source-cache", "Boolean">,
195211
Global,
196212
DefaultTrue,

lldb/source/Core/Debugger.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,18 @@ llvm::StringRef Debugger::GetSeparator() const {
510510
idx, g_debugger_properties[idx].default_cstr_value);
511511
}
512512

513+
llvm::StringRef Debugger::GetDisabledAnsiPrefix() const {
514+
const uint32_t idx = ePropertyShowDisabledAnsiPrefix;
515+
return GetPropertyAtIndexAs<llvm::StringRef>(
516+
idx, g_debugger_properties[idx].default_cstr_value);
517+
}
518+
519+
llvm::StringRef Debugger::GetDisabledAnsiSuffix() const {
520+
const uint32_t idx = ePropertyShowDisabledAnsiSuffix;
521+
return GetPropertyAtIndexAs<llvm::StringRef>(
522+
idx, g_debugger_properties[idx].default_cstr_value);
523+
}
524+
513525
bool Debugger::SetSeparator(llvm::StringRef s) {
514526
constexpr uint32_t idx = ePropertySeparator;
515527
bool ret = SetPropertyAtIndex(idx, s);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Test that disabling breakpoints and viewing them in a list uses the correct ANSI color settings when colors are enabled and disabled.
3+
"""
4+
5+
import lldb
6+
from lldbsuite.test.decorators import *
7+
from lldbsuite.test.lldbtest import *
8+
from lldbsuite.test import lldbutil
9+
from lldbsuite.test.lldbpexpect import PExpectTest
10+
11+
import io
12+
13+
14+
class DisabledBreakpointsTest(PExpectTest):
15+
@add_test_categories(["pexpect"])
16+
def test_disabling_breakpoints_with_color(self):
17+
"""Test that disabling a breakpoint and viewing the breakpoints list uses the specified ANSI color prefix."""
18+
ansi_red_color_code = "\x1b[31m"
19+
20+
self.launch(use_colors=True, dimensions=(100, 100))
21+
self.expect('settings set disable-ansi-prefix "${ansi.fg.red}"')
22+
self.expect("b main")
23+
self.expect("br dis")
24+
self.expect("br l", substrs=[ansi_red_color_code + "1:"])
25+
self.quit()

0 commit comments

Comments
 (0)