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 #endif +#if defined(__APPLE__) +#include +static os_log_t g_os_log; +static std::once_flag g_os_log_once; +#endif + using namespace lldb_private; llvm::ManagedStatic 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 +}