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:
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:
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits