https://github.com/jasonmolenda created 
https://github.com/llvm/llvm-project/pull/182216

The code to check with the shared cache binary provider was previously in the 
native host platform (PlatformDarwinDevice), but it also needs to be called 
from PlatformAppleSimulator for simulator debug sessions.  Move the code to the 
base class PlatformDarwin and call it from both subclasses.  No changes to the 
code itself, just moving it to the base class.

rdar://170693756

>From c4f9edf9ecd4118b3043c1e40430b7048a78f3fd Mon Sep 17 00:00:00 2001
From: Jason Molenda <[email protected]>
Date: Wed, 18 Feb 2026 20:36:12 -0800
Subject: [PATCH] [lldb] Check the shared cache binary provider for Simulator
 sessions The code to check with the shared cache binary provider was
 previously in the native host platform (PlatformDarwinDevice), but it also
 needs to be called from PlatformAppleSimulator for simulator debug sessions. 
 Move the code to the base class PlatformDarwin and call it from both
 subclasses.  No changes to the code itself, just moving it to the base class.

rdar://170693756
---
 .../MacOSX/PlatformAppleSimulator.cpp         |  8 ++-
 .../Platform/MacOSX/PlatformDarwin.cpp        | 46 +++++++++++++++++
 .../Plugins/Platform/MacOSX/PlatformDarwin.h  |  6 +++
 .../Platform/MacOSX/PlatformDarwinDevice.cpp  | 49 ++-----------------
 4 files changed, 64 insertions(+), 45 deletions(-)

diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp 
b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
index 00aeeb4da6913..995c0d395e19d 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
@@ -421,11 +421,17 @@ Status PlatformAppleSimulator::GetSymbolFile(const 
FileSpec &platform_file,
 Status PlatformAppleSimulator::GetSharedModule(
     const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
     llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr) {
+
+  Status error;
+  error = GetModuleFromSharedCaches(module_spec, process, module_sp,
+                                    old_modules, did_create_ptr);
+  if (module_sp)
+    return error;
+
   // For iOS/tvOS/watchOS, the SDK files are all cached locally on the
   // host system. So first we ask for the file in the cached SDK, then
   // we attempt to get a shared module for the right architecture with
   // the right UUID.
-  Status error;
   ModuleSpec platform_module_spec(module_spec);
   const FileSpec &platform_file = module_spec.GetFileSpec();
   error = GetSymbolFile(platform_file, module_spec.GetUUIDPtr(),
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 5e1aa33a59f89..3d12f9f815661 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -33,6 +33,7 @@
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/SymbolFile.h"
 #include "lldb/Symbol/SymbolVendor.h"
+#include "lldb/Target/DynamicLoader.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
@@ -422,6 +423,51 @@ Status PlatformDarwin::GetSharedModule(
     module_sp->SetPlatformFileSpec(module_spec.GetFileSpec());
   return error;
 }
+Status PlatformDarwin::GetModuleFromSharedCaches(
+    const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
+    llvm::SmallVectorImpl<ModuleSP> *old_modules, bool *did_create_ptr) {
+  Status err;
+
+  SymbolSharedCacheUse sc_mode =
+      
ModuleList::GetGlobalModuleListProperties().GetSharedCacheBinaryLoading();
+  SharedCacheImageInfo image_info;
+  if (process && process->GetDynamicLoader()) {
+    addr_t sc_base_addr;
+    UUID sc_uuid;
+    LazyBool using_sc, private_sc;
+    FileSpec sc_path;
+    if (process->GetDynamicLoader()->GetSharedCacheInformation(
+            sc_base_addr, sc_uuid, using_sc, private_sc, sc_path)) {
+      if (module_spec.GetUUID())
+        image_info = HostInfo::GetSharedCacheImageInfo(module_spec.GetUUID(),
+                                                       sc_uuid, sc_mode);
+      else
+        image_info = HostInfo::GetSharedCacheImageInfo(
+            module_spec.GetFileSpec().GetPathAsConstString(), sc_uuid, 
sc_mode);
+    }
+  }
+  // Fall back to looking for the file in lldb's own shared cache.
+  if (!image_info.GetUUID())
+    image_info = HostInfo::GetSharedCacheImageInfo(
+        module_spec.GetFileSpec().GetPathAsConstString(), sc_mode);
+
+  // If we found it and it has the correct UUID, let's proceed with
+  // creating a module from the memory contents.
+  if (image_info.GetUUID() && (!module_spec.GetUUID() ||
+                               module_spec.GetUUID() == image_info.GetUUID())) 
{
+    ModuleSpec shared_cache_spec(module_spec.GetFileSpec(),
+                                 image_info.GetUUID(),
+                                 image_info.GetExtractor());
+    err = ModuleList::GetSharedModule(shared_cache_spec, module_sp, 
old_modules,
+                                      did_create_ptr);
+    if (module_sp) {
+      Log *log = GetLog(LLDBLog::Platform | LLDBLog::Modules);
+      LLDB_LOGF(log, "module %s was found in a shared cache",
+                module_spec.GetFileSpec().GetPath().c_str());
+    }
+  }
+  return err;
+}
 
 size_t
 PlatformDarwin::GetSoftwareBreakpointTrapOpcode(Target &target,
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index 82e69e36dca0c..dc81a9baf5e51 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -76,6 +76,12 @@ class PlatformDarwin : public PlatformPOSIX {
                          llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
                          bool *did_create_ptr) override;
 
+  Status
+  GetModuleFromSharedCaches(const ModuleSpec &module_spec, Process *process,
+                            lldb::ModuleSP &module_sp,
+                            llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
+                            bool *did_create_ptr);
+
   size_t GetSoftwareBreakpointTrapOpcode(Target &target,
                                          BreakpointSite *bp_site) override;
 
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
index 6b0e8514342b2..26a507bbe1310 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
@@ -314,49 +314,11 @@ lldb_private::Status 
PlatformDarwinDevice::GetSharedModuleWithLocalCache(
   Status err;
 
   if (CheckLocalSharedCache()) {
-
-    SymbolSharedCacheUse sc_mode = ModuleList::GetGlobalModuleListProperties()
-                                       .GetSharedCacheBinaryLoading();
-    SharedCacheImageInfo image_info;
-    if (process && process->GetDynamicLoader()) {
-      addr_t sc_base_addr;
-      UUID sc_uuid;
-      LazyBool using_sc, private_sc;
-      FileSpec sc_path;
-      if (process->GetDynamicLoader()->GetSharedCacheInformation(
-              sc_base_addr, sc_uuid, using_sc, private_sc, sc_path)) {
-        if (module_spec.GetUUID())
-          image_info = HostInfo::GetSharedCacheImageInfo(module_spec.GetUUID(),
-                                                         sc_uuid, sc_mode);
-        else
-          image_info = HostInfo::GetSharedCacheImageInfo(
-              module_spec.GetFileSpec().GetPathAsConstString(), sc_uuid,
-              sc_mode);
-      }
-    }
-
-    // Fall back to looking for the file in lldb's own shared cache.
-    if (!image_info.GetUUID())
-      image_info = HostInfo::GetSharedCacheImageInfo(
-          module_spec.GetFileSpec().GetPathAsConstString(), sc_mode);
-
-    // If we found it and it has the correct UUID, let's proceed with
-    // creating a module from the memory contents.
-    if (image_info.GetUUID() &&
-        (!module_spec.GetUUID() ||
-         module_spec.GetUUID() == image_info.GetUUID())) {
-      ModuleSpec shared_cache_spec(module_spec.GetFileSpec(),
-                                   image_info.GetUUID(),
-                                   image_info.GetExtractor());
-      err = ModuleList::GetSharedModule(shared_cache_spec, module_sp,
-                                        old_modules, did_create_ptr);
-      if (module_sp) {
-        LLDB_LOGF(log, "[%s] module %s was found in the in-memory shared 
cache",
-                  (IsHost() ? "host" : "remote"),
-                  module_spec.GetFileSpec().GetPath().c_str());
-        return err;
-      }
-    }
+    err = GetModuleFromSharedCaches(module_spec, process, module_sp,
+                                    old_modules, did_create_ptr);
+    if (module_sp)
+      return err;
+  }
 
     // We failed to find the module in our shared cache. Let's see if we have a
     // copy in our device support directory.
@@ -378,7 +340,6 @@ lldb_private::Status 
PlatformDarwinDevice::GetSharedModuleWithLocalCache(
                   local_spec.GetFileSpec().GetPath().c_str());
         return err;
       }
-    }
   }
 
   err = ModuleList::GetSharedModule(module_spec, module_sp, old_modules,

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to