[Lldb-commits] [PATCH] D128321: [lldb] Add OSLog log handler
Jonas Devlieghere via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Wed Jun 22 14:44:11 PDT 2022
JDevlieghere updated this revision to Diff 439164.
JDevlieghere marked 5 inline comments as done.
JDevlieghere added a comment.
Address remaining code review feedback
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128321/new/
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;
@@ -384,3 +390,24 @@
}
stream.flush();
}
+
+SystemLogHandler::SystemLogHandler() {
+#if defined(__APPLE__)
+ std::call_once(g_os_log_once, []() {
+ g_os_log = os_log_create("com.apple.dt.lldb", "lldb");
+ });
+#endif
+}
+
+void SystemLogHandler::Emit(llvm::StringRef message) {
+ std::string str(message);
+#if defined(__APPLE__)
+ if (__builtin_available(macos 10.12, iOS 10, tvOS 10, watchOS 3, *)) {
+ os_log(g_os_log, "%{public}s", str.c_str());
+ } else {
+ fprintf(stderr, "%s", str.c_str());
+ }
+#else
+ fprintf(stderr, "%s", str.c_str());
+#endif
+}
Index: lldb/include/lldb/Utility/Log.h
===================================================================
--- lldb/include/lldb/Utility/Log.h
+++ lldb/include/lldb/Utility/Log.h
@@ -95,6 +95,12 @@
size_t m_total_count = 0;
};
+class SystemLogHandler : public LogHandler {
+public:
+ SystemLogHandler();
+ void Emit(llvm::StringRef message) override;
+};
+
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.439164.patch
Type: text/x-patch
Size: 1473 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220622/7fe44f37/attachment.bin>
More information about the lldb-commits
mailing list