llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Jason Molenda (jasonmolenda)

<details>
<summary>Changes</summary>

In a PR last month I changed the ObjectFile CreateInstance etc methods to 
accept an optional DataExtractorSP instead of a DataBufferSP, and retain the 
extractor in a shared pointer internally in all of the ObjectFile subclasses.  
This is laying the groundwork for using a VirtualDataExtractor for some Mach-O 
binaries on macOS, where the segments of the binary are out-of-order in actual 
memory, and we add a lookup table to make it appear that the TEXT segment is at 
offset 0 in the Extractor, etc.  Working on the actual implementation, I 
realized we were still using DataBufferSP's in ModuleSpec and Module, as well 
as in ObjectFile::GetModuleSpecifications.

I originally was making a much larger NFC change where I had all ObjectFile 
subclasses operating on DataExtractors throughout their implementation, as well 
as in the DWARF parser.  It was a very large patchset.  Many subclasses start 
with their DataExtractor, then create smaller DataExtractors for parts of the 
binary image - the string table, the symbol table, etc., for processing.

After consideration and discussion with Jonas, we agreed that a segment/section 
of a binary will never require a lookup table to access the bytes within it, so 
I changed
VirtualDataExtractor::GetSubsetExtractorSP to (1) require that the Subset be 
contained within a single lookup table entry, and (2) return a simple 
DataExtractor bounded on that byte range.  By doing this, I was able to remove 
all of my very-invasive changes to the ObjectFile subclass internals; it's only 
when they are operating on the entire binary image that care is needed.

One pattern that subclasses like ObjectFileBreakpad use is to take an ArrayRef 
of the DataBuffer for a binary, then create a StringRef of that, then look for 
strings in it.  With a VirtualDataExtractor and out-of-order binary segments, 
with gaps between them, this allows us to search the entire buffer looking for 
a string, and segfault when it gets to an unmapped region of the buffer.  I 
added a VirtualDataExtractor::GetSubsetExtractorSP(0) which gets the largest 
contiguous memory region starting at offset 0 for this use case, and I added a 
comment about what was being done there because I know it is not obvious, and 
people not working on macOS wouldn't be familiar with the requirement.  (when 
we have a ModuleSpec with a DataExtractor, any of the ObjectFile subclasses get 
a shot at Creating, so they all have to be able to iterate on these)

rdar://148939795

---

Patch is 73.38 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/178347.diff


51 Files Affected:

- (modified) lldb/include/lldb/Core/Module.h (+2-2) 
- (modified) lldb/include/lldb/Core/ModuleSpec.h (+9-7) 
- (modified) lldb/include/lldb/Expression/ObjectFileJIT.h (+1-1) 
- (modified) lldb/include/lldb/Host/HostInfoBase.h (+1-1) 
- (modified) lldb/include/lldb/Symbol/ObjectFile.h (+3-3) 
- (modified) lldb/include/lldb/Target/DynamicLoader.h (+9-3) 
- (modified) lldb/include/lldb/lldb-private-interfaces.h (+1-1) 
- (modified) lldb/source/Core/Module.cpp (+18-17) 
- (modified) lldb/source/Expression/ObjectFileJIT.cpp (+1-1) 
- (modified) lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm (+8-5) 
- (modified) 
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp (+1-1) 
- (modified) 
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp (+7-2) 
- (modified) lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h 
(+6-4) 
- (modified) 
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp 
(+1-1) 
- (modified) 
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h (+2-1) 
- (modified) 
lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp 
(+7-6) 
- (modified) 
lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h 
(+1-1) 
- (modified) 
lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.cpp 
(+1-1) 
- (modified) 
lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.h 
(+1-1) 
- (modified) 
lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp
 (+7-6) 
- (modified) 
lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.h
 (+1-1) 
- (modified) 
lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
 (+7-6) 
- (modified) 
lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
 (+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp 
(+20-8) 
- (modified) lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h 
(+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.cpp (+22-10) 
- (modified) lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.h (+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (+17-11) 
- (modified) lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h (+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp (+10-7) 
- (modified) lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.h (+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (+39-36) 
- (modified) lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h (+4-4) 
- (modified) lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp 
(+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h 
(+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp (+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.h (+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp (+7-5) 
- (modified) lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h (+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp (+3-2) 
- (modified) lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h (+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp (+2-2) 
- (modified) lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h (+1-1) 
- (modified) lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp 
(+1-1) 
- (modified) lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp 
(+17-4) 
- (modified) lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp (+4-2) 
- (modified) lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp (+5-4) 
- (modified) lldb/source/Symbol/ObjectFile.cpp (+28-18) 
- (modified) lldb/unittests/Core/ModuleSpecTest.cpp (+4-2) 
- (modified) lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp (+3-3) 
- (modified) lldb/unittests/TestingSupport/TestUtilities.h (+2-1) 


``````````diff
diff --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h
index 643b9a5c3bf54..10c5982ac3c2b 100644
--- a/lldb/include/lldb/Core/Module.h
+++ b/lldb/include/lldb/Core/Module.h
@@ -1044,10 +1044,10 @@ class Module : public 
std::enable_shared_from_this<Module>,
   uint64_t m_object_offset = 0;
   llvm::sys::TimePoint<> m_object_mod_time;
 
-  /// DataBuffer containing the module image, if it was provided at
+  /// DataExtractor containing the module image, if it was provided at
   /// construction time. Otherwise the data will be retrieved by mapping
   /// one of the FileSpec members above.
-  lldb::DataBufferSP m_data_sp;
+  lldb::DataExtractorSP m_extractor_sp;
 
   lldb::ObjectFileSP m_objfile_sp; ///< A shared pointer to the object file
                                    /// parser for this module as it may or may
diff --git a/lldb/include/lldb/Core/ModuleSpec.h 
b/lldb/include/lldb/Core/ModuleSpec.h
index 1af5f144169a8..0306dfc280e57 100644
--- a/lldb/include/lldb/Core/ModuleSpec.h
+++ b/lldb/include/lldb/Core/ModuleSpec.h
@@ -12,6 +12,7 @@
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Target/PathMappingList.h"
 #include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/DataExtractor.h"
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/Iterable.h"
 #include "lldb/Utility/Stream.h"
@@ -30,14 +31,15 @@ class ModuleSpec {
 public:
   ModuleSpec() = default;
 
-  /// If the \c data argument is passed, its contents will be used
+  /// If the \c extractor_sp argument is passed, its contents will be used
   /// as the module contents instead of trying to read them from
   /// \c file_spec .
   ModuleSpec(const FileSpec &file_spec, const UUID &uuid = UUID(),
-             lldb::DataBufferSP data = lldb::DataBufferSP())
-      : m_file(file_spec), m_uuid(uuid), m_object_offset(0), m_data(data) {
-    if (data)
-      m_object_size = data->GetByteSize();
+             lldb::DataExtractorSP extractor_sp = lldb::DataExtractorSP())
+      : m_file(file_spec), m_uuid(uuid), m_object_offset(0),
+        m_extractor_sp(extractor_sp) {
+    if (extractor_sp)
+      m_object_size = extractor_sp->GetByteSize();
     else if (m_file)
       m_object_size = FileSystem::Instance().GetByteSize(file_spec);
   }
@@ -126,7 +128,7 @@ class ModuleSpec {
 
   PathMappingList &GetSourceMappingList() const { return m_source_mappings; }
 
-  lldb::DataBufferSP GetData() const { return m_data; }
+  lldb::DataExtractorSP GetExtractor() const { return m_extractor_sp; }
 
   lldb::TargetSP GetTargetSP() const { return m_target_wp.lock(); }
 
@@ -300,7 +302,7 @@ class ModuleSpec {
   uint64_t m_object_size = 0;
   llvm::sys::TimePoint<> m_object_mod_time;
   mutable PathMappingList m_source_mappings;
-  lldb::DataBufferSP m_data = {};
+  lldb::DataExtractorSP m_extractor_sp = {};
 };
 
 class ModuleSpecList {
diff --git a/lldb/include/lldb/Expression/ObjectFileJIT.h 
b/lldb/include/lldb/Expression/ObjectFileJIT.h
index e3e8c27641698..0694a969ed8d1 100644
--- a/lldb/include/lldb/Expression/ObjectFileJIT.h
+++ b/lldb/include/lldb/Expression/ObjectFileJIT.h
@@ -59,7 +59,7 @@ class ObjectFileJIT : public ObjectFile {
       const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
 
   static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
-                                        lldb::DataBufferSP &data_sp,
+                                        lldb::DataExtractorSP &extractor_sp,
                                         lldb::offset_t data_offset,
                                         lldb::offset_t file_offset,
                                         lldb::offset_t length,
diff --git a/lldb/include/lldb/Host/HostInfoBase.h 
b/lldb/include/lldb/Host/HostInfoBase.h
index a6aaacd9d6feb..670fee19fca3d 100644
--- a/lldb/include/lldb/Host/HostInfoBase.h
+++ b/lldb/include/lldb/Host/HostInfoBase.h
@@ -29,7 +29,7 @@ class FileSpec;
 
 struct SharedCacheImageInfo {
   UUID uuid;
-  lldb::DataBufferSP data_sp;
+  lldb::DataExtractorSP extractor_sp;
 };
 
 namespace {
diff --git a/lldb/include/lldb/Symbol/ObjectFile.h 
b/lldb/include/lldb/Symbol/ObjectFile.h
index 01115a22aeda3..2cdcadd262622 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -177,10 +177,10 @@ class ObjectFile : public 
std::enable_shared_from_this<ObjectFile>,
   static size_t
   GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset,
                           lldb::offset_t file_size, ModuleSpecList &specs,
-                          lldb::DataBufferSP data_sp = lldb::DataBufferSP());
+                          lldb::DataExtractorSP = lldb::DataExtractorSP());
 
   static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
-                                        lldb::DataBufferSP &data_sp,
+                                        lldb::DataExtractorSP &extractor_sp,
                                         lldb::offset_t data_offset,
                                         lldb::offset_t file_offset,
                                         lldb::offset_t file_size,
@@ -659,7 +659,7 @@ class ObjectFile : public 
std::enable_shared_from_this<ObjectFile>,
   // This function returns raw file contents. Do not use it if you want
   // transparent decompression of section contents.
   size_t GetData(lldb::offset_t offset, size_t length,
-                 DataExtractor &data) const;
+                 lldb::DataExtractorSP &data_sp) const;
 
   // This function returns raw file contents. Do not use it if you want
   // transparent decompression of section contents.
diff --git a/lldb/include/lldb/Target/DynamicLoader.h 
b/lldb/include/lldb/Target/DynamicLoader.h
index 7f2652bb28727..04fd7556e1068 100644
--- a/lldb/include/lldb/Target/DynamicLoader.h
+++ b/lldb/include/lldb/Target/DynamicLoader.h
@@ -310,12 +310,18 @@ class DynamicLoader : public PluginInterface {
   ///     private shared cache.
   ///     If this information cannot be fetched, eLazyBoolCalculate.
   ///
+  /// \param[out] shared_cache_path
+  ///     A FileSpec representing the shared cache path being run
+  ///     in the inferior process.
+  ///
   /// \return
   ///     Returns false if this DynamicLoader cannot gather information
   ///     about the shared cache / has no concept of a shared cache.
-  virtual bool GetSharedCacheInformation(lldb::addr_t &base_address, UUID 
&uuid,
-                                         LazyBool &using_shared_cache,
-                                         LazyBool &private_shared_cache) {
+  virtual bool
+  GetSharedCacheInformation(lldb::addr_t &base_address, UUID &uuid,
+                            LazyBool &using_shared_cache,
+                            LazyBool &private_shared_cache,
+                            lldb_private::FileSpec &shared_cache_path) {
     base_address = LLDB_INVALID_ADDRESS;
     uuid.Clear();
     using_shared_cache = eLazyBoolCalculate;
diff --git a/lldb/include/lldb/lldb-private-interfaces.h 
b/lldb/include/lldb/lldb-private-interfaces.h
index 0e02d1ca25746..dbd81b0683f50 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -46,7 +46,7 @@ typedef ObjectContainer 
*(*ObjectContainerCreateMemoryInstance)(
     const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
     const lldb::ProcessSP &process_sp, lldb::addr_t offset);
 typedef size_t (*ObjectFileGetModuleSpecifications)(
-    const FileSpec &file, lldb::DataBufferSP &data_sp,
+    const FileSpec &file, lldb::DataExtractorSP &extractor_sp,
     lldb::offset_t data_offset, lldb::offset_t file_offset,
     lldb::offset_t length, ModuleSpecList &module_specs);
 typedef ObjectFile *(*ObjectFileCreateInstance)(
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 486af1a053344..5cec752b76bb6 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -149,16 +149,17 @@ Module::Module(const ModuleSpec &module_spec)
               module_spec.GetObjectName().AsCString(""),
               module_spec.GetObjectName().IsEmpty() ? "" : ")");
 
-  auto data_sp = module_spec.GetData();
+  auto extractor_sp = module_spec.GetExtractor();
   lldb::offset_t file_size = 0;
-  if (data_sp)
-    file_size = data_sp->GetByteSize();
+  if (extractor_sp)
+    file_size = extractor_sp->GetByteSize();
 
   // First extract all module specifications from the file using the local file
   // path. If there are no specifications, then don't fill anything in
   ModuleSpecList modules_specs;
-  if (ObjectFile::GetModuleSpecifications(
-          module_spec.GetFileSpec(), 0, file_size, modules_specs, data_sp) == 
0)
+  if (ObjectFile::GetModuleSpecifications(module_spec.GetFileSpec(), 0,
+                                          file_size, modules_specs,
+                                          extractor_sp) == 0)
     return;
 
   // Now make sure that one of the module specifications matches what we just
@@ -177,11 +178,11 @@ Module::Module(const ModuleSpec &module_spec)
     return;
   }
 
-  // Set m_data_sp if it was initially provided in the ModuleSpec. Note that
-  // we cannot use the data_sp variable here, because it will have been
-  // modified by GetModuleSpecifications().
-  if (auto module_spec_data_sp = module_spec.GetData()) {
-    m_data_sp = module_spec_data_sp;
+  // Set m_extractor_sp if it was initially provided in the ModuleSpec. Note
+  // that we cannot use the extractor_sp variable here, because it will have
+  // been modified by GetModuleSpecifications().
+  if (auto module_spec_extractor_sp = module_spec.GetExtractor()) {
+    m_extractor_sp = module_spec_extractor_sp;
     m_mod_time = {};
   } else {
     if (module_spec.GetFileSpec())
@@ -1071,9 +1072,9 @@ void Module::GetDescription(llvm::raw_ostream &s,
 }
 
 bool Module::FileHasChanged() const {
-  // We have provided the DataBuffer for this module to avoid accessing the
+  // We have provided the DataExtractor for this module to avoid accessing the
   // filesystem. We never want to reload those files.
-  if (m_data_sp)
+  if (m_extractor_sp)
     return false;
   if (!m_file_has_changed)
     m_file_has_changed =
@@ -1203,18 +1204,18 @@ ObjectFile *Module::GetObjectFile() {
       lldb::offset_t data_offset = 0;
       lldb::offset_t file_size = 0;
 
-      if (m_data_sp)
-        file_size = m_data_sp->GetByteSize();
+      if (m_extractor_sp)
+        file_size = m_extractor_sp->GetByteSize();
       else if (m_file)
         file_size = FileSystem::Instance().GetByteSize(m_file);
 
       if (file_size > m_object_offset) {
         m_did_load_objfile = true;
         // FindPlugin will modify its data_sp argument. Do not let it
-        // modify our m_data_sp member.
+        // modify our m_extractor_sp member.
         DataExtractorSP extractor_sp;
-        if (m_data_sp)
-          extractor_sp = std::make_shared<DataExtractor>(m_data_sp);
+        if (m_extractor_sp)
+          extractor_sp = m_extractor_sp;
         m_objfile_sp = ObjectFile::FindPlugin(
             shared_from_this(), &m_file, m_object_offset,
             file_size - m_object_offset, extractor_sp, data_offset);
diff --git a/lldb/source/Expression/ObjectFileJIT.cpp 
b/lldb/source/Expression/ObjectFileJIT.cpp
index 86ebb27562603..5f51617158197 100644
--- a/lldb/source/Expression/ObjectFileJIT.cpp
+++ b/lldb/source/Expression/ObjectFileJIT.cpp
@@ -61,7 +61,7 @@ ObjectFile *ObjectFileJIT::CreateMemoryInstance(const 
lldb::ModuleSP &module_sp,
 }
 
 size_t ObjectFileJIT::GetModuleSpecifications(
-    const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
+    const lldb_private::FileSpec &file, lldb::DataExtractorSP &extractor_sp,
     lldb::offset_t data_offset, lldb::offset_t file_offset,
     lldb::offset_t length, lldb_private::ModuleSpecList &specs) {
   // JIT'ed object file can't be read from a file on disk
diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm 
b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
index 45ba4baae3d33..19d3601e60109 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/DataExtractor.h"
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Timer.h"
@@ -730,11 +731,13 @@ static bool ResolveAndVerifyCandidateSupportDir(FileSpec 
&path) {
 
   dyld_shared_cache_iterate_text(
       dsc_uuid, ^(const dyld_shared_cache_dylib_text_info *info) {
-        m_images[info->path] = SharedCacheImageInfo{
-            UUID(info->dylibUuid, 16),
-            std::make_shared<DataBufferUnowned>(
-                shared_cache_start + info->textSegmentOffset,
-                shared_cache_size - info->textSegmentOffset)};
+        lldb::DataBufferSP data_sp = std::make_shared<DataBufferUnowned>(
+            shared_cache_start + info->textSegmentOffset,
+            shared_cache_size - info->textSegmentOffset);
+        lldb::DataExtractorSP extractor_sp =
+            std::make_shared<DataExtractor>(data_sp);
+        m_images[info->path] =
+            SharedCacheImageInfo{UUID(info->dylibUuid, 16), extractor_sp};
       });
 }
 
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
index 316723480eb22..e7128ca875b94 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -138,7 +138,7 @@ ModuleSP DynamicLoaderDarwin::FindTargetModuleForImageInfo(
     if (image_info.uuid &&
         (!module_spec.GetUUID() || module_spec.GetUUID() == image_info.uuid)) {
       ModuleSpec shared_cache_spec(module_spec.GetFileSpec(), image_info.uuid,
-                                   image_info.data_sp);
+                                   image_info.extractor_sp);
       module_sp =
           target.GetOrCreateModule(shared_cache_spec, false /* notify */);
     }
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
index ce1a0975260c9..7b07d4aa14fc8 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
@@ -691,7 +691,7 @@ Status DynamicLoaderMacOS::CanLoadImage() {
 
 bool DynamicLoaderMacOS::GetSharedCacheInformation(
     lldb::addr_t &base_address, UUID &uuid, LazyBool &using_shared_cache,
-    LazyBool &private_shared_cache) {
+    LazyBool &private_shared_cache, FileSpec &shared_cache_path) {
   base_address = LLDB_INVALID_ADDRESS;
   uuid.Clear();
   using_shared_cache = eLazyBoolCalculate;
@@ -726,7 +726,12 @@ bool DynamicLoaderMacOS::GetSharedCacheInformation(
         private_shared_cache = eLazyBoolYes;
       else
         private_shared_cache = eLazyBoolNo;
-
+      if (info_dict->HasKey("shared_cache_path")) {
+        std::string filepath = info_dict->GetValueForKey("shared_cache_path")
+                                   ->GetStringValue()
+                                   .str();
+        shared_cache_path.SetPath(filepath);
+      }
       return true;
     }
   }
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h
index bd2c2e0bac538..9bb50de3eadb3 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h
@@ -54,10 +54,12 @@ class DynamicLoaderMacOS : public 
lldb_private::DynamicLoaderDarwin {
 
   lldb_private::Status CanLoadImage() override;
 
-  bool GetSharedCacheInformation(
-      lldb::addr_t &base_address, lldb_private::UUID &uuid,
-      lldb_private::LazyBool &using_shared_cache,
-      lldb_private::LazyBool &private_shared_cache) override;
+  bool
+  GetSharedCacheInformation(lldb::addr_t &base_address,
+                            lldb_private::UUID &uuid,
+                            lldb_private::LazyBool &using_shared_cache,
+                            lldb_private::LazyBool &private_shared_cache,
+                            lldb_private::FileSpec &shared_cache_path) 
override;
 
   // PluginInterface protocol
   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
index f839948660aa0..1ec91548a1866 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -1071,7 +1071,7 @@ Status DynamicLoaderMacOSXDYLD::CanLoadImage() {
 
 bool DynamicLoaderMacOSXDYLD::GetSharedCacheInformation(
     lldb::addr_t &base_address, UUID &uuid, LazyBool &using_shared_cache,
-    LazyBool &private_shared_cache) {
+    LazyBool &private_shared_cache, FileSpec &shared_cache_filepath) {
   base_address = LLDB_INVALID_ADDRESS;
   uuid.Clear();
   using_shared_cache = eLazyBoolCalculate;
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h
index ae7451722a8d7..e3f263a08d7df 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h
@@ -61,7 +61,8 @@ class DynamicLoaderMacOSXDYLD : public 
lldb_private::DynamicLoaderDarwin {
   bool GetSharedCacheInformation(
       lldb::addr_t &base_address, lldb_private::UUID &uuid,
       lldb_private::LazyBool &using_shared_cache,
-      lldb_private::LazyBool &private_shared_cache) override;
+      lldb_private::LazyBool &private_shared_cache,
+      lldb_private::FileSpec &shared_cache_filepath) override;
 
   // PluginInterface protocol
   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
diff --git 
a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp 
b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
index 0adc204ade9db..26729a6224df8 100644
--- 
a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
+++ 
b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
@@ -434,18 +434,19 @@ ObjectFileSP 
ObjectContainerBSDArchive::GetObjectFile(const FileSpec *file) {
 }
 
 size_t ObjectContainerBSDArchive::GetModuleSpecifications(
-    const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
+    const lldb_private::FileSpec &file, lldb::DataExtractorSP &extractor_sp,
     lldb::offset_t data_offset, lldb::offset_t file_offset,
     lldb::offset_t file_size, lldb_private::ModuleSpecList &specs) {
 
+  DataExtractorSP data_extractor_sp = extractor_sp->GetSubsetExtractorSP(
+      data_offset,
+      extractor_sp->GetSharedDataBuffer()->GetByteSize() - data_offset);
   // We have data, which means this is the first 512 bytes of the file Check to
   // see if the magic bytes match and if they do, read the entire table of
   // contents for the archive and cache it
-  DataExtractorSP extractor_sp = std::make_shared<DataExtractor>();
-  extractor_sp->SetData(data_sp, data_offset, data_sp->GetByteSize());
   ArchiveType archive_type =
-      ObjectContainerBSDArchive::MagicBytesMatch(*extractor_sp.get());
-  if (!file || !data_sp || archive_type == ArchiveType::Invalid)
+      ObjectContainerBSDArchive::MagicBytesMatch(*data_extractor_sp.get());
+  if (!file || !data_extractor_sp || archive_type == ArchiveType::Invalid)
     return 0;
 
   const size_t initial_count = specs.GetSize();
@@ -456,7 +457,7 @@ size_t ObjectContainerBSDArchive::GetModuleSpecifications(
   bool set_archive_arch = false;
   if (!archive_sp) {
     set_archive_arch = true;
-    data_sp =
+    DataBufferSP data_sp =
         FileSystem::Instance().CreateDataBuffer(file, file_size, file_offset);
     if (data_sp) {
       extractor_sp->SetData(data_sp);
diff --git 
a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h 
b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchiv...
[truncated]

``````````

</details>


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

Reply via email to