diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index fd5cc1d17da25..04380c6255f13 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -88,12 +88,27 @@ int __pthread_fchdir(int fildes); using namespace lldb; using namespace lldb_private; -#if !defined(__APPLE__) -// The system log is currently only meaningful on Darwin, where this means -// os_log. The meaning of a "system log" isn't as clear on other platforms, and -// therefore we don't providate a default implementation. Vendors are free to -// to implement this function if they have a use for it. -void Host::SystemLog(Severity severity, llvm::StringRef message) {} +#if !defined(__APPLE__) && !defined(_WIN32) +#include +void Host::SystemLog(Severity severity, llvm::StringRef message) { + static llvm::once_flag g_openlog_once; + llvm::call_once(g_openlog_once, [] { + openlog("lldb", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER); + }); + int level = LOG_DEBUG; + switch (severity) { + case lldb::eSeverityInfo: + level = LOG_INFO; + break; + case lldb::eSeverityWarning: + level = LOG_WARNING; + break; + case lldb::eSeverityError: + level = LOG_ERR; + break; + } + syslog(level, "%s", message.data()); +} #endif #if !defined(__APPLE__) && !defined(_WIN32) diff --git a/lldb/source/Host/windows/Host.cpp b/lldb/source/Host/windows/Host.cpp index a7369e7eade3b..e8973a3fb937a 100644 --- a/lldb/source/Host/windows/Host.cpp +++ b/lldb/source/Host/windows/Host.cpp @@ -22,6 +22,7 @@ #include "lldb/Utility/StreamString.h" #include "lldb/Utility/StructuredData.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/ConvertUTF.h" // Windows includes @@ -30,6 +31,8 @@ using namespace lldb; using namespace lldb_private; +using llvm::sys::windows::UTF8ToUTF16; + static bool GetTripleForProcess(const FileSpec &executable, llvm::Triple &triple) { // Open the PE File as a binary file, and parse just enough information to @@ -302,3 +305,29 @@ Environment Host::GetEnvironment() { } return env; } + +void Host::SystemLog(Severity severity, llvm::StringRef message) { + if (message.empty()) + return; + + std::string log_msg; + llvm::raw_string_ostream stream(log_msg); + + switch (severity) { + case lldb::eSeverityWarning: + stream << "[Warning] "; + break; + case lldb::eSeverityError: + stream << "[Error] "; + break; + case lldb::eSeverityInfo: + default: + stream << "[Info] "; + break; + } + + stream << message; + stream.flush(); + + OutputDebugStringA(log_msg.c_str()); +}