[Lldb-commits] [lldb] [lldb][Windows] Use LazyImport for WaitForDebugEventEx (PR #201118)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 2 06:42:38 PDT 2026
https://github.com/Nerixyz updated https://github.com/llvm/llvm-project/pull/201118
>From 73e72f02a64c05be9f036d1c832b2740b4992cff Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Tue, 2 Jun 2026 15:18:40 +0200
Subject: [PATCH 1/2] [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. "
>From 6ff209f5c2fb6391b2658351190b2917a0c5e8ef Mon Sep 17 00:00:00 2001
From: Nerixyz <nero.9 at hotmail.de>
Date: Tue, 2 Jun 2026 15:42:28 +0200
Subject: [PATCH 2/2] Update
lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
Co-authored-by: Charles Zablit <c_zablit at apple.com>
---
.../Process/Windows/Common/DebuggerThread.cpp | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp b/lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
index 2b787abe27fb1..c69e207bde29d 100644
--- a/lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
@@ -65,6 +65,21 @@ static void InitializeWaitForDebugEvent() {
"Unicode strings from OutputDebugStringW might show incorrectly.");
g_wait_for_debug_event = &WaitForDebugEvent;
}
+ static LazyImport<WaitForDebugEventFn *> s_wait_for_debug_event_ex = {
+ L"kernel32.dll", "WaitForDebugEventEx"};
+
+ if (g_wait_for_debug_event)
+ return;
+
+ if (!s_wait_for_debug_event_ex) {
+ LLDB_LOG(
+ GetLog(LLDBLog::Host),
+ "WaitForDebugEventEx unavailable, using WaitForDebugEvent instead. "
+ "Unicode strings from OutputDebugStringW might show incorrectly.");
+ g_wait_for_debug_event = &WaitForDebugEvent;
+ } else {
+ g_wait_for_debug_event = *s_wait_for_debug_event_ex;
+ }
}
DebuggerThread::DebuggerThread(DebugDelegateSP debug_delegate)
More information about the lldb-commits
mailing list