Author: Jason Molenda
Date: 2026-02-16T18:13:10-08:00
New Revision: e496e3c273b1d7bb6e4665748c1ade65926d5041

URL: 
https://github.com/llvm/llvm-project/commit/e496e3c273b1d7bb6e4665748c1ade65926d5041
DIFF: 
https://github.com/llvm/llvm-project/commit/e496e3c273b1d7bb6e4665748c1ade65926d5041.diff

LOG: [lldb][macOS] Index shared cache files by UUID & filename (#180874)

The shared cache index only had accessors for getting a file from a
shared cache by filename. In some environments like iOS Simulator, a
filename can be either the actual realpath name of the framework in an
SDK or simulator runtime install location, or rooted on / like
/System/LibraryFrameworks/SwiftUI.framework. Because the searches for
binaries were by filename, this divergence would be a problem. However,
searching for binaries by the binary's UUID can remove that ambiguity.

I changed HostInfoMacOSX's store of SharedCacheImageInfo's to have a
std::vector of all of the SharedCacheImageInfo's in a shared cache. Then
I create a mapping of filename-to-SharedCacheImageInfo* and a mapping of
UUID-to-SharedCacheImageInfo*, both pointing into the now-frozen
std::vector. I added a HostInfo::GetSharedCacheImageInfo method to fetch
an entry by shared-cache UUID + file UUID, in addition to the previous
shared-cache UUID + filename.

Have HostInfoMacOSX store the filenames it gets from the libdyld SPI in
ConstStrings to make it clear that they have infinite lifetime in the
process, and we don't need to do anything further.

rdar://148939795

---------

Co-authored-by: Jonas Devlieghere <[email protected]>

Added: 
    

Modified: 
    lldb/include/lldb/Host/HostInfoBase.h
    lldb/include/lldb/Host/macosx/HostInfoMacOSX.h
    lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
    lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
    lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.cpp
    lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Host/HostInfoBase.h 
b/lldb/include/lldb/Host/HostInfoBase.h
index 25e970ffb0aaa..cfc41581636b2 100644
--- a/lldb/include/lldb/Host/HostInfoBase.h
+++ b/lldb/include/lldb/Host/HostInfoBase.h
@@ -30,15 +30,17 @@ class FileSpec;
 
 struct SharedCacheImageInfo {
   SharedCacheImageInfo()
-      : m_uuid(), m_extractor_sp(), m_create_data_extractor(nullptr),
-        m_image_baton(nullptr) {}
-  SharedCacheImageInfo(UUID uuid, lldb::DataExtractorSP extractor_sp)
-      : m_uuid(uuid), m_extractor_sp(extractor_sp),
+      : m_filename(), m_uuid(), m_extractor_sp(),
+        m_create_data_extractor(nullptr), m_image_baton(nullptr) {}
+  SharedCacheImageInfo(ConstString filename, UUID uuid,
+                       lldb::DataExtractorSP extractor_sp)
+      : m_filename(filename), m_uuid(uuid), m_extractor_sp(extractor_sp),
         m_create_data_extractor(nullptr), m_image_baton(nullptr) {}
   SharedCacheImageInfo(
-      UUID uuid, lldb::DataExtractorSP (*create_data_extractor)(void *image),
+      ConstString filename, UUID uuid,
+      lldb::DataExtractorSP (*create_data_extractor)(void *image),
       void *image_baton)
-      : m_uuid(uuid), m_extractor_sp(),
+      : m_filename(filename), m_uuid(uuid), m_extractor_sp(),
         m_create_data_extractor(create_data_extractor),
         m_image_baton(image_baton) {}
 
@@ -47,6 +49,7 @@ struct SharedCacheImageInfo {
       m_extractor_sp = m_create_data_extractor(m_image_baton);
     return m_extractor_sp;
   }
+  ConstString GetFilename() const { return m_filename; }
   const UUID &GetUUID() const { return m_uuid; }
   void *GetImageBaton();
   void SetExtractor(lldb::DataExtractorSP extractor_sp) {
@@ -57,6 +60,7 @@ struct SharedCacheImageInfo {
       lldb::DataExtractorSP (*create_data_extractor)(void *image));
 
 private:
+  ConstString m_filename;
   UUID m_uuid;
   lldb::DataExtractorSP m_extractor_sp;
   lldb::DataExtractorSP (*m_create_data_extractor)(void *image);
@@ -183,15 +187,56 @@ class HostInfoBase {
     return llvm::errorCodeToError(llvm::errc::no_such_file_or_directory);
   }
 
-  /// Return information about module \p image_name if it is loaded in
+  /// Return information about module \p filepath if it is loaded in
   /// the current process's address space.
   ///
-  /// \param[in] use_sc_binary_directly
+  /// \param[in] sc_mode
+  ///     Flag to control if this method can try to read a shared
+  ///     cache binary blob directly, needed to keep user settings out of
+  ///     Host.
+  static SharedCacheImageInfo
+  GetSharedCacheImageInfo(ConstString filepath,
+                          lldb::SymbolSharedCacheUse sc_mode) {
+    return {};
+  }
+
+  /// Return information about module \p uuid if it is loaded in
+  /// the current process's address space.
+  ///
+  /// \param[in] sc_mode
+  ///     Flag to control if this method can try to read a shared
+  ///     cache binary blob directly, needed to keep user settings out of
+  ///     Host.
+  static SharedCacheImageInfo
+  GetSharedCacheImageInfo(const UUID &uuid,
+                          lldb::SymbolSharedCacheUse sc_mode) {
+    return {};
+  }
+
+  /// Return information about module \p filepath, if it is loaded in
+  /// the current process's address space using shared cache \p sc_uuid.
+  /// The shared cache must have been previously indexed.
+  ///
+  /// \param[in] sc_mode
+  ///     Flag to control if this method can try to read a shared
+  ///     cache binary blob directly, needed to keep user settings out of
+  ///     Host.
+  static SharedCacheImageInfo
+  GetSharedCacheImageInfo(ConstString filepath, const UUID &sc_uuid,
+                          lldb::SymbolSharedCacheUse sc_mode) {
+    return {};
+  }
+
+  /// Return information about module \p uuid, if it is loaded in
+  /// the current process's address space using shared cache \p sc_uuid.
+  /// The shared cache must have been previously indexed.
+  ///
+  /// \param[in] sc_mode
   ///     Flag to control if this method can try to read a shared
   ///     cache binary blob directly, needed to keep user settings out of
   ///     Host.
   static SharedCacheImageInfo
-  GetSharedCacheImageInfo(llvm::StringRef image_name,
+  GetSharedCacheImageInfo(const UUID &uuid, const UUID &sc_uuid,
                           lldb::SymbolSharedCacheUse sc_mode) {
     return {};
   }

diff  --git a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h 
b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h
index d410143cbcaa6..ed00c44df4bdc 100644
--- a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h
+++ b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h
@@ -43,11 +43,16 @@ class HostInfoMacOSX : public HostInfoPosix {
 
   /// Shared cache utilities
   static SharedCacheImageInfo
-  GetSharedCacheImageInfo(llvm::StringRef image_name,
+  GetSharedCacheImageInfo(ConstString filepath,
                           lldb::SymbolSharedCacheUse sc_mode);
+  static SharedCacheImageInfo
+  GetSharedCacheImageInfo(const UUID &uuid, lldb::SymbolSharedCacheUse 
sc_mode);
 
   static SharedCacheImageInfo
-  GetSharedCacheImageInfo(llvm::StringRef image_name, const UUID &uuid,
+  GetSharedCacheImageInfo(ConstString filepath, const UUID &sc_uuid,
+                          lldb::SymbolSharedCacheUse sc_mode);
+  static SharedCacheImageInfo
+  GetSharedCacheImageInfo(const UUID &uuid, const UUID &sc_uuid,
                           lldb::SymbolSharedCacheUse sc_mode);
 
   static bool SharedCacheIndexFiles(FileSpec &filepath, UUID &uuid,

diff  --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm 
b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
index c29ff36731396..a46c97514f67e 100644
--- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -11,6 +11,7 @@
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Utility/Args.h"
+#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/DataBuffer.h"
 #include "lldb/Utility/DataExtractor.h"
 #include "lldb/Utility/LLDBLog.h"
@@ -18,6 +19,7 @@
 #include "lldb/Utility/Timer.h"
 #include "lldb/Utility/VirtualDataExtractor.h"
 
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
@@ -683,18 +685,28 @@ void dyld_shared_cache_for_each_image(dyld_shared_cache_t 
cache,
 namespace {
 class SharedCacheInfo {
 public:
-  llvm::StringMap<SharedCacheImageInfo> &GetImages() {
-    return m_caches[m_host_uuid];
+  SharedCacheImageInfo GetByFilename(UUID sc_uuid, ConstString filename) {
+    std::lock_guard<std::recursive_mutex> guard(m_mutex);
+    if (!sc_uuid)
+      sc_uuid = m_host_uuid;
+    if (!m_filename_map.contains(sc_uuid))
+      return {};
+    if (!m_filename_map[sc_uuid].contains(filename))
+      return {};
+    size_t idx = m_filename_map[sc_uuid][filename];
+    return m_file_infos[sc_uuid][idx];
   }
 
-  bool GetImages(llvm::StringMap<SharedCacheImageInfo> **images,
-                 const UUID &uuid) {
-    if (m_caches.find(uuid) != m_caches.end()) {
-      *images = &m_caches[uuid];
-      return true;
-    }
-    *images = nullptr;
-    return false;
+  SharedCacheImageInfo GetByUUID(UUID sc_uuid, UUID file_uuid) {
+    std::lock_guard<std::recursive_mutex> guard(m_mutex);
+    if (!sc_uuid)
+      sc_uuid = m_host_uuid;
+    if (!m_uuid_map.contains(sc_uuid))
+      return {};
+    if (!m_uuid_map[sc_uuid].contains(file_uuid))
+      return {};
+    size_t idx = m_uuid_map[sc_uuid][file_uuid];
+    return m_file_infos[sc_uuid][idx];
   }
 
   /// Given the UUID and filepath to a shared cache on the local debug host
@@ -708,9 +720,17 @@ bool GetImages(llvm::StringMap<SharedCacheImageInfo> 
**images,
   void CreateSharedCacheInfoLLDBsVirtualMemory();
   bool CreateHostSharedCacheImageList();
 
-  std::map<UUID, llvm::StringMap<SharedCacheImageInfo>> m_caches;
+  // These three ivars have an initial key of a shared cache UUID.
+  // All of the entries for a given shared cache are in m_file_infos.
+  // m_filename_map and m_uuid_map have pointers into those entries.
+  llvm::SmallDenseMap<UUID, std::vector<SharedCacheImageInfo>> m_file_infos;
+  llvm::SmallDenseMap<UUID, llvm::DenseMap<ConstString, size_t>> 
m_filename_map;
+  llvm::SmallDenseMap<UUID, llvm::DenseMap<UUID, size_t>> m_uuid_map;
+
   UUID m_host_uuid;
 
+  std::recursive_mutex m_mutex;
+
   // macOS 26.4 and newer
   void (*m_dyld_image_retain_4HWTrace)(void *image);
   void (*m_dyld_image_release_4HWTrace)(void *image);
@@ -847,8 +867,9 @@ static dispatch_data_t 
(*g_dyld_image_segment_data_4HWTrace)(
 // Scan the binaries in the specified shared cache filepath
 // if the UUID matches, using the macOS 26.4 libdyld SPI,
 // create a new entry in m_caches.
-bool SharedCacheInfo::CreateSharedCacheImageList(UUID uuid,
+bool SharedCacheInfo::CreateSharedCacheImageList(UUID sc_uuid,
                                                  std::string filepath) {
+  std::lock_guard<std::recursive_mutex> guard(m_mutex);
   if (!m_dyld_image_retain_4HWTrace || !m_dyld_image_release_4HWTrace ||
       !m_dyld_image_segment_data_4HWTrace)
     return false;
@@ -857,45 +878,68 @@ static dispatch_data_t 
(*g_dyld_image_segment_data_4HWTrace)(
     return false;
 
   Log *log = GetLog(LLDBLog::Modules);
+
+  // Have we already indexed this shared cache.
+  if (m_file_infos.contains(sc_uuid)) {
+    LLDB_LOGF(log, "Have already indexed shared cache UUID %s",
+              sc_uuid.GetAsString().c_str());
+    return true;
+  }
+
   LLDB_LOGF(log, "Opening shared cache at %s to check for matching UUID %s",
-            filepath.c_str(), uuid.GetAsString().c_str());
+            filepath.c_str(), sc_uuid.GetAsString().c_str());
 
   __block bool return_failed = false;
   dyld_shared_cache_for_file(filepath.c_str(), ^(dyld_shared_cache_t cache) {
-    uuid_t sc_uuid;
-    dyld_shared_cache_copy_uuid(cache, &sc_uuid);
-    UUID this_cache(sc_uuid, sizeof(uuid_t));
-    if (this_cache != uuid) {
+    uuid_t uuid;
+    dyld_shared_cache_copy_uuid(cache, &uuid);
+    UUID this_cache(uuid, sizeof(uuid_t));
+    if (this_cache != sc_uuid) {
       return_failed = true;
       return;
     }
 
+    // In macOS 26, a shared cache has around 3500 files.
+    m_file_infos[sc_uuid].reserve(4000);
+
     dyld_shared_cache_for_each_image(cache, ^(dyld_image_t image) {
       uuid_t uuid_tmp;
       if (!dyld_image_copy_uuid(image, &uuid_tmp))
         return;
       UUID image_uuid(uuid_tmp, sizeof(uuid_t));
 
+      // Copy the filename into the const string pool to
+      // ensure lifetime.
+      ConstString installname(dyld_image_get_installname(image));
       Log *log = GetLog(LLDBLog::Modules);
       if (log && log->GetVerbose())
-        LLDB_LOGF(log, "sc file %s image %p", 
dyld_image_get_installname(image),
+        LLDB_LOGF(log, "sc file %s image %p", installname.GetCString(),
                   (void *)image);
 
       m_dyld_image_retain_4HWTrace(image);
-      m_caches[m_host_uuid][dyld_image_get_installname(image)] =
-          SharedCacheImageInfo(image_uuid, map_shared_cache_binary_segments,
-                               image);
+      m_file_infos[sc_uuid].push_back(SharedCacheImageInfo(
+          installname, image_uuid, map_shared_cache_binary_segments, image));
     });
   });
   if (return_failed)
     return false;
 
+  // Vector of SharedCacheImageInfos has been fully populated, we can
+  // take pointers to the objects now.
+  size_t file_info_size = m_file_infos[sc_uuid].size();
+  for (size_t i = 0; i < file_info_size; i++) {
+    SharedCacheImageInfo *entry = &m_file_infos[sc_uuid][i];
+    m_filename_map[sc_uuid][entry->GetFilename()] = i;
+    m_uuid_map[sc_uuid][entry->GetUUID()] = i;
+  }
+
   return true;
 }
 
 // Get the filename and uuid of lldb's own shared cache, scan
 // the files in it using the macOS 26.4 and newer libdyld SPI.
 bool SharedCacheInfo::CreateHostSharedCacheImageList() {
+  std::lock_guard<std::recursive_mutex> guard(m_mutex);
   std::string host_shared_cache_file = dyld_shared_cache_file_path();
   __block UUID host_sc_uuid;
   dyld_shared_cache_for_file(host_shared_cache_file.c_str(),
@@ -915,6 +959,7 @@ static dispatch_data_t 
(*g_dyld_image_segment_data_4HWTrace)(
 // libdyld SPI present on macOS 12 and newer, when building against
 // the internal SDK, and add an entry to the m_caches map.
 bool SharedCacheInfo::CreateSharedCacheInfoWithInstrospectionSPIs() {
+  std::lock_guard<std::recursive_mutex> guard(m_mutex);
 #if defined(SDK_HAS_NEW_DYLD_INTROSPECTION_SPIS)
   dyld_process_t dyld_process = dyld_process_create_for_current_task();
   if (!dyld_process)
@@ -936,6 +981,9 @@ static dispatch_data_t 
(*g_dyld_image_segment_data_4HWTrace)(
   if (!shared_cache)
     return false;
 
+  // In macOS 26, a shared cache has around 3500 files.
+  m_file_infos[m_host_uuid].reserve(4000);
+
   dyld_shared_cache_for_each_image(shared_cache, ^(dyld_image_t image) {
     __block uint64_t minVmAddr = UINT64_MAX;
     __block uint64_t maxVmAddr = 0;
@@ -954,9 +1002,21 @@ static dispatch_data_t 
(*g_dyld_image_segment_data_4HWTrace)(
     lldb::DataBufferSP data_sp = std::make_shared<DataBufferUnowned>(
         (uint8_t *)minVmAddr, maxVmAddr - minVmAddr);
     lldb::DataExtractorSP extractor_sp = 
std::make_shared<DataExtractor>(data_sp);
-    m_caches[m_host_uuid][dyld_image_get_installname(image)] =
-        SharedCacheImageInfo{UUID(uuid, 16), extractor_sp};
+    // Copy the filename into the const string pool to
+    // ensure lifetime.
+    ConstString installname(dyld_image_get_installname(image));
+    m_file_infos[m_host_uuid].push_back(
+        SharedCacheImageInfo(installname, UUID(uuid, 16), extractor_sp));
   });
+
+  // std::vector of SharedCacheImageInfos has been fully populated, we can
+  // take pointers to the objects now.
+  size_t file_info_size = m_file_infos[m_host_uuid].size();
+  for (size_t i = 0; i < file_info_size; i++) {
+    SharedCacheImageInfo *entry = &m_file_infos[m_host_uuid][i];
+    m_filename_map[m_host_uuid][entry->GetFilename()] = i;
+    m_uuid_map[m_host_uuid][entry->GetUUID()] = i;
+  }
   return true;
 #endif
   return false;
@@ -966,10 +1026,14 @@ static dispatch_data_t 
(*g_dyld_image_segment_data_4HWTrace)(
 // libdyld SPI available on macOS 10.13 or newer, add an entry to
 // m_caches.
 void SharedCacheInfo::CreateSharedCacheInfoLLDBsVirtualMemory() {
+  std::lock_guard<std::recursive_mutex> guard(m_mutex);
   size_t shared_cache_size;
   uint8_t *shared_cache_start =
       _dyld_get_shared_cache_range(&shared_cache_size);
 
+  // In macOS 26, a shared cache has around 3500 files.
+  m_file_infos[m_host_uuid].reserve(4000);
+
   dyld_shared_cache_iterate_text(
       m_host_uuid.GetBytes().data(),
       ^(const dyld_shared_cache_dylib_text_info *info) {
@@ -978,9 +1042,19 @@ static dispatch_data_t 
(*g_dyld_image_segment_data_4HWTrace)(
             shared_cache_size - info->textSegmentOffset);
         lldb::DataExtractorSP extractor_sp =
             std::make_shared<DataExtractor>(buffer_sp);
-        m_caches[m_host_uuid][info->path] =
-            SharedCacheImageInfo{UUID(info->dylibUuid, 16), extractor_sp};
+        ConstString filepath(info->path);
+        m_file_infos[m_host_uuid].push_back(SharedCacheImageInfo(
+            filepath, UUID(info->dylibUuid, 16), extractor_sp));
       });
+
+  // std::vector of SharedCacheImageInfos has been fully populated, we can
+  // take pointers to the objects now.
+  size_t file_info_size = m_file_infos[m_host_uuid].size();
+  for (size_t i = 0; i < file_info_size; i++) {
+    SharedCacheImageInfo *entry = &m_file_infos[m_host_uuid][i];
+    m_filename_map[m_host_uuid][entry->GetFilename()] = i;
+    m_uuid_map[m_host_uuid][entry->GetUUID()] = i;
+  }
 }
 
 SharedCacheInfo &GetSharedCacheSingleton(SymbolSharedCacheUse sc_mode) {
@@ -989,19 +1063,25 @@ static dispatch_data_t 
(*g_dyld_image_segment_data_4HWTrace)(
 }
 
 SharedCacheImageInfo
-HostInfoMacOSX::GetSharedCacheImageInfo(llvm::StringRef image_name,
+HostInfoMacOSX::GetSharedCacheImageInfo(ConstString filepath,
                                         SymbolSharedCacheUse sc_mode) {
-  return GetSharedCacheSingleton(sc_mode).GetImages().lookup(image_name);
+  return GetSharedCacheSingleton(sc_mode).GetByFilename(UUID(), filepath);
 }
 
 SharedCacheImageInfo
-HostInfoMacOSX::GetSharedCacheImageInfo(llvm::StringRef image_name,
-                                        const UUID &uuid,
+HostInfoMacOSX::GetSharedCacheImageInfo(const UUID &file_uuid,
                                         SymbolSharedCacheUse sc_mode) {
-  llvm::StringMap<SharedCacheImageInfo> *shared_cache_info;
-  if (GetSharedCacheSingleton(sc_mode).GetImages(&shared_cache_info, uuid))
-    return shared_cache_info->lookup(image_name);
-  return {};
+  return GetSharedCacheSingleton(sc_mode).GetByUUID(UUID(), file_uuid);
+}
+
+SharedCacheImageInfo HostInfoMacOSX::GetSharedCacheImageInfo(
+    ConstString filepath, const UUID &sc_uuid, SymbolSharedCacheUse sc_mode) {
+  return GetSharedCacheSingleton(sc_mode).GetByFilename(sc_uuid, filepath);
+}
+
+SharedCacheImageInfo HostInfoMacOSX::GetSharedCacheImageInfo(
+    const UUID &file_uuid, const UUID &sc_uuid, SymbolSharedCacheUse sc_mode) {
+  return GetSharedCacheSingleton(sc_mode).GetByUUID(sc_uuid, file_uuid);
 }
 
 bool HostInfoMacOSX::SharedCacheIndexFiles(FileSpec &filepath, UUID &uuid,

diff  --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
index 04c7e3aa668aa..eb9f49aef2069 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -130,12 +130,13 @@ ModuleSP 
DynamicLoaderDarwin::FindTargetModuleForImageInfo(
 
   if (!module_sp &&
       HostInfo::GetArchitecture().IsCompatibleMatch(target.GetArchitecture())) 
{
-    // When debugging on the host, we are most likely using the same shared
-    // cache as our inferior. The dylibs from the shared cache might not
-    // exist on the filesystem, so let's use the images in our own memory
-    // to create the modules.
-    // Check if the requested image is in our shared cache.
+
     SharedCacheImageInfo image_info;
+
+    // If we have a shared cache filepath and UUID, ask HostInfo
+    // if it can provide the SourceCacheImageInfo for the binary
+    // out of that shared cache.  Search by the Module's UUID if
+    // available, else the filepath.
     addr_t sc_base_addr;
     UUID sc_uuid;
     LazyBool using_sc;
@@ -145,12 +146,19 @@ ModuleSP 
DynamicLoaderDarwin::FindTargetModuleForImageInfo(
                                        .GetSharedCacheBinaryLoading();
     if (GetSharedCacheInformation(sc_base_addr, sc_uuid, using_sc, private_sc,
                                   sc_path) &&
-        sc_uuid)
-      image_info = HostInfo::GetSharedCacheImageInfo(
-          module_spec.GetFileSpec().GetPath(), sc_uuid, sc_mode);
-    else
+        sc_uuid) {
+      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);
+    } else {
+      // Fall back to looking lldb's own shared cache by filename
       image_info = HostInfo::GetSharedCacheImageInfo(
-          module_spec.GetFileSpec().GetPath(), sc_mode);
+          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.

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
index 3afd360e0a621..6b0e8514342b2 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
@@ -314,10 +314,6 @@ lldb_private::Status 
PlatformDarwinDevice::GetSharedModuleWithLocalCache(
   Status err;
 
   if (CheckLocalSharedCache()) {
-    // When debugging on the host, we are most likely using the same shared
-    // cache as our inferior. The dylibs from the shared cache might not
-    // exist on the filesystem, so let's use the images in our own memory
-    // to create the modules.
 
     SymbolSharedCacheUse sc_mode = ModuleList::GetGlobalModuleListProperties()
                                        .GetSharedCacheBinaryLoading();
@@ -328,14 +324,21 @@ lldb_private::Status 
PlatformDarwinDevice::GetSharedModuleWithLocalCache(
       LazyBool using_sc, private_sc;
       FileSpec sc_path;
       if (process->GetDynamicLoader()->GetSharedCacheInformation(
-              sc_base_addr, sc_uuid, using_sc, private_sc, sc_path))
-        image_info = HostInfo::GetSharedCacheImageInfo(
-            module_spec.GetFileSpec().GetPath(), sc_uuid, sc_mode);
+              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().GetPath(), sc_mode);
+          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.

diff  --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp 
b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index c8667ee247f23..57d86ef71eecc 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -4375,12 +4375,16 @@ StructuredData::ObjectSP 
ProcessGDBRemote::GetSharedCacheInfo() {
         FileSpec sc_path(
             dict->GetValueForKey("shared_cache_path")->GetStringValue());
 
-        // Attempt to open the shared cache at sc_path, and
-        // if the uuid matches, index all the files.
-        HostInfo::SharedCacheIndexFiles(
-            sc_path, uuid,
+        SymbolSharedCacheUse sc_mode =
             ModuleList::GetGlobalModuleListProperties()
-                .GetSharedCacheBinaryLoading());
+                .GetSharedCacheBinaryLoading();
+
+        if (sc_mode == eSymbolSharedCacheUseHostAndInferiorSharedCache ||
+            sc_mode == eSymbolSharedCacheUseInferiorSharedCacheOnly) {
+          // Attempt to open the shared cache at sc_path, and
+          // if the uuid matches, index all the files.
+          HostInfo::SharedCacheIndexFiles(sc_path, uuid, sc_mode);
+        }
       }
       m_shared_cache_info_sp = response_sp;
     }

diff  --git 
a/lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.cpp 
b/lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.cpp
index e784e3d37818a..5c1aaac886d6c 100644
--- 
a/lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.cpp
+++ 
b/lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.cpp
@@ -207,7 +207,7 @@ std::optional<ModuleSpec> 
SymbolLocatorDebugSymbols::LocateExecutableObjectFile(
                 ModuleList::GetGlobalModuleListProperties()
                     .GetSharedCacheBinaryLoading();
             SharedCacheImageInfo image_info = 
HostInfo::GetSharedCacheImageInfo(
-                module_spec.GetFileSpec().GetPath(), sc_mode);
+                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.
@@ -653,7 +653,7 @@ static int LocateMacOSXFilesUsingDebugSymbols(const 
ModuleSpec &module_spec,
                 ModuleList::GetGlobalModuleListProperties()
                     .GetSharedCacheBinaryLoading();
             SharedCacheImageInfo image_info = 
HostInfo::GetSharedCacheImageInfo(
-                module_spec.GetFileSpec().GetPath(), sc_mode);
+                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.

diff  --git a/lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp 
b/lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp
index 18bc63a9ce3ee..f4cf3c17e554b 100644
--- a/lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp
+++ b/lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp
@@ -12,8 +12,10 @@
 #include "TestingSupport/SubsystemRAII.h"
 #include "TestingSupport/TestUtilities.h"
 #include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
+#include "lldb/Utility/FileSpec.h"
 #include "lldb/lldb-defines.h"
 #include "gtest/gtest.h"
 
@@ -38,7 +40,8 @@ TEST_F(ObjectFileMachOTest, ModuleFromSharedCacheInfo) {
   Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));
 
   SharedCacheImageInfo image_info = HostInfo::GetSharedCacheImageInfo(
-      "/usr/lib/libobjc.A.dylib", lldb::eSymbolSharedCacheUseHostSharedCache);
+      ConstString("/usr/lib/libobjc.A.dylib"),
+      lldb::eSymbolSharedCacheUseHostSharedCache);
   EXPECT_TRUE(image_info.GetUUID());
   EXPECT_TRUE(image_info.GetExtractor());
 
@@ -86,7 +89,8 @@ TEST_F(ObjectFileMachOTest, ModuleFromSharedCacheInfo) {
 
 TEST_F(ObjectFileMachOTest, IndirectSymbolsInTheSharedCache) {
   SharedCacheImageInfo image_info = HostInfo::GetSharedCacheImageInfo(
-      "/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit",
+      ConstString(
+          "/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit"),
       lldb::eSymbolSharedCacheUseHostSharedCache);
   ModuleSpec spec(FileSpec(), UUID(), image_info.GetExtractor());
   lldb::ModuleSP module = std::make_shared<Module>(spec);


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

Reply via email to