[Lldb-commits] [lldb] [lldb] Make ELF files able to load section headers from memory. (PR #129166)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 10 08:03:48 PDT 2025


================
@@ -270,14 +270,48 @@ class ObjectFileELF : public lldb_private::ObjectFile {
   lldb::SectionType GetSectionType(const ELFSectionHeaderInfo &H) const;
 
   static void ParseARMAttributes(lldb_private::DataExtractor &data,
-                                 uint64_t length,
                                  lldb_private::ArchSpec &arch_spec);
 
+  /// Read the section contents for a given section header.
+  ///
+  /// Section contents are available in the ELF file data if we have all of the
+  /// data mapped into \a object_data.
+  ///
+  /// \param[in] sh
+  ///    The section header of the section we want to read.
+  ///
+  /// \param[in] object_data
+  ///    The object data that contains all of the contiguous bytes which starts
+  ///    with the ELF header and also contains the program headers. This data
+  ///    will contain the full ELF file if the ELF file is read from disk. If
+  ///    the ELF file is read from memory, then it might only contain the ELF
+  ///    header and program header data.
+  ///
+  /// \param[out] section_data
+  ///    The section data to fill in if we are able to read the section contents
+  ///    completely.
+  ///
+  /// \return True if we are able to read all of the section data from
+  ///    \a object_data. False otherwise.
+  static bool GetSectionContentsFromELFData(
+    const elf::ELFSectionHeader &sh,
+    const lldb_private::DataExtractor &object_data,
+    lldb_private::DataExtractor &section_data);
+
+  /// Callback that can be used to read the data for a section.
+  ///
+  /// \return True if the section has a size and all bytes can be read,
+  ///         False otherwise.
+  using ReadSectionDataCallback =
+  std::function<bool(const elf::ELFSectionHeader &sh,
----------------
labath wrote:

```suggestion
  llvm::function_ref<bool(const elf::ELFSectionHeader &sh,
```

(also, since it's used in just a single place, I might not bother with typedefing this)

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


More information about the lldb-commits mailing list