Skip to content

Commit 00626f5

Browse files
JDevliegherekastiglione
authored andcommitted
[lldb] Highlight "note:" in CommandReturnObject (llvm#114610)
We have helpers to emit warnings and errors. Do the same thing for notes to they stand out more. (cherry picked from commit 79178ca)
1 parent adfb8ba commit 00626f5

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
@@ -117,6 +117,11 @@ class CommandReturnObject {
117117
void AppendMessageWithFormat(const char *format, ...)
118118
__attribute__((format(printf, 2, 3)));
119119

120+
void AppendNote(llvm::StringRef in_string);
121+
122+
void AppendNoteWithFormat(const char *format, ...)
123+
__attribute__((format(printf, 2, 3)));
124+
120125
void AppendWarning(llvm::StringRef in_string);
121126

122127
void AppendWarningWithFormat(const char *format, ...)
@@ -134,6 +139,11 @@ class CommandReturnObject {
134139
AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
135140
}
136141

142+
template <typename... Args>
143+
void AppendNoteWithFormatv(const char *format, Args &&...args) {
144+
AppendNote(llvm::formatv(format, std::forward<Args>(args)...).str());
145+
}
146+
137147
template <typename... Args>
138148
void AppendWarningWithFormatv(const char *format, Args &&... args) {
139149
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
@@ -123,10 +123,10 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
123123
if (note_shown)
124124
return;
125125

126-
result.GetOutputStream()
127-
<< "note: object description requested, but type doesn't implement "
128-
"a custom object description. Consider using \"p\" instead of "
129-
"\"po\" (this note will only be shown once per debug session).\n";
126+
result.AppendNote(
127+
"object description requested, but type doesn't implement "
128+
"a custom object description. Consider using \"p\" instead of "
129+
"\"po\" (this note will only be shown once per debug session).\n");
130130
note_shown = true;
131131
}
132132
};
@@ -180,8 +180,8 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
180180
StringRef flags;
181181
if (args.HasArgs())
182182
flags = args.GetArgString();
183-
result.AppendMessageWithFormatv("note: ran `frame variable {0}{1}`",
184-
flags, expr);
183+
result.AppendNoteWithFormatv("ran `frame variable {0}{1}`", flags,
184+
expr);
185185
}
186186

187187
dump_val_object(*valobj_sp);
@@ -280,8 +280,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
280280
StringRef flags;
281281
if (args.HasArgs())
282282
flags = args.GetArgStringWithDelimiter();
283-
result.AppendMessageWithFormatv("note: ran `expression {0}{1}`", flags,
284-
expr);
283+
result.AppendNoteWithFormatv("ran `expression {0}{1}`", flags, expr);
285284
}
286285

287286
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)