https://github.com/Qwinci updated https://github.com/llvm/llvm-project/pull/214023
>From 7960987709b0ccac2f03ac0db2c35acc54ac117e 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 | 33 +++++++++++++++---- 1 file changed, 27 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..075c21002b4d3 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,33 @@ 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 if the process is live. + // 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. + + if (!m_process->IsLiveDebugSession()) + return; - // Request the process base address. - lldb::addr_t image_base = m_process->GetImageInfoAddress(); - if (image_base == load_addr) - return; + ObjectFile *object_file = executable->GetObjectFile(); + if (!object_file) + return; + + load_addr = object_file->GetBaseAddress().GetFileAddress(); + if (load_addr == LLDB_INVALID_ADDRESS) + return; + + executable->ReportWarning( + "failed to get load address, assuming image base at {0:x}", load_addr); + } 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
