Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions lldb/source/Host/common/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <syslog.h>
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)
Expand Down
29 changes: 29 additions & 0 deletions lldb/source/Host/windows/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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());
}