[Lldb-commits] [PATCH] D128321: [lldb] Add OSLog log handler
Jonas Devlieghere via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 21 22:51:19 PDT 2022
JDevlieghere created this revision.
JDevlieghere added reviewers: aprantl, labath, clayborg.
Herald added a project: All.
JDevlieghere requested review of this revision.
Add an OSLog log handler on macOS. These log messages end up in Console.app and will be part of a sysdiagnose.
https://reviews.llvm.org/D128321
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
@@ -32,6 +32,12 @@
#include <unistd.h>
#endif
+#if defined(__APPLE__)
+#include <os/log.h>
+static os_log_t g_os_log;
+static std::once_flag g_os_log_once;
+#endif
+
using namespace lldb_private;
llvm::ManagedStatic<Log::ChannelMap> Log::g_channel_map;
@@ -389,3 +395,15 @@
}
stream.flush();
}
+
+#if defined(__APPLE__)
+OSLogLogHandler::OSLogLogHandler() {
+ std::call_once(g_os_log_once, []() {
+ g_os_log = os_log_create("com.apple.dt.lldb", "lldb");
+ });
+}
+
+void OSLogLogHandler::Emit(llvm::StringRef message) {
+ os_log_with_type(g_os_log, OS_LOG_TYPE_DEFAULT, "%{public}s", message.data());
+}
+#endif
Index: lldb/include/lldb/Utility/Log.h
===================================================================
--- lldb/include/lldb/Utility/Log.h
+++ lldb/include/lldb/Utility/Log.h
@@ -96,6 +96,14 @@
size_t m_total_count = 0;
};
+#if defined(__APPLE__)
+class OSLogLogHandler : public LogHandler {
+public:
+ OSLogLogHandler();
+ void Emit(llvm::StringRef message) override;
+};
+#endif
+
class Log final {
public:
/// The underlying type of all log channel enums. Declare them as:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128321.438918.patch
Type: text/x-patch
Size: 1293 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220622/1e276856/attachment.bin>
More information about the lldb-commits
mailing list