Skip to content

Commit 0d02465

Browse files
author
git apple-llvm automerger
committed
Merge commit '28c2b58a5f3c' from swift/release/6.2 into stable/20240723
2 parents 75c6640 + 28c2b58 commit 0d02465

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

lldb/source/Host/common/Host.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,27 @@ int __pthread_fchdir(int fildes);
8888
using namespace lldb;
8989
using namespace lldb_private;
9090

91-
#if !defined(__APPLE__)
92-
// The system log is currently only meaningful on Darwin, where this means
93-
// os_log. The meaning of a "system log" isn't as clear on other platforms, and
94-
// therefore we don't providate a default implementation. Vendors are free to
95-
// to implement this function if they have a use for it.
96-
void Host::SystemLog(Severity severity, llvm::StringRef message) {}
91+
#if !defined(__APPLE__) && !defined(_WIN32)
92+
#include <syslog.h>
93+
void Host::SystemLog(Severity severity, llvm::StringRef message) {
94+
static llvm::once_flag g_openlog_once;
95+
llvm::call_once(g_openlog_once, [] {
96+
openlog("lldb", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
97+
});
98+
int level = LOG_DEBUG;
99+
switch (severity) {
100+
case lldb::eSeverityInfo:
101+
level = LOG_INFO;
102+
break;
103+
case lldb::eSeverityWarning:
104+
level = LOG_WARNING;
105+
break;
106+
case lldb::eSeverityError:
107+
level = LOG_ERR;
108+
break;
109+
}
110+
syslog(level, "%s", message.data());
111+
}
97112
#endif
98113

99114
#if !defined(__APPLE__) && !defined(_WIN32)

lldb/source/Host/windows/Host.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "lldb/Utility/StreamString.h"
2323
#include "lldb/Utility/StructuredData.h"
2424

25+
#include "llvm/ADT/StringRef.h"
2526
#include "llvm/Support/ConvertUTF.h"
2627

2728
// Windows includes
@@ -30,6 +31,8 @@
3031
using namespace lldb;
3132
using namespace lldb_private;
3233

34+
using llvm::sys::windows::UTF8ToUTF16;
35+
3336
static bool GetTripleForProcess(const FileSpec &executable,
3437
llvm::Triple &triple) {
3538
// Open the PE File as a binary file, and parse just enough information to
@@ -302,3 +305,29 @@ Environment Host::GetEnvironment() {
302305
}
303306
return env;
304307
}
308+
309+
void Host::SystemLog(Severity severity, llvm::StringRef message) {
310+
if (message.empty())
311+
return;
312+
313+
std::string log_msg;
314+
llvm::raw_string_ostream stream(log_msg);
315+
316+
switch (severity) {
317+
case lldb::eSeverityWarning:
318+
stream << "[Warning] ";
319+
break;
320+
case lldb::eSeverityError:
321+
stream << "[Error] ";
322+
break;
323+
case lldb::eSeverityInfo:
324+
default:
325+
stream << "[Info] ";
326+
break;
327+
}
328+
329+
stream << message;
330+
stream.flush();
331+
332+
OutputDebugStringA(log_msg.c_str());
333+
}

0 commit comments

Comments
 (0)