https://github.com/Qwinci updated https://github.com/llvm/llvm-project/pull/214023
>From ee1f92aba53d002160f509207870bd9c50e0f844 Mon Sep 17 00:00:00 2001 From: Qwinci <[email protected]> Date: Tue, 4 Aug 2026 20:34:22 +0300 Subject: [PATCH] [lldb][Windows] Fall back to load address from file in DynamicLoaderWindowsDYLD If GetLoadAddress fails then fall back to the preferred load address from the file, this allows e.g. debugging PE kernel binaries in QEMU over gdbstub without needing to specify a load address manually (if no KASLR is in effect). --- .../Windows-DYLD/DynamicLoaderWindowsDYLD.cpp | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp index 2d6e97b067c30..d7d5912533641 100644 --- a/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp @@ -11,6 +11,7 @@ #include "MSVCRTCFrameRecognizer.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" +#include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" @@ -148,13 +149,26 @@ void DynamicLoaderWindowsDYLD::DidAttach() { // Try to fetch the load address of the file from the process, since there // could be randomization of the load address. lldb::addr_t load_addr = GetLoadAddress(executable); - if (load_addr == LLDB_INVALID_ADDRESS) - return; + if (load_addr == LLDB_INVALID_ADDRESS) { + // If the load address couldn't be determined (e.g. for a remote gdbstub + // target), fall back to the preferred load address/image base from the + // file. This is a best-effort guess, if the image isn't loaded there the + // sections will have incorrect addresses and the slide will have to be + // specified manually. + + ObjectFile *object_file = executable->GetObjectFile(); + if (!object_file) + return; - // Request the process base address. - lldb::addr_t image_base = m_process->GetImageInfoAddress(); - if (image_base == load_addr) - return; + load_addr = object_file->GetBaseAddress().GetFileAddress(); + if (load_addr == LLDB_INVALID_ADDRESS) + return; + } else { + // Request the process base address. + lldb::addr_t image_base = m_process->GetImageInfoAddress(); + if (image_base == load_addr) + return; + } // Rebase the process's modules if there is a mismatch. UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_addr, false); _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
