[Lldb-commits] [PATCH] D151764: [lldb] Support file and function names in LLDB_LOGF macro
Jonas Devlieghere via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue May 30 16:45:35 PDT 2023
JDevlieghere created this revision.
JDevlieghere added a reviewer: LLDB.
Herald added a project: All.
JDevlieghere requested review of this revision.
LLDB's logging machinery supports prepending log messages with the name of the file and function that generates the log. However, currently this functionality is limited to the `LLDB_LOG` macro. I meant to do this as a follow up to D65128 <https://reviews.llvm.org/D65128> but never got around to it.
https://reviews.llvm.org/D151764
Files:
lldb/include/lldb/Utility/Log.h
lldb/source/Utility/Log.cpp
Index: lldb/source/Utility/Log.cpp
===================================================================
--- lldb/source/Utility/Log.cpp
+++ lldb/source/Utility/Log.cpp
@@ -155,6 +155,21 @@
PutString(Content);
}
+void Log::Formatf(llvm::StringRef file, llvm::StringRef function,
+ const char *format, ...) {
+ va_list args;
+ va_start(args, format);
+ VAFormatf(file, function, format, args);
+ va_end(args);
+}
+
+void Log::VAFormatf(llvm::StringRef file, llvm::StringRef function,
+ const char *format, va_list args) {
+ llvm::SmallString<64> Content;
+ lldb_private::VASprintf(Content, format, args);
+ Format(file, function, llvm::formatv("{0}", Content));
+}
+
// Printing of errors that are not fatal.
void Log::Error(const char *format, ...) {
va_list args;
Index: lldb/include/lldb/Utility/Log.h
===================================================================
--- lldb/include/lldb/Utility/Log.h
+++ lldb/include/lldb/Utility/Log.h
@@ -232,6 +232,9 @@
std::forward<Args>(args)...));
}
+ void Formatf(llvm::StringRef file, llvm::StringRef function,
+ const char *format, ...) __attribute__((format(printf, 4, 5)));
+
/// Prefer using LLDB_LOGF whenever possible.
void Printf(const char *format, ...) __attribute__((format(printf, 2, 3)));
@@ -249,6 +252,8 @@
void VAPrintf(const char *format, va_list args);
void VAError(const char *format, va_list args);
+ void VAFormatf(llvm::StringRef file, llvm::StringRef function,
+ const char *format, va_list args);
private:
Channel &m_channel;
@@ -345,7 +350,7 @@
do { \
::lldb_private::Log *log_private = (log); \
if (log_private) \
- log_private->Printf(__VA_ARGS__); \
+ log_private->Formatf(__FILE__, __func__, __VA_ARGS__); \
} while (0)
#define LLDB_LOGV(log, ...) \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151764.526845.patch
Type: text/x-patch
Size: 2164 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230530/463cda8d/attachment.bin>
More information about the lldb-commits
mailing list