[Lldb-commits] [lldb] [lldb] Add a new way of loading files from a shared cache (PR #179881)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 5 01:27:00 PST 2026


================
@@ -649,30 +653,228 @@ static bool ResolveAndVerifyCandidateSupportDir(FileSpec &path) {
     dyld_shared_cache_dylib_text_info;
 }
 
-extern "C" int dyld_shared_cache_iterate_text(
+// All available on at least macOS 12
+extern "C" {
+int dyld_shared_cache_iterate_text(
     const uuid_t cacheUuid,
     void (^callback)(const dyld_shared_cache_dylib_text_info *info));
-extern "C" uint8_t *_dyld_get_shared_cache_range(size_t *length);
-extern "C" bool _dyld_get_shared_cache_uuid(uuid_t uuid);
+uint8_t *_dyld_get_shared_cache_range(size_t *length);
+bool _dyld_get_shared_cache_uuid(uuid_t uuid);
+bool dyld_image_for_each_segment_info(void *image,
+                                      void (^)(const char *segmentName,
+                                               uint64_t vmAddr, uint64_t vmSize,
+                                               int perm));
+const char *dyld_shared_cache_file_path(void);
+bool dyld_shared_cache_for_file(const char *filePath,
+                                void (^block)(void *cache));
+void dyld_shared_cache_copy_uuid(void *cache, uuid_t *uuid);
+uint64_t dyld_shared_cache_get_base_address(void *cache);
+void dyld_shared_cache_for_each_image(void *cache, void (^block)(void *image));
+bool dyld_image_copy_uuid(void *cache, uuid_t *uuid);
+const char *dyld_image_get_installname(void *image);
+const char *dyld_image_get_file_path(void *image);
+}
 
 namespace {
 class SharedCacheInfo {
 public:
-  const UUID &GetUUID() const { return m_uuid; }
-  const llvm::StringMap<SharedCacheImageInfo> &GetImages() const {
-    return m_images;
+  llvm::StringMap<SharedCacheImageInfo> &GetImages() {
+    return m_caches[m_host_uuid];
   }
 
   SharedCacheInfo();
 
 private:
   bool CreateSharedCacheInfoWithInstrospectionSPIs();
+  void CreateSharedCacheInfoLLDBsVirtualMemory();
+  bool CreateHostSharedCacheImageList();
+
+  // Given the UUID and filepath to a shared cache on the local debug host
+  // system, open it and add all of the binary images to m_caches.
+  bool CreateSharedCacheImageList(UUID uuid, std::string filepath);
 
-  llvm::StringMap<SharedCacheImageInfo> m_images;
-  UUID m_uuid;
+  std::map<UUID, llvm::StringMap<SharedCacheImageInfo>> m_caches;
----------------
JDevlieghere wrote:

`std::map` is slow and this is somewhat performance sensitive code. The number of entries will likely be small, so this seems like a great candidate for `llvm::SmallDenseMap`. You may need to implement traits for the key (UUID) if that doesn't exist already, but that's trivial and we have examples of that in LLDB already.

https://github.com/llvm/llvm-project/pull/179881


More information about the lldb-commits mailing list