Skip to content

Commit 79178ca

Browse files
authored
[lldb] Highlight "note:" in CommandReturnObject (#114610)
We have helpers to emit warnings and errors. Do the same thing for notes to they stand out more.
1 parent 94f9cbb commit 79178ca

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

lldb/include/lldb/Interpreter/CommandReturnObject.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ class CommandReturnObject {
110110
void AppendMessageWithFormat(const char *format, ...)
111111
__attribute__((format(printf, 2, 3)));
112112

113+
void AppendNote(llvm::StringRef in_string);
114+
115+
void AppendNoteWithFormat(const char *format, ...)
116+
__attribute__((format(printf, 2, 3)));
117+
113118
void AppendWarning(llvm::StringRef in_string);
114119

115120
void AppendWarningWithFormat(const char *format, ...)
@@ -127,6 +132,11 @@ class CommandReturnObject {
127132
AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
128133
}
129134

135+
template <typename... Args>
136+
void AppendNoteWithFormatv(const char *format, Args &&...args) {
137+
AppendNote(llvm::formatv(format, std::forward<Args>(args)...).str());
138+
}
139+
130140
template <typename... Args>
131141
void AppendWarningWithFormatv(const char *format, Args &&... args) {
132142
AppendWarning(llvm::formatv(format, std::forward<Args>(args)...).str());

lldb/source/Commands/CommandObjectDWIMPrint.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
121121
if (note_shown)
122122
return;
123123

124-
result.GetOutputStream()
125-
<< "note: object description requested, but type doesn't implement "
126-
"a custom object description. Consider using \"p\" instead of "
127-
"\"po\" (this note will only be shown once per debug session).\n";
124+
result.AppendNote(
125+
"object description requested, but type doesn't implement "
126+
"a custom object description. Consider using \"p\" instead of "
127+
"\"po\" (this note will only be shown once per debug session).\n");
128128
note_shown = true;
129129
}
130130
};
@@ -164,8 +164,8 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
164164
StringRef flags;
165165
if (args.HasArgs())
166166
flags = args.GetArgString();
167-
result.AppendMessageWithFormatv("note: ran `frame variable {0}{1}`",
168-
flags, expr);
167+
result.AppendNoteWithFormatv("ran `frame variable {0}{1}`", flags,
168+
expr);
169169
}
170170

171171
dump_val_object(*valobj_sp);
@@ -224,8 +224,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
224224
StringRef flags;
225225
if (args.HasArgs())
226226
flags = args.GetArgStringWithDelimiter();
227-
result.AppendMessageWithFormatv("note: ran `expression {0}{1}`", flags,
228-
expr);
227+
result.AppendNoteWithFormatv("ran `expression {0}{1}`", flags, expr);
229228
}
230229

231230
if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)

lldb/source/Interpreter/CommandReturnObject.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ static llvm::raw_ostream &warning(Stream &strm) {
2727
<< "warning: ";
2828
}
2929

30+
static llvm::raw_ostream &note(Stream &strm) {
31+
return llvm::WithColor(strm.AsRawOstream(), llvm::HighlightColor::Note,
32+
llvm::ColorMode::Enable)
33+
<< "note: ";
34+
}
35+
3036
static void DumpStringToStreamWithNewline(Stream &strm, const std::string &s) {
3137
bool add_newline = false;
3238
if (!s.empty()) {
@@ -74,6 +80,18 @@ void CommandReturnObject::AppendMessageWithFormat(const char *format, ...) {
7480
GetOutputStream() << sstrm.GetString();
7581
}
7682

83+
void CommandReturnObject::AppendNoteWithFormat(const char *format, ...) {
84+
if (!format)
85+
return;
86+
va_list args;
87+
va_start(args, format);
88+
StreamString sstrm;
89+
sstrm.PrintfVarArg(format, args);
90+
va_end(args);
91+
92+
note(GetOutputStream()) << sstrm.GetString();
93+
}
94+
7795
void CommandReturnObject::AppendWarningWithFormat(const char *format, ...) {
7896
if (!format)
7997
return;
@@ -92,6 +110,12 @@ void CommandReturnObject::AppendMessage(llvm::StringRef in_string) {
92110
GetOutputStream() << in_string.rtrim() << '\n';
93111
}
94112

113+
void CommandReturnObject::AppendNote(llvm::StringRef in_string) {
114+
if (in_string.empty())
115+
return;
116+
note(GetOutputStream()) << in_string.rtrim() << '\n';
117+
}
118+
95119
void CommandReturnObject::AppendWarning(llvm::StringRef in_string) {
96120
if (in_string.empty())
97121
return;

0 commit comments

Comments
 (0)