[Lldb-commits] [lldb] [lldb][windows] use OutputDebugStringA instead of c to log events (PR #156474)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 2 09:57:30 PDT 2025
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/156474
>From ec308302c936c8ce4993ae27f8d5e813e4ac59c9 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Tue, 2 Sep 2025 16:13:17 +0100
Subject: [PATCH 1/2] [lldb][windows] use OutputDebugStringA instead of
ReportEventW to log events
---
lldb/source/Host/windows/Host.cpp | 44 +++++--------------------------
1 file changed, 7 insertions(+), 37 deletions(-)
diff --git a/lldb/source/Host/windows/Host.cpp b/lldb/source/Host/windows/Host.cpp
index 4277b8edb38e5..8be4596c420a4 100644
--- a/lldb/source/Host/windows/Host.cpp
+++ b/lldb/source/Host/windows/Host.cpp
@@ -22,10 +22,8 @@
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/StructuredData.h"
-#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ConvertUTF.h"
-#include "llvm/Support/ManagedStatic.h"
// Windows includes
#include <tlhelp32.h>
@@ -308,52 +306,24 @@ Environment Host::GetEnvironment() {
return env;
}
-/// Manages the lifecycle of a Windows Event's Source.
-/// The destructor will call DeregisterEventSource.
-/// This class is meant to be used with \ref llvm::ManagedStatic.
-class WindowsEventLog {
-public:
- WindowsEventLog() : handle(RegisterEventSource(nullptr, L"lldb")) {}
-
- ~WindowsEventLog() {
- if (handle)
- DeregisterEventSource(handle);
- }
-
- HANDLE GetHandle() const { return handle; }
-
-private:
- HANDLE handle;
-};
-
-static llvm::ManagedStatic<WindowsEventLog> event_log;
-
void Host::SystemLog(Severity severity, llvm::StringRef message) {
if (message.empty())
return;
- HANDLE h = event_log->GetHandle();
- if (!h)
- return;
-
- llvm::SmallVector<wchar_t, 1> argsUTF16;
- if (UTF8ToUTF16(message.str(), argsUTF16))
- return;
-
- WORD event_type;
+ std::string log_prefix;
switch (severity) {
case lldb::eSeverityWarning:
- event_type = EVENTLOG_WARNING_TYPE;
+ log_prefix = "[Warning] ";
break;
case lldb::eSeverityError:
- event_type = EVENTLOG_ERROR_TYPE;
+ log_prefix = "[Error] ";
break;
case lldb::eSeverityInfo:
default:
- event_type = EVENTLOG_INFORMATION_TYPE;
+ log_prefix = "[Info] ";
+ break;
}
- LPCWSTR messages[1] = {argsUTF16.data()};
- ReportEventW(h, event_type, 0, 0, nullptr, std::size(messages), 0, messages,
- nullptr);
+ std::string final_message = log_prefix + message.str();
+ OutputDebugStringA(final_message.c_str());
}
>From be11dc3b8c516c6305b074ecf6f0cb1a76935bae Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Tue, 2 Sep 2025 17:57:17 +0100
Subject: [PATCH 2/2] fixup! [lldb][windows] use OutputDebugStringA instead of
ReportEventW to log events
---
lldb/source/Host/windows/Host.cpp | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/lldb/source/Host/windows/Host.cpp b/lldb/source/Host/windows/Host.cpp
index 8be4596c420a4..e8973a3fb937a 100644
--- a/lldb/source/Host/windows/Host.cpp
+++ b/lldb/source/Host/windows/Host.cpp
@@ -310,20 +310,24 @@ void Host::SystemLog(Severity severity, llvm::StringRef message) {
if (message.empty())
return;
- std::string log_prefix;
+ std::string log_msg;
+ llvm::raw_string_ostream stream(log_msg);
+
switch (severity) {
case lldb::eSeverityWarning:
- log_prefix = "[Warning] ";
+ stream << "[Warning] ";
break;
case lldb::eSeverityError:
- log_prefix = "[Error] ";
+ stream << "[Error] ";
break;
case lldb::eSeverityInfo:
default:
- log_prefix = "[Info] ";
+ stream << "[Info] ";
break;
}
- std::string final_message = log_prefix + message.str();
- OutputDebugStringA(final_message.c_str());
+ stream << message;
+ stream.flush();
+
+ OutputDebugStringA(log_msg.c_str());
}
More information about the lldb-commits
mailing list