[Lldb-commits] [lldb] [lldb] Preserve TargetSP in Platform module lookup (PR #186323)

Emre Kultursay via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 13 10:14:56 PDT 2026


https://github.com/emrekultursay updated https://github.com/llvm/llvm-project/pull/186323

>From 89de82b9ebb69665e104b7b62c4332d5d4adf092 Mon Sep 17 00:00:00 2001
From: Emre Kultursay <emrekultursay at google.com>
Date: Fri, 13 Mar 2026 06:08:32 +0000
Subject: [PATCH 1/2] [lldb] Preserve TargetSP in Platform module lookup

When Platform::GetRemoteSharedModule resolves a module specification
by calling GetModuleSpec on the process, the target context
(TargetSP) is lost. This happens because the underlying process
plugin populates a new ModuleSpec object that does not inherit
the target context.

This causes failures in subsequent symbol resolution steps. For
example, when ModuleList  relies on the TargetSP to query
target-specific settings like target.exec-search-paths and
target.symbols-search-paths, the lookup fails because TargetSP
evaluates to null. This prevents    B from finding local unstripped
libraries.

This commit fixes the issue by transferring the target context from
the original module_spec over to the resolved_module_spec before
proceeding with the lookup.

Additionally, this commit avoids redundant calls to the locate module
callback. Since the platform already handles the callback explicitly,
passing the target context to subsequent ModuleList::GetSharedModule
calls would normally trigger the callback again redundantly. This is
suppressed by passing invoke_locate_callback=false in
Platform::GetSharedModule and ModuleCache::Get. This also avoids
triggering the callback with incomplete module specifications (e.g.
cleared UUIDs) during cache lookups.
---
 lldb/source/Target/ModuleCache.cpp | 2 +-
 lldb/source/Target/Platform.cpp    | 8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/lldb/source/Target/ModuleCache.cpp b/lldb/source/Target/ModuleCache.cpp
index 8160ab1fbb2c3..9978946105456 100644
--- a/lldb/source/Target/ModuleCache.cpp
+++ b/lldb/source/Target/ModuleCache.cpp
@@ -255,7 +255,7 @@ Status ModuleCache::Get(const FileSpec &root_dir_spec, const char *hostname,
   cached_module_spec.GetPlatformFileSpec() = module_spec.GetFileSpec();
 
   error = ModuleList::GetSharedModule(cached_module_spec, cached_module_sp,
-                                      nullptr, did_create_ptr);
+                                      nullptr, did_create_ptr, false);
   if (error.Fail())
     return error;
 
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index c47ef47b0f60c..2978eeef07cbd 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -182,14 +182,14 @@ Status Platform::GetSharedModule(
       resolved_spec.GetFileSpec().PrependPathComponent(m_sdk_sysroot);
       // Try to get shared module with resolved spec.
       error = ModuleList::GetSharedModule(resolved_spec, module_sp, old_modules,
-                                          did_create_ptr);
+                                          did_create_ptr, false);
     }
     // If we don't have sysroot or it didn't work then
     // try original module spec.
     if (!error.Success()) {
       resolved_spec = spec;
       error = ModuleList::GetSharedModule(resolved_spec, module_sp, old_modules,
-                                          did_create_ptr);
+                                          did_create_ptr, false);
     }
     if (error.Success() && module_sp)
       module_sp->SetPlatformFileSpec(resolved_spec.GetFileSpec());
@@ -1525,6 +1525,10 @@ Status Platform::GetRemoteSharedModule(const ModuleSpec &module_spec,
     resolved_module_spec.GetUUID() = module_spec.GetUUID();
   }
 
+  // Retain the target context from the original module_spec since
+  // process->GetModuleSpec might have cleared it.
+  resolved_module_spec.SetTarget(module_spec.GetTargetSP());
+
   // Call locate module callback if set. This allows users to implement their
   // own module cache system. For example, to leverage build system artifacts,
   // to bypass pulling files from remote platform, or to search symbol files

>From efb1a783fafc29e296dcab60e2bc3c21272b9993 Mon Sep 17 00:00:00 2001
From: Emre Kultursay <emrekultursay at google.com>
Date: Fri, 13 Mar 2026 17:14:27 +0000
Subject: [PATCH 2/2] Add inline comments with the argument name

---
 lldb/source/Target/ModuleCache.cpp |  3 ++-
 lldb/source/Target/Platform.cpp    | 10 ++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/lldb/source/Target/ModuleCache.cpp b/lldb/source/Target/ModuleCache.cpp
index 9978946105456..3d2812b0966e4 100644
--- a/lldb/source/Target/ModuleCache.cpp
+++ b/lldb/source/Target/ModuleCache.cpp
@@ -255,7 +255,8 @@ Status ModuleCache::Get(const FileSpec &root_dir_spec, const char *hostname,
   cached_module_spec.GetPlatformFileSpec() = module_spec.GetFileSpec();
 
   error = ModuleList::GetSharedModule(cached_module_spec, cached_module_sp,
-                                      nullptr, did_create_ptr, false);
+                                      nullptr, did_create_ptr,
+                                      /*invoke_locate_callback=*/false);
   if (error.Fail())
     return error;
 
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 2978eeef07cbd..e79b888c0fc38 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -181,15 +181,17 @@ Status Platform::GetSharedModule(
       resolved_spec = spec;
       resolved_spec.GetFileSpec().PrependPathComponent(m_sdk_sysroot);
       // Try to get shared module with resolved spec.
-      error = ModuleList::GetSharedModule(resolved_spec, module_sp, old_modules,
-                                          did_create_ptr, false);
+      error = ModuleList::GetSharedModule(
+          resolved_spec, module_sp, old_modules, did_create_ptr,
+          /*invoke_locate_callback=*/false);
     }
     // If we don't have sysroot or it didn't work then
     // try original module spec.
     if (!error.Success()) {
       resolved_spec = spec;
-      error = ModuleList::GetSharedModule(resolved_spec, module_sp, old_modules,
-                                          did_create_ptr, false);
+      error = ModuleList::GetSharedModule(
+          resolved_spec, module_sp, old_modules, did_create_ptr,
+          /*invoke_locate_callback=*/false);
     }
     if (error.Success() && module_sp)
       module_sp->SetPlatformFileSpec(resolved_spec.GetFileSpec());



More information about the lldb-commits mailing list