https://github.com/Nerixyz created 
https://github.com/llvm/llvm-project/pull/201118

>From 
>https://github.com/llvm/llvm-project/pull/196395#pullrequestreview-4409209050.

This uses `LazyImport` for `WaitForDebugEventEx` to simplify the import.

>From 73e72f02a64c05be9f036d1c832b2740b4992cff Mon Sep 17 00:00:00 2001
From: Nerixyz <[email protected]>
Date: Tue, 2 Jun 2026 15:18:40 +0200
Subject: [PATCH] [lldb][Windows] Use LazyImport for WaitForDebugEventEx

---
 .../Process/Windows/Common/DebuggerThread.cpp | 22 +++++--------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp 
b/lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
index 8eff602f65c4c..2b787abe27fb1 100644
--- a/lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
@@ -16,6 +16,7 @@
 #include "lldb/Host/windows/AutoHandle.h"
 #include "lldb/Host/windows/HostProcessWindows.h"
 #include "lldb/Host/windows/HostThreadWindows.h"
+#include "lldb/Host/windows/LazyImport.h"
 #include "lldb/Host/windows/ProcessLauncherWindows.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Utility/FileSpec.h"
@@ -45,30 +46,19 @@ using namespace lldb_private;
 typedef BOOL WINAPI WaitForDebugEventFn(LPDEBUG_EVENT, DWORD);
 static WaitForDebugEventFn *g_wait_for_debug_event = nullptr;
 
-static WaitForDebugEventFn *GetWaitForDebugEventEx() {
-  HMODULE h_kernel32 = LoadLibraryW(L"kernel32.dll");
-  if (!h_kernel32) {
-    llvm::Error err = llvm::errorCodeToError(
-        std::error_code(GetLastError(), std::system_category()));
-    LLDB_LOG_ERROR(GetLog(LLDBLog::Host), std::move(err),
-                   "Could not load kernel32: {0}");
-    return nullptr;
-  }
-
-  return reinterpret_cast<WaitForDebugEventFn *>(
-      GetProcAddress(h_kernel32, "WaitForDebugEventEx"));
-}
-
 /// WaitForDebugEventEx is only available on Windows 10+. This lazily checks if
 /// the function is available and falls back to WaitForDebugEvent if
 /// unavailable. The -Ex version ensures correct forwarding of
 /// OutputDebugStringW events.
 static void InitializeWaitForDebugEvent() {
+  static LazyImport<WaitForDebugEventFn *> WaitForDebugEventEx = {
+      L"kernel32.dll", "WaitForDebugEventEx"};
+
   if (g_wait_for_debug_event)
     return;
 
-  g_wait_for_debug_event = GetWaitForDebugEventEx();
-  if (!g_wait_for_debug_event) {
+  g_wait_for_debug_event = WaitForDebugEventEx.get();
+  if (!WaitForDebugEventEx) {
     LLDB_LOG(
         GetLog(LLDBLog::Host),
         "WaitForDebugEventEx unavailable, using WaitForDebugEvent instead. "

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to