10b57cec5SDimitry Andric //===-- ObjectFileELF.h --------------------------------------- -*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
95ffd83dbSDimitry Andric #ifndef LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H
105ffd83dbSDimitry Andric #define LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H
110b57cec5SDimitry Andric 
12fe6060f1SDimitry Andric #include <cstdint>
130b57cec5SDimitry Andric 
14bdd1243dSDimitry Andric #include <optional>
150b57cec5SDimitry Andric #include <vector>
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric #include "lldb/Symbol/ObjectFile.h"
180b57cec5SDimitry Andric #include "lldb/Utility/ArchSpec.h"
190b57cec5SDimitry Andric #include "lldb/Utility/FileSpec.h"
200b57cec5SDimitry Andric #include "lldb/Utility/UUID.h"
210b57cec5SDimitry Andric #include "lldb/lldb-private.h"
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric #include "ELFHeader.h"
240b57cec5SDimitry Andric 
250b57cec5SDimitry Andric struct ELFNote {
26fe6060f1SDimitry Andric   elf::elf_word n_namesz = 0;
27fe6060f1SDimitry Andric   elf::elf_word n_descsz = 0;
28fe6060f1SDimitry Andric   elf::elf_word n_type = 0;
290b57cec5SDimitry Andric 
300b57cec5SDimitry Andric   std::string n_name;
310b57cec5SDimitry Andric 
32fe6060f1SDimitry Andric   ELFNote() = default;
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric   /// Parse an ELFNote entry from the given DataExtractor starting at position
350b57cec5SDimitry Andric   /// \p offset.
360b57cec5SDimitry Andric   ///
370b57cec5SDimitry Andric   /// \param[in] data
380b57cec5SDimitry Andric   ///    The DataExtractor to read from.
390b57cec5SDimitry Andric   ///
400b57cec5SDimitry Andric   /// \param[in,out] offset
410b57cec5SDimitry Andric   ///    Pointer to an offset in the data.  On return the offset will be
420b57cec5SDimitry Andric   ///    advanced by the number of bytes read.
430b57cec5SDimitry Andric   ///
440b57cec5SDimitry Andric   /// \return
450b57cec5SDimitry Andric   ///    True if the ELFRel entry was successfully read and false otherwise.
460b57cec5SDimitry Andric   bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
470b57cec5SDimitry Andric 
GetByteSizeELFNote480b57cec5SDimitry Andric   size_t GetByteSize() const {
490b57cec5SDimitry Andric     return 12 + llvm::alignTo(n_namesz, 4) + llvm::alignTo(n_descsz, 4);
500b57cec5SDimitry Andric   }
510b57cec5SDimitry Andric };
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric /// \class ObjectFileELF
540b57cec5SDimitry Andric /// Generic ELF object file reader.
550b57cec5SDimitry Andric ///
560b57cec5SDimitry Andric /// This class provides a generic ELF (32/64 bit) reader plugin implementing
570b57cec5SDimitry Andric /// the ObjectFile protocol.
580b57cec5SDimitry Andric class ObjectFileELF : public lldb_private::ObjectFile {
590b57cec5SDimitry Andric public:
600b57cec5SDimitry Andric   // Static Functions
610b57cec5SDimitry Andric   static void Initialize();
620b57cec5SDimitry Andric 
630b57cec5SDimitry Andric   static void Terminate();
640b57cec5SDimitry Andric 
GetPluginNameStatic()65349cc55cSDimitry Andric   static llvm::StringRef GetPluginNameStatic() { return "elf"; }
660b57cec5SDimitry Andric 
GetPluginDescriptionStatic()67349cc55cSDimitry Andric   static llvm::StringRef GetPluginDescriptionStatic() {
68349cc55cSDimitry Andric     return "ELF object file reader.";
69349cc55cSDimitry Andric   }
700b57cec5SDimitry Andric 
710b57cec5SDimitry Andric   static lldb_private::ObjectFile *
7281ad6265SDimitry Andric   CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
730b57cec5SDimitry Andric                  lldb::offset_t data_offset, const lldb_private::FileSpec *file,
740b57cec5SDimitry Andric                  lldb::offset_t file_offset, lldb::offset_t length);
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric   static lldb_private::ObjectFile *CreateMemoryInstance(
7781ad6265SDimitry Andric       const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
780b57cec5SDimitry Andric       const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
790b57cec5SDimitry Andric 
800b57cec5SDimitry Andric   static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
810b57cec5SDimitry Andric                                         lldb::DataBufferSP &data_sp,
820b57cec5SDimitry Andric                                         lldb::offset_t data_offset,
830b57cec5SDimitry Andric                                         lldb::offset_t file_offset,
840b57cec5SDimitry Andric                                         lldb::offset_t length,
850b57cec5SDimitry Andric                                         lldb_private::ModuleSpecList &specs);
860b57cec5SDimitry Andric 
870b57cec5SDimitry Andric   static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset,
880b57cec5SDimitry Andric                               lldb::addr_t length);
890b57cec5SDimitry Andric 
900b57cec5SDimitry Andric   // PluginInterface protocol
GetPluginName()91349cc55cSDimitry Andric   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
920b57cec5SDimitry Andric 
939dba64beSDimitry Andric   // LLVM RTTI support
949dba64beSDimitry Andric   static char ID;
isA(const void * ClassID)959dba64beSDimitry Andric   bool isA(const void *ClassID) const override {
969dba64beSDimitry Andric     return ClassID == &ID || ObjectFile::isA(ClassID);
979dba64beSDimitry Andric   }
classof(const ObjectFile * obj)989dba64beSDimitry Andric   static bool classof(const ObjectFile *obj) { return obj->isA(&ID); }
999dba64beSDimitry Andric 
1000b57cec5SDimitry Andric   // ObjectFile Protocol.
1010b57cec5SDimitry Andric   bool ParseHeader() override;
1020b57cec5SDimitry Andric 
1030b57cec5SDimitry Andric   bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value,
1040b57cec5SDimitry Andric                       bool value_is_offset) override;
1050b57cec5SDimitry Andric 
1060b57cec5SDimitry Andric   lldb::ByteOrder GetByteOrder() const override;
1070b57cec5SDimitry Andric 
1080b57cec5SDimitry Andric   bool IsExecutable() const override;
1090b57cec5SDimitry Andric 
1100b57cec5SDimitry Andric   uint32_t GetAddressByteSize() const override;
1110b57cec5SDimitry Andric 
1120b57cec5SDimitry Andric   lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override;
1130b57cec5SDimitry Andric 
1144824e7fdSDimitry Andric   void ParseSymtab(lldb_private::Symtab &symtab) override;
1150b57cec5SDimitry Andric 
1160b57cec5SDimitry Andric   bool IsStripped() override;
1170b57cec5SDimitry Andric 
1180b57cec5SDimitry Andric   void CreateSections(lldb_private::SectionList &unified_section_list) override;
1190b57cec5SDimitry Andric 
1200b57cec5SDimitry Andric   void Dump(lldb_private::Stream *s) override;
1210b57cec5SDimitry Andric 
1220b57cec5SDimitry Andric   lldb_private::ArchSpec GetArchitecture() override;
1230b57cec5SDimitry Andric 
1240b57cec5SDimitry Andric   lldb_private::UUID GetUUID() override;
1250b57cec5SDimitry Andric 
1269dba64beSDimitry Andric   /// Return the contents of the .gnu_debuglink section, if the object file
1279dba64beSDimitry Andric   /// contains it.
128bdd1243dSDimitry Andric   std::optional<lldb_private::FileSpec> GetDebugLink();
1290b57cec5SDimitry Andric 
1300b57cec5SDimitry Andric   uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
1310b57cec5SDimitry Andric 
1320b57cec5SDimitry Andric   lldb_private::Address
1330b57cec5SDimitry Andric   GetImageInfoAddress(lldb_private::Target *target) override;
1340b57cec5SDimitry Andric 
1350b57cec5SDimitry Andric   lldb_private::Address GetEntryPointAddress() override;
1360b57cec5SDimitry Andric 
1370b57cec5SDimitry Andric   lldb_private::Address GetBaseAddress() override;
1380b57cec5SDimitry Andric 
1390b57cec5SDimitry Andric   ObjectFile::Type CalculateType() override;
1400b57cec5SDimitry Andric 
1410b57cec5SDimitry Andric   ObjectFile::Strata CalculateStrata() override;
1420b57cec5SDimitry Andric 
1430b57cec5SDimitry Andric   size_t ReadSectionData(lldb_private::Section *section,
1440b57cec5SDimitry Andric                          lldb::offset_t section_offset, void *dst,
1450b57cec5SDimitry Andric                          size_t dst_len) override;
1460b57cec5SDimitry Andric 
1470b57cec5SDimitry Andric   size_t ReadSectionData(lldb_private::Section *section,
1480b57cec5SDimitry Andric                          lldb_private::DataExtractor &section_data) override;
1490b57cec5SDimitry Andric 
1500b57cec5SDimitry Andric   llvm::ArrayRef<elf::ELFProgramHeader> ProgramHeaders();
1510b57cec5SDimitry Andric   lldb_private::DataExtractor GetSegmentData(const elf::ELFProgramHeader &H);
1520b57cec5SDimitry Andric 
1530b57cec5SDimitry Andric   llvm::StringRef
1540b57cec5SDimitry Andric   StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const override;
1550b57cec5SDimitry Andric 
1560b57cec5SDimitry Andric   void RelocateSection(lldb_private::Section *section) override;
1570b57cec5SDimitry Andric 
1580b57cec5SDimitry Andric protected:
1590b57cec5SDimitry Andric 
1600b57cec5SDimitry Andric   std::vector<LoadableData>
1610b57cec5SDimitry Andric   GetLoadableData(lldb_private::Target &target) override;
1620b57cec5SDimitry Andric 
16381ad6265SDimitry Andric   static lldb::WritableDataBufferSP
16481ad6265SDimitry Andric   MapFileDataWritable(const lldb_private::FileSpec &file, uint64_t Size,
16581ad6265SDimitry Andric                       uint64_t Offset);
16681ad6265SDimitry Andric 
1670b57cec5SDimitry Andric private:
16881ad6265SDimitry Andric   ObjectFileELF(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
1690b57cec5SDimitry Andric                 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
1700b57cec5SDimitry Andric                 lldb::offset_t offset, lldb::offset_t length);
1710b57cec5SDimitry Andric 
1720b57cec5SDimitry Andric   ObjectFileELF(const lldb::ModuleSP &module_sp,
17381ad6265SDimitry Andric                 lldb::DataBufferSP header_data_sp,
1740b57cec5SDimitry Andric                 const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
1750b57cec5SDimitry Andric 
1760b57cec5SDimitry Andric   typedef std::vector<elf::ELFProgramHeader> ProgramHeaderColl;
1770b57cec5SDimitry Andric 
1780b57cec5SDimitry Andric   struct ELFSectionHeaderInfo : public elf::ELFSectionHeader {
1790b57cec5SDimitry Andric     lldb_private::ConstString section_name;
1800b57cec5SDimitry Andric   };
1810b57cec5SDimitry Andric 
1820b57cec5SDimitry Andric   typedef std::vector<ELFSectionHeaderInfo> SectionHeaderColl;
1830b57cec5SDimitry Andric   typedef SectionHeaderColl::iterator SectionHeaderCollIter;
1840b57cec5SDimitry Andric   typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;
1850b57cec5SDimitry Andric 
1860b57cec5SDimitry Andric   typedef std::vector<elf::ELFDynamic> DynamicSymbolColl;
1870b57cec5SDimitry Andric   typedef DynamicSymbolColl::iterator DynamicSymbolCollIter;
1880b57cec5SDimitry Andric   typedef DynamicSymbolColl::const_iterator DynamicSymbolCollConstIter;
1890b57cec5SDimitry Andric 
1900b57cec5SDimitry Andric   typedef std::map<lldb::addr_t, lldb_private::AddressClass>
1910b57cec5SDimitry Andric       FileAddressToAddressClassMap;
1920b57cec5SDimitry Andric 
1930b57cec5SDimitry Andric   /// Version of this reader common to all plugins based on this class.
1940b57cec5SDimitry Andric   static const uint32_t m_plugin_version = 1;
1950b57cec5SDimitry Andric   static const uint32_t g_core_uuid_magic;
1960b57cec5SDimitry Andric 
1970b57cec5SDimitry Andric   /// ELF file header.
1980b57cec5SDimitry Andric   elf::ELFHeader m_header;
1990b57cec5SDimitry Andric 
2000b57cec5SDimitry Andric   /// ELF build ID.
2010b57cec5SDimitry Andric   lldb_private::UUID m_uuid;
2020b57cec5SDimitry Andric 
2030b57cec5SDimitry Andric   /// ELF .gnu_debuglink file and crc data if available.
2040b57cec5SDimitry Andric   std::string m_gnu_debuglink_file;
2059dba64beSDimitry Andric   uint32_t m_gnu_debuglink_crc = 0;
2060b57cec5SDimitry Andric 
2070b57cec5SDimitry Andric   /// Collection of program headers.
2080b57cec5SDimitry Andric   ProgramHeaderColl m_program_headers;
2090b57cec5SDimitry Andric 
2100b57cec5SDimitry Andric   /// Collection of section headers.
2110b57cec5SDimitry Andric   SectionHeaderColl m_section_headers;
2120b57cec5SDimitry Andric 
2130b57cec5SDimitry Andric   /// Collection of symbols from the dynamic table.
2140b57cec5SDimitry Andric   DynamicSymbolColl m_dynamic_symbols;
2150b57cec5SDimitry Andric 
2169dba64beSDimitry Andric   /// Object file parsed from .gnu_debugdata section (\sa
2179dba64beSDimitry Andric   /// GetGnuDebugDataObjectFile())
2189dba64beSDimitry Andric   std::shared_ptr<ObjectFileELF> m_gnu_debug_data_object_file;
2199dba64beSDimitry Andric 
2200b57cec5SDimitry Andric   /// List of file specifications corresponding to the modules (shared
2210b57cec5SDimitry Andric   /// libraries) on which this object file depends.
2220b57cec5SDimitry Andric   mutable std::unique_ptr<lldb_private::FileSpecList> m_filespec_up;
2230b57cec5SDimitry Andric 
2240b57cec5SDimitry Andric   /// Cached value of the entry point for this module.
2250b57cec5SDimitry Andric   lldb_private::Address m_entry_point_address;
2260b57cec5SDimitry Andric 
2270b57cec5SDimitry Andric   /// The architecture detected from parsing elf file contents.
2280b57cec5SDimitry Andric   lldb_private::ArchSpec m_arch_spec;
2290b57cec5SDimitry Andric 
2300b57cec5SDimitry Andric   /// The address class for each symbol in the elf file
2310b57cec5SDimitry Andric   FileAddressToAddressClassMap m_address_class_map;
2320b57cec5SDimitry Andric 
2330b57cec5SDimitry Andric   /// Returns the index of the given section header.
2340b57cec5SDimitry Andric   size_t SectionIndex(const SectionHeaderCollIter &I);
2350b57cec5SDimitry Andric 
2360b57cec5SDimitry Andric   /// Returns the index of the given section header.
2370b57cec5SDimitry Andric   size_t SectionIndex(const SectionHeaderCollConstIter &I) const;
2380b57cec5SDimitry Andric 
2390b57cec5SDimitry Andric   // Parses the ELF program headers.
2400b57cec5SDimitry Andric   static size_t GetProgramHeaderInfo(ProgramHeaderColl &program_headers,
2410b57cec5SDimitry Andric                                      lldb_private::DataExtractor &object_data,
2420b57cec5SDimitry Andric                                      const elf::ELFHeader &header);
2430b57cec5SDimitry Andric 
2440b57cec5SDimitry Andric   // Finds PT_NOTE segments and calculates their crc sum.
2450b57cec5SDimitry Andric   static uint32_t
2460b57cec5SDimitry Andric   CalculateELFNotesSegmentsCRC32(const ProgramHeaderColl &program_headers,
2470b57cec5SDimitry Andric                                  lldb_private::DataExtractor &data);
2480b57cec5SDimitry Andric 
2490b57cec5SDimitry Andric   /// Parses all section headers present in this object file and populates
2500b57cec5SDimitry Andric   /// m_program_headers.  This method will compute the header list only once.
2510b57cec5SDimitry Andric   /// Returns true iff the headers have been successfully parsed.
2520b57cec5SDimitry Andric   bool ParseProgramHeaders();
2530b57cec5SDimitry Andric 
2540b57cec5SDimitry Andric   /// Parses all section headers present in this object file and populates
2550b57cec5SDimitry Andric   /// m_section_headers.  This method will compute the header list only once.
2560b57cec5SDimitry Andric   /// Returns the number of headers parsed.
2570b57cec5SDimitry Andric   size_t ParseSectionHeaders();
2580b57cec5SDimitry Andric 
2590b57cec5SDimitry Andric   lldb::SectionType GetSectionType(const ELFSectionHeaderInfo &H) const;
2600b57cec5SDimitry Andric 
2610b57cec5SDimitry Andric   static void ParseARMAttributes(lldb_private::DataExtractor &data,
2620b57cec5SDimitry Andric                                  uint64_t length,
2630b57cec5SDimitry Andric                                  lldb_private::ArchSpec &arch_spec);
2640b57cec5SDimitry Andric 
2650b57cec5SDimitry Andric   /// Parses the elf section headers and returns the uuid, debug link name,
2660b57cec5SDimitry Andric   /// crc, archspec.
2670b57cec5SDimitry Andric   static size_t GetSectionHeaderInfo(SectionHeaderColl &section_headers,
2680b57cec5SDimitry Andric                                      lldb_private::DataExtractor &object_data,
2690b57cec5SDimitry Andric                                      const elf::ELFHeader &header,
2700b57cec5SDimitry Andric                                      lldb_private::UUID &uuid,
2710b57cec5SDimitry Andric                                      std::string &gnu_debuglink_file,
2720b57cec5SDimitry Andric                                      uint32_t &gnu_debuglink_crc,
2730b57cec5SDimitry Andric                                      lldb_private::ArchSpec &arch_spec);
2740b57cec5SDimitry Andric 
2750b57cec5SDimitry Andric   /// Scans the dynamic section and locates all dependent modules (shared
2760b57cec5SDimitry Andric   /// libraries) populating m_filespec_up.  This method will compute the
2770b57cec5SDimitry Andric   /// dependent module list only once.  Returns the number of dependent
2780b57cec5SDimitry Andric   /// modules parsed.
2790b57cec5SDimitry Andric   size_t ParseDependentModules();
2800b57cec5SDimitry Andric 
2810b57cec5SDimitry Andric   /// Parses the dynamic symbol table and populates m_dynamic_symbols.  The
2820b57cec5SDimitry Andric   /// vector retains the order as found in the object file.  Returns the
2830b57cec5SDimitry Andric   /// number of dynamic symbols parsed.
2840b57cec5SDimitry Andric   size_t ParseDynamicSymbols();
2850b57cec5SDimitry Andric 
2864824e7fdSDimitry Andric   /// Populates the symbol table with all non-dynamic linker symbols.  This
2874824e7fdSDimitry Andric   /// method will parse the symbols only once.  Returns the number of symbols
2884824e7fdSDimitry Andric   /// parsed.
2890b57cec5SDimitry Andric   unsigned ParseSymbolTable(lldb_private::Symtab *symbol_table,
2900b57cec5SDimitry Andric                             lldb::user_id_t start_id,
2910b57cec5SDimitry Andric                             lldb_private::Section *symtab);
2920b57cec5SDimitry Andric 
2930b57cec5SDimitry Andric   /// Helper routine for ParseSymbolTable().
2940b57cec5SDimitry Andric   unsigned ParseSymbols(lldb_private::Symtab *symbol_table,
2950b57cec5SDimitry Andric                         lldb::user_id_t start_id,
2960b57cec5SDimitry Andric                         lldb_private::SectionList *section_list,
2970b57cec5SDimitry Andric                         const size_t num_symbols,
2980b57cec5SDimitry Andric                         const lldb_private::DataExtractor &symtab_data,
2990b57cec5SDimitry Andric                         const lldb_private::DataExtractor &strtab_data);
3000b57cec5SDimitry Andric 
3010b57cec5SDimitry Andric   /// Scans the relocation entries and adds a set of artificial symbols to the
3020b57cec5SDimitry Andric   /// given symbol table for each PLT slot.  Returns the number of symbols
3030b57cec5SDimitry Andric   /// added.
3040b57cec5SDimitry Andric   unsigned ParseTrampolineSymbols(lldb_private::Symtab *symbol_table,
3050b57cec5SDimitry Andric                                   lldb::user_id_t start_id,
3060b57cec5SDimitry Andric                                   const ELFSectionHeaderInfo *rela_hdr,
3070b57cec5SDimitry Andric                                   lldb::user_id_t section_id);
3080b57cec5SDimitry Andric 
3090b57cec5SDimitry Andric   void ParseUnwindSymbols(lldb_private::Symtab *symbol_table,
3100b57cec5SDimitry Andric                           lldb_private::DWARFCallFrameInfo *eh_frame);
3110b57cec5SDimitry Andric 
3120b57cec5SDimitry Andric   /// Relocates debug sections
3130b57cec5SDimitry Andric   unsigned RelocateDebugSections(const elf::ELFSectionHeader *rel_hdr,
3140b57cec5SDimitry Andric                                  lldb::user_id_t rel_id,
3150b57cec5SDimitry Andric                                  lldb_private::Symtab *thetab);
3160b57cec5SDimitry Andric 
3170b57cec5SDimitry Andric   unsigned ApplyRelocations(lldb_private::Symtab *symtab,
3180b57cec5SDimitry Andric                             const elf::ELFHeader *hdr,
3190b57cec5SDimitry Andric                             const elf::ELFSectionHeader *rel_hdr,
3200b57cec5SDimitry Andric                             const elf::ELFSectionHeader *symtab_hdr,
3210b57cec5SDimitry Andric                             const elf::ELFSectionHeader *debug_hdr,
3220b57cec5SDimitry Andric                             lldb_private::DataExtractor &rel_data,
3230b57cec5SDimitry Andric                             lldb_private::DataExtractor &symtab_data,
3240b57cec5SDimitry Andric                             lldb_private::DataExtractor &debug_data,
3250b57cec5SDimitry Andric                             lldb_private::Section *rel_section);
3260b57cec5SDimitry Andric 
3270b57cec5SDimitry Andric   /// Loads the section name string table into m_shstr_data.  Returns the
3280b57cec5SDimitry Andric   /// number of bytes constituting the table.
3290b57cec5SDimitry Andric   size_t GetSectionHeaderStringTable();
3300b57cec5SDimitry Andric 
3310b57cec5SDimitry Andric   /// Utility method for looking up a section given its name.  Returns the
3320b57cec5SDimitry Andric   /// index of the corresponding section or zero if no section with the given
3330b57cec5SDimitry Andric   /// name can be found (note that section indices are always 1 based, and so
3340b57cec5SDimitry Andric   /// section index 0 is never valid).
3350b57cec5SDimitry Andric   lldb::user_id_t GetSectionIndexByName(const char *name);
3360b57cec5SDimitry Andric 
3370b57cec5SDimitry Andric   /// Returns the section header with the given id or NULL.
3380b57cec5SDimitry Andric   const ELFSectionHeaderInfo *GetSectionHeaderByIndex(lldb::user_id_t id);
3390b57cec5SDimitry Andric 
3400b57cec5SDimitry Andric   /// \name  ELF header dump routines
3410b57cec5SDimitry Andric   //@{
3420b57cec5SDimitry Andric   static void DumpELFHeader(lldb_private::Stream *s,
3430b57cec5SDimitry Andric                             const elf::ELFHeader &header);
3440b57cec5SDimitry Andric 
3450b57cec5SDimitry Andric   static void DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s,
3460b57cec5SDimitry Andric                                             unsigned char ei_data);
3470b57cec5SDimitry Andric 
3480b57cec5SDimitry Andric   static void DumpELFHeader_e_type(lldb_private::Stream *s,
3490b57cec5SDimitry Andric                                    elf::elf_half e_type);
3500b57cec5SDimitry Andric   //@}
3510b57cec5SDimitry Andric 
3520b57cec5SDimitry Andric   /// \name ELF program header dump routines
3530b57cec5SDimitry Andric   //@{
3540b57cec5SDimitry Andric   void DumpELFProgramHeaders(lldb_private::Stream *s);
3550b57cec5SDimitry Andric 
3560b57cec5SDimitry Andric   static void DumpELFProgramHeader(lldb_private::Stream *s,
3570b57cec5SDimitry Andric                                    const elf::ELFProgramHeader &ph);
3580b57cec5SDimitry Andric 
3590b57cec5SDimitry Andric   static void DumpELFProgramHeader_p_type(lldb_private::Stream *s,
3600b57cec5SDimitry Andric                                           elf::elf_word p_type);
3610b57cec5SDimitry Andric 
3620b57cec5SDimitry Andric   static void DumpELFProgramHeader_p_flags(lldb_private::Stream *s,
3630b57cec5SDimitry Andric                                            elf::elf_word p_flags);
3640b57cec5SDimitry Andric   //@}
3650b57cec5SDimitry Andric 
3660b57cec5SDimitry Andric   /// \name ELF section header dump routines
3670b57cec5SDimitry Andric   //@{
3680b57cec5SDimitry Andric   void DumpELFSectionHeaders(lldb_private::Stream *s);
3690b57cec5SDimitry Andric 
3700b57cec5SDimitry Andric   static void DumpELFSectionHeader(lldb_private::Stream *s,
3710b57cec5SDimitry Andric                                    const ELFSectionHeaderInfo &sh);
3720b57cec5SDimitry Andric 
3730b57cec5SDimitry Andric   static void DumpELFSectionHeader_sh_type(lldb_private::Stream *s,
3740b57cec5SDimitry Andric                                            elf::elf_word sh_type);
3750b57cec5SDimitry Andric 
3760b57cec5SDimitry Andric   static void DumpELFSectionHeader_sh_flags(lldb_private::Stream *s,
3770b57cec5SDimitry Andric                                             elf::elf_xword sh_flags);
3780b57cec5SDimitry Andric   //@}
3790b57cec5SDimitry Andric 
3800b57cec5SDimitry Andric   /// ELF dependent module dump routine.
3810b57cec5SDimitry Andric   void DumpDependentModules(lldb_private::Stream *s);
3820b57cec5SDimitry Andric 
3830b57cec5SDimitry Andric   const elf::ELFDynamic *FindDynamicSymbol(unsigned tag);
3840b57cec5SDimitry Andric 
3850b57cec5SDimitry Andric   unsigned PLTRelocationType();
3860b57cec5SDimitry Andric 
3870b57cec5SDimitry Andric   static lldb_private::Status
3880b57cec5SDimitry Andric   RefineModuleDetailsFromNote(lldb_private::DataExtractor &data,
3890b57cec5SDimitry Andric                               lldb_private::ArchSpec &arch_spec,
3900b57cec5SDimitry Andric                               lldb_private::UUID &uuid);
3910b57cec5SDimitry Andric 
3920b57cec5SDimitry Andric   bool AnySegmentHasPhysicalAddress();
3939dba64beSDimitry Andric 
3949dba64beSDimitry Andric   /// Takes the .gnu_debugdata and returns the decompressed object file that is
3959dba64beSDimitry Andric   /// stored within that section.
3969dba64beSDimitry Andric   ///
3979dba64beSDimitry Andric   /// \returns either the decompressed object file stored within the
3989dba64beSDimitry Andric   /// .gnu_debugdata section or \c nullptr if an error occured or if there's no
3999dba64beSDimitry Andric   /// section with that name.
4009dba64beSDimitry Andric   std::shared_ptr<ObjectFileELF> GetGnuDebugDataObjectFile();
4010b57cec5SDimitry Andric };
4020b57cec5SDimitry Andric 
4035ffd83dbSDimitry Andric #endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H
404