[Lldb-commits] [PATCH] D132710: [lldb] Computer and apply the slide to the fileset entry's vmaddr

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 25 16:16:55 PDT 2022


JDevlieghere created this revision.
JDevlieghere added a reviewer: jasonmolenda.
Herald added a project: All.
JDevlieghere requested review of this revision.

Computer and apply the slide to the fileset entry's vmaddr when reading a fileset from memory.


https://reviews.llvm.org/D132710

Files:
  lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp
  lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.h


Index: lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.h
===================================================================
--- lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.h
+++ lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.h
@@ -73,7 +73,6 @@
         : vmaddr(vmaddr), fileoff(fileoff), id(id) {}
     uint64_t vmaddr;
     uint64_t fileoff;
-    uint64_t slide;
     std::string id;
   };
 
Index: lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp
===================================================================
--- lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp
+++ lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp
@@ -133,21 +133,34 @@
 
 static bool
 ParseFileset(DataExtractor &data, mach_header header,
-             std::vector<ObjectContainerMachOFileset::Entry> &entries) {
+             std::vector<ObjectContainerMachOFileset::Entry> &entries,
+             llvm::Optional<lldb::addr_t> load_addr = llvm::None) {
   lldb::offset_t offset = MachHeaderSizeFromMagic(header.magic);
+  lldb::offset_t slide = 0;
   for (uint32_t i = 0; i < header.ncmds; ++i) {
     const lldb::offset_t load_cmd_offset = offset;
     load_command lc = {};
     if (data.GetU32(&offset, &lc.cmd, 2) == nullptr)
       break;
 
+    // If we know the load address we can compute the slide.
+    if (load_addr) {
+      if (lc.cmd == llvm::MachO::LC_SEGMENT_64) {
+        segment_command_64 segment;
+        data.CopyData(load_cmd_offset, sizeof(segment_command_64), &segment);
+        if (llvm::StringRef(segment.segname) == "__TEXT")
+          slide = *load_addr - segment.vmaddr;
+      }
+    }
+
     if (lc.cmd == LC_FILESET_ENTRY) {
       fileset_entry_command entry;
       data.CopyData(load_cmd_offset, sizeof(fileset_entry_command), &entry);
       lldb::offset_t entry_id_offset = load_cmd_offset + entry.entry_id;
       const char *id = data.GetCStr(&entry_id_offset);
-      entries.emplace_back(entry.vmaddr, entry.fileoff, std::string(id));
+      entries.emplace_back(entry.vmaddr + slide, entry.fileoff, std::string(id));
     }
+
     offset = load_cmd_offset + lc.cmdsize;
   }
 
@@ -198,7 +211,7 @@
     m_data.SetData(data_sp);
   }
 
-  return ParseFileset(m_data, *header, m_entries);
+  return ParseFileset(m_data, *header, m_entries, m_memory_addr);
 }
 
 size_t ObjectContainerMachOFileset::GetModuleSpecifications(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132710.455749.patch
Type: text/x-patch
Size: 2546 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220825/2bf9200f/attachment.bin>


More information about the lldb-commits mailing list