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