[Lldb-commits] [lldb] [lldb][Windows] Use LazyImport for WaitForDebugEventEx (PR #201118)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 2 06:22:17 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Nerixyz (Nerixyz)
<details>
<summary>Changes</summary>
>From https://github.com/llvm/llvm-project/pull/196395#pullrequestreview-4409209050.
This uses `LazyImport` for `WaitForDebugEventEx` to simplify the import.
---
Full diff: https://github.com/llvm/llvm-project/pull/201118.diff
1 Files Affected:
- (modified) lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp (+6-16)
``````````diff
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. "
``````````
</details>
https://github.com/llvm/llvm-project/pull/201118
More information about the lldb-commits
mailing list