https://github.com/charles-zablit updated 
https://github.com/llvm/llvm-project/pull/154424

>From 5c7c53e53d179e7e002cbe958c12aef453afa6da Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zab...@apple.com>
Date: Tue, 19 Aug 2025 22:22:38 +0100
Subject: [PATCH 1/3] [lldb][windows] remove duplicate implementation of
 UTF8ToUTF16

---
 lldb/source/Host/windows/Host.cpp | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/lldb/source/Host/windows/Host.cpp 
b/lldb/source/Host/windows/Host.cpp
index 4e747f77afc0e..8b76b21f33b29 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/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ManagedStatic.h"
@@ -32,6 +33,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
@@ -325,30 +328,17 @@ class WindowsEventLog {
 
 static llvm::ManagedStatic<WindowsEventLog> event_log;
 
-static std::wstring AnsiToUtf16(const std::string &ansi) {
-  if (ansi.empty())
-    return {};
-
-  const int unicode_length =
-      MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), -1, nullptr, 0);
-  if (unicode_length == 0)
-    return {};
-
-  std::wstring unicode(unicode_length, L'\0');
-  MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), -1, &unicode[0], 
unicode_length);
-  return unicode;
-}
-
 void Host::SystemLog(Severity severity, llvm::StringRef message) {
   HANDLE h = event_log->GetHandle();
   if (!h)
     return;
 
-  std::wstring wide_message = AnsiToUtf16(message.str());
-  if (wide_message.empty())
+  llvm::SmallVector<wchar_t, 1> argsUTF16;
+  if (UTF8ToUTF16(message.str(), argsUTF16))
     return;
 
-  LPCWSTR msg_ptr = wide_message.c_str();
+  if (argsUTF16.empty())
+    return;
 
   WORD event_type;
   switch (severity) {
@@ -363,5 +353,6 @@ void Host::SystemLog(Severity severity, llvm::StringRef 
message) {
     event_type = EVENTLOG_INFORMATION_TYPE;
   }
 
-  ReportEventW(h, event_type, 0, 0, nullptr, 1, 0, &msg_ptr, nullptr);
+  LPCWSTR messages[] = {argsUTF16.data()};
+  ReportEventW(h, event_type, 0, 0, nullptr, 1, 0, messages, nullptr);
 }

>From 2160e5b0033fa1f01509cc3ac8e5e9cf6f04d0ea Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zab...@apple.com>
Date: Wed, 20 Aug 2025 11:15:00 +0100
Subject: [PATCH 2/3] remove magic constant

---
 lldb/source/Host/windows/Host.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lldb/source/Host/windows/Host.cpp 
b/lldb/source/Host/windows/Host.cpp
index 8b76b21f33b29..15c49091c63ff 100644
--- a/lldb/source/Host/windows/Host.cpp
+++ b/lldb/source/Host/windows/Host.cpp
@@ -329,6 +329,9 @@ class WindowsEventLog {
 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;
@@ -337,9 +340,6 @@ void Host::SystemLog(Severity severity, llvm::StringRef 
message) {
   if (UTF8ToUTF16(message.str(), argsUTF16))
     return;
 
-  if (argsUTF16.empty())
-    return;
-
   WORD event_type;
   switch (severity) {
   case lldb::eSeverityWarning:
@@ -353,6 +353,7 @@ void Host::SystemLog(Severity severity, llvm::StringRef 
message) {
     event_type = EVENTLOG_INFORMATION_TYPE;
   }
 
-  LPCWSTR messages[] = {argsUTF16.data()};
-  ReportEventW(h, event_type, 0, 0, nullptr, 1, 0, messages, nullptr);
+  LPCWSTR messages[1] = {argsUTF16.data()};
+  ReportEventW(h, event_type, 0, 0, nullptr, sizeof(messages), 0, messages,
+               nullptr);
 }

>From e639ecadcb305b9471d536d279a51caa95c442ec Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zab...@apple.com>
Date: Wed, 20 Aug 2025 11:22:10 +0100
Subject: [PATCH 3/3] fixup! remove magic constant

---
 lldb/source/Host/windows/Host.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Host/windows/Host.cpp 
b/lldb/source/Host/windows/Host.cpp
index 15c49091c63ff..4277b8edb38e5 100644
--- a/lldb/source/Host/windows/Host.cpp
+++ b/lldb/source/Host/windows/Host.cpp
@@ -354,6 +354,6 @@ void Host::SystemLog(Severity severity, llvm::StringRef 
message) {
   }
 
   LPCWSTR messages[1] = {argsUTF16.data()};
-  ReportEventW(h, event_type, 0, 0, nullptr, sizeof(messages), 0, messages,
+  ReportEventW(h, event_type, 0, 0, nullptr, std::size(messages), 0, messages,
                nullptr);
 }

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to