[Lldb-commits] [lldb] [lldb] Improve PE remote debugging by falling back to the load address (PR #214023)

via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 14 05:19:14 PDT 2026


https://github.com/Qwinci updated https://github.com/llvm/llvm-project/pull/214023

>From 704c95805fad7c4a53b6a47952dec6e7709d0394 Mon Sep 17 00:00:00 2001
From: Qwinci <qwinci222 at gmail.com>
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 | 34 +++++++++++++++----
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
index 38914ff208934c..617337a6ca5faa 100644
--- a/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
@@ -12,6 +12,7 @@
 #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.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"
@@ -155,14 +156,35 @@ void DynamicLoaderWindowsDYLD::DidAttach() {
     // one. Take the modules it reports as loaded, which replaces the target's
     // executable with the process's.
     auto error = m_process->LoadModules();
+    if (!error)
+      return;
     LLDB_LOG_ERROR(log, std::move(error), "failed to load modules: {0}");
-    return;
-  }
 
-  // Request the process base address.
-  lldb::addr_t image_base = m_process->GetImageInfoAddress();
-  if (image_base == load_addr)
-    return;
+    // 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;
+
+    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);



More information about the lldb-commits mailing list