[Lldb-commits] [lldb] 79178ca - [lldb] Highlight "note:" in CommandReturnObject (#114610)
via lldb-commits
lldb-commits at lists.llvm.org
Sat Nov 2 08:52:35 PDT 2024
Author: Jonas Devlieghere
Date: 2024-11-02T08:52:32-07:00
New Revision: 79178ca689a8259d19d93320a6299e3d31383ac4
URL: https://github.com/llvm/llvm-project/commit/79178ca689a8259d19d93320a6299e3d31383ac4
DIFF: https://github.com/llvm/llvm-project/commit/79178ca689a8259d19d93320a6299e3d31383ac4.diff
LOG: [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.
Added:
Modified:
lldb/include/lldb/Interpreter/CommandReturnObject.h
lldb/source/Commands/CommandObjectDWIMPrint.cpp
lldb/source/Interpreter/CommandReturnObject.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Interpreter/CommandReturnObject.h b/lldb/include/lldb/Interpreter/CommandReturnObject.h
index a491a6c1535b11..9fef59337016df 100644
--- a/lldb/include/lldb/Interpreter/CommandReturnObject.h
+++ b/lldb/include/lldb/Interpreter/CommandReturnObject.h
@@ -110,6 +110,11 @@ class CommandReturnObject {
void AppendMessageWithFormat(const char *format, ...)
__attribute__((format(printf, 2, 3)));
+ void AppendNote(llvm::StringRef in_string);
+
+ void AppendNoteWithFormat(const char *format, ...)
+ __attribute__((format(printf, 2, 3)));
+
void AppendWarning(llvm::StringRef in_string);
void AppendWarningWithFormat(const char *format, ...)
@@ -127,6 +132,11 @@ class CommandReturnObject {
AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
}
+ template <typename... Args>
+ void AppendNoteWithFormatv(const char *format, Args &&...args) {
+ AppendNote(llvm::formatv(format, std::forward<Args>(args)...).str());
+ }
+
template <typename... Args>
void AppendWarningWithFormatv(const char *format, Args &&... args) {
AppendWarning(llvm::formatv(format, std::forward<Args>(args)...).str());
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index 76bed100dc7291..62c4e74d853ad1 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -121,10 +121,10 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
if (note_shown)
return;
- result.GetOutputStream()
- << "note: object description requested, but type doesn't implement "
- "a custom object description. Consider using \"p\" instead of "
- "\"po\" (this note will only be shown once per debug session).\n";
+ result.AppendNote(
+ "object description requested, but type doesn't implement "
+ "a custom object description. Consider using \"p\" instead of "
+ "\"po\" (this note will only be shown once per debug session).\n");
note_shown = true;
}
};
@@ -164,8 +164,8 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
StringRef flags;
if (args.HasArgs())
flags = args.GetArgString();
- result.AppendMessageWithFormatv("note: ran `frame variable {0}{1}`",
- flags, expr);
+ result.AppendNoteWithFormatv("ran `frame variable {0}{1}`", flags,
+ expr);
}
dump_val_object(*valobj_sp);
@@ -224,8 +224,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
StringRef flags;
if (args.HasArgs())
flags = args.GetArgStringWithDelimiter();
- result.AppendMessageWithFormatv("note: ran `expression {0}{1}`", flags,
- expr);
+ result.AppendNoteWithFormatv("ran `expression {0}{1}`", flags, expr);
}
if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
diff --git a/lldb/source/Interpreter/CommandReturnObject.cpp b/lldb/source/Interpreter/CommandReturnObject.cpp
index 94f5ff608b2aea..2776efbb5ee36d 100644
--- a/lldb/source/Interpreter/CommandReturnObject.cpp
+++ b/lldb/source/Interpreter/CommandReturnObject.cpp
@@ -27,6 +27,12 @@ static llvm::raw_ostream &warning(Stream &strm) {
<< "warning: ";
}
+static llvm::raw_ostream ¬e(Stream &strm) {
+ return llvm::WithColor(strm.AsRawOstream(), llvm::HighlightColor::Note,
+ llvm::ColorMode::Enable)
+ << "note: ";
+}
+
static void DumpStringToStreamWithNewline(Stream &strm, const std::string &s) {
bool add_newline = false;
if (!s.empty()) {
@@ -74,6 +80,18 @@ void CommandReturnObject::AppendMessageWithFormat(const char *format, ...) {
GetOutputStream() << sstrm.GetString();
}
+void CommandReturnObject::AppendNoteWithFormat(const char *format, ...) {
+ if (!format)
+ return;
+ va_list args;
+ va_start(args, format);
+ StreamString sstrm;
+ sstrm.PrintfVarArg(format, args);
+ va_end(args);
+
+ note(GetOutputStream()) << sstrm.GetString();
+}
+
void CommandReturnObject::AppendWarningWithFormat(const char *format, ...) {
if (!format)
return;
@@ -92,6 +110,12 @@ void CommandReturnObject::AppendMessage(llvm::StringRef in_string) {
GetOutputStream() << in_string.rtrim() << '\n';
}
+void CommandReturnObject::AppendNote(llvm::StringRef in_string) {
+ if (in_string.empty())
+ return;
+ note(GetOutputStream()) << in_string.rtrim() << '\n';
+}
+
void CommandReturnObject::AppendWarning(llvm::StringRef in_string) {
if (in_string.empty())
return;
More information about the lldb-commits
mailing list