xref: /src/contrib/llvm-project/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1f034231aSEd Maste //===-- ObjectFileELF.h --------------------------------------- -*- C++ -*-===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
9cfca06d7SDimitry Andric #ifndef LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H
10cfca06d7SDimitry Andric #define LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H
11f034231aSEd Maste 
12344a3780SDimitry Andric #include <cstdint>
13e81d9d49SDimitry Andric 
14e3b55780SDimitry Andric #include <optional>
15f034231aSEd Maste #include <vector>
16f034231aSEd Maste 
17f034231aSEd Maste #include "lldb/Symbol/ObjectFile.h"
18ef5d0b5eSDimitry Andric #include "lldb/Utility/ArchSpec.h"
1974a628f7SDimitry Andric #include "lldb/Utility/FileSpec.h"
2074a628f7SDimitry Andric #include "lldb/Utility/UUID.h"
2114f1b3e8SDimitry Andric #include "lldb/lldb-private.h"
22f034231aSEd Maste 
23f034231aSEd Maste #include "ELFHeader.h"
24f034231aSEd Maste 
2514f1b3e8SDimitry Andric struct ELFNote {
26344a3780SDimitry Andric   elf::elf_word n_namesz = 0;
27344a3780SDimitry Andric   elf::elf_word n_descsz = 0;
28344a3780SDimitry Andric   elf::elf_word n_type = 0;
2986758c71SEd Maste 
3086758c71SEd Maste   std::string n_name;
3186758c71SEd Maste 
32344a3780SDimitry Andric   ELFNote() = default;
3386758c71SEd Maste 
3486758c71SEd Maste   /// Parse an ELFNote entry from the given DataExtractor starting at position
3586758c71SEd Maste   /// \p offset.
3686758c71SEd Maste   ///
375f29bb8aSDimitry Andric   /// \param[in] data
3886758c71SEd Maste   ///    The DataExtractor to read from.
3986758c71SEd Maste   ///
405f29bb8aSDimitry Andric   /// \param[in,out] offset
4186758c71SEd Maste   ///    Pointer to an offset in the data.  On return the offset will be
4286758c71SEd Maste   ///    advanced by the number of bytes read.
4386758c71SEd Maste   ///
445f29bb8aSDimitry Andric   /// \return
4586758c71SEd Maste   ///    True if the ELFRel entry was successfully read and false otherwise.
4614f1b3e8SDimitry Andric   bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
47e81d9d49SDimitry Andric 
GetByteSizeELFNote4814f1b3e8SDimitry Andric   size_t GetByteSize() const {
49f3fbd1c0SDimitry Andric     return 12 + llvm::alignTo(n_namesz, 4) + llvm::alignTo(n_descsz, 4);
50e81d9d49SDimitry Andric   }
5186758c71SEd Maste };
5286758c71SEd Maste 
535f29bb8aSDimitry Andric /// \class ObjectFileELF
54f73363f1SDimitry Andric /// Generic ELF object file reader.
55f034231aSEd Maste ///
56f73363f1SDimitry Andric /// This class provides a generic ELF (32/64 bit) reader plugin implementing
57f73363f1SDimitry Andric /// the ObjectFile protocol.
5814f1b3e8SDimitry Andric class ObjectFileELF : public lldb_private::ObjectFile {
59f034231aSEd Maste public:
60f034231aSEd Maste   // Static Functions
6114f1b3e8SDimitry Andric   static void Initialize();
62f034231aSEd Maste 
6314f1b3e8SDimitry Andric   static void Terminate();
64f034231aSEd Maste 
GetPluginNameStatic()65c0981da4SDimitry Andric   static llvm::StringRef GetPluginNameStatic() { return "elf"; }
66f034231aSEd Maste 
GetPluginDescriptionStatic()67c0981da4SDimitry Andric   static llvm::StringRef GetPluginDescriptionStatic() {
68c0981da4SDimitry Andric     return "ELF object file reader.";
69c0981da4SDimitry Andric   }
70f034231aSEd Maste 
71f034231aSEd Maste   static lldb_private::ObjectFile *
72145449b1SDimitry Andric   CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
7314f1b3e8SDimitry Andric                  lldb::offset_t data_offset, const lldb_private::FileSpec *file,
7414f1b3e8SDimitry Andric                  lldb::offset_t file_offset, lldb::offset_t length);
75f034231aSEd Maste 
7614f1b3e8SDimitry Andric   static lldb_private::ObjectFile *CreateMemoryInstance(
77145449b1SDimitry Andric       const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
7814f1b3e8SDimitry Andric       const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
79f034231aSEd Maste 
8014f1b3e8SDimitry Andric   static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
81f034231aSEd Maste                                         lldb::DataBufferSP &data_sp,
82f034231aSEd Maste                                         lldb::offset_t data_offset,
83f034231aSEd Maste                                         lldb::offset_t file_offset,
84f034231aSEd Maste                                         lldb::offset_t length,
85f034231aSEd Maste                                         lldb_private::ModuleSpecList &specs);
86f034231aSEd Maste 
8714f1b3e8SDimitry Andric   static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset,
88f034231aSEd Maste                               lldb::addr_t length);
89f034231aSEd Maste 
90f034231aSEd Maste   // PluginInterface protocol
GetPluginName()91c0981da4SDimitry Andric   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
92f034231aSEd Maste 
93ead24645SDimitry Andric   // LLVM RTTI support
94ead24645SDimitry Andric   static char ID;
isA(const void * ClassID)95ead24645SDimitry Andric   bool isA(const void *ClassID) const override {
96ead24645SDimitry Andric     return ClassID == &ID || ObjectFile::isA(ClassID);
97ead24645SDimitry Andric   }
classof(const ObjectFile * obj)98ead24645SDimitry Andric   static bool classof(const ObjectFile *obj) { return obj->isA(&ID); }
99ead24645SDimitry Andric 
100f034231aSEd Maste   // ObjectFile Protocol.
10114f1b3e8SDimitry Andric   bool ParseHeader() override;
102f034231aSEd Maste 
10314f1b3e8SDimitry Andric   bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value,
1045e95aa85SEd Maste                       bool value_is_offset) override;
105866dcdacSEd Maste 
10614f1b3e8SDimitry Andric   lldb::ByteOrder GetByteOrder() const override;
107f034231aSEd Maste 
10814f1b3e8SDimitry Andric   bool IsExecutable() const override;
109f034231aSEd Maste 
11014f1b3e8SDimitry Andric   uint32_t GetAddressByteSize() const override;
111f034231aSEd Maste 
112f73363f1SDimitry Andric   lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override;
113205afe67SEd Maste 
114f65dcba8SDimitry Andric   void ParseSymtab(lldb_private::Symtab &symtab) override;
115f034231aSEd Maste 
11614f1b3e8SDimitry Andric   bool IsStripped() override;
117f034231aSEd Maste 
11814f1b3e8SDimitry Andric   void CreateSections(lldb_private::SectionList &unified_section_list) override;
119f034231aSEd Maste 
12014f1b3e8SDimitry Andric   void Dump(lldb_private::Stream *s) override;
121f034231aSEd Maste 
12294994d37SDimitry Andric   lldb_private::ArchSpec GetArchitecture() override;
123f034231aSEd Maste 
1245f29bb8aSDimitry Andric   lldb_private::UUID GetUUID() override;
125f034231aSEd Maste 
126ead24645SDimitry Andric   /// Return the contents of the .gnu_debuglink section, if the object file
127ead24645SDimitry Andric   /// contains it.
128e3b55780SDimitry Andric   std::optional<lldb_private::FileSpec> GetDebugLink();
129f034231aSEd Maste 
13014f1b3e8SDimitry Andric   uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
131f034231aSEd Maste 
1325e95aa85SEd Maste   lldb_private::Address
1335e95aa85SEd Maste   GetImageInfoAddress(lldb_private::Target *target) override;
134f034231aSEd Maste 
13514f1b3e8SDimitry Andric   lldb_private::Address GetEntryPointAddress() override;
136f034231aSEd Maste 
13794994d37SDimitry Andric   lldb_private::Address GetBaseAddress() override;
13894994d37SDimitry Andric 
13914f1b3e8SDimitry Andric   ObjectFile::Type CalculateType() override;
140f034231aSEd Maste 
14114f1b3e8SDimitry Andric   ObjectFile::Strata CalculateStrata() override;
142f034231aSEd Maste 
143ef5d0b5eSDimitry Andric   size_t ReadSectionData(lldb_private::Section *section,
144ef5d0b5eSDimitry Andric                          lldb::offset_t section_offset, void *dst,
145ef5d0b5eSDimitry Andric                          size_t dst_len) override;
146ef5d0b5eSDimitry Andric 
147ef5d0b5eSDimitry Andric   size_t ReadSectionData(lldb_private::Section *section,
148ef5d0b5eSDimitry Andric                          lldb_private::DataExtractor &section_data) override;
149ef5d0b5eSDimitry Andric 
15094994d37SDimitry Andric   llvm::ArrayRef<elf::ELFProgramHeader> ProgramHeaders();
15194994d37SDimitry Andric   lldb_private::DataExtractor GetSegmentData(const elf::ELFProgramHeader &H);
152f034231aSEd Maste 
153773dd0e6SDimitry Andric   llvm::StringRef
1545e95aa85SEd Maste   StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const override;
1555e95aa85SEd Maste 
156ef5d0b5eSDimitry Andric   void RelocateSection(lldb_private::Section *section) override;
157ef5d0b5eSDimitry Andric 
158f73363f1SDimitry Andric protected:
159f73363f1SDimitry Andric 
160f73363f1SDimitry Andric   std::vector<LoadableData>
161f73363f1SDimitry Andric   GetLoadableData(lldb_private::Target &target) override;
162f73363f1SDimitry Andric 
163145449b1SDimitry Andric   static lldb::WritableDataBufferSP
164145449b1SDimitry Andric   MapFileDataWritable(const lldb_private::FileSpec &file, uint64_t Size,
165145449b1SDimitry Andric                       uint64_t Offset);
166145449b1SDimitry Andric 
167f034231aSEd Maste private:
168145449b1SDimitry Andric   ObjectFileELF(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
16914f1b3e8SDimitry Andric                 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
17014f1b3e8SDimitry Andric                 lldb::offset_t offset, lldb::offset_t length);
171f034231aSEd Maste 
1720cac4ca3SEd Maste   ObjectFileELF(const lldb::ModuleSP &module_sp,
173145449b1SDimitry Andric                 lldb::DataBufferSP header_data_sp,
17414f1b3e8SDimitry Andric                 const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
1750cac4ca3SEd Maste 
176f034231aSEd Maste   typedef std::vector<elf::ELFProgramHeader> ProgramHeaderColl;
177f034231aSEd Maste 
17814f1b3e8SDimitry Andric   struct ELFSectionHeaderInfo : public elf::ELFSectionHeader {
179f034231aSEd Maste     lldb_private::ConstString section_name;
180f034231aSEd Maste   };
181e81d9d49SDimitry Andric 
182f034231aSEd Maste   typedef std::vector<ELFSectionHeaderInfo> SectionHeaderColl;
183f034231aSEd Maste   typedef SectionHeaderColl::iterator SectionHeaderCollIter;
184f034231aSEd Maste   typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;
185f034231aSEd Maste 
186f034231aSEd Maste   typedef std::vector<elf::ELFDynamic> DynamicSymbolColl;
187f034231aSEd Maste   typedef DynamicSymbolColl::iterator DynamicSymbolCollIter;
188f034231aSEd Maste   typedef DynamicSymbolColl::const_iterator DynamicSymbolCollConstIter;
189f034231aSEd Maste 
190ac9a064cSDimitry Andric   /// An ordered map of file address to address class. Used on architectures
191ac9a064cSDimitry Andric   /// like Arm where there is an alternative ISA mode like Thumb. The container
192ac9a064cSDimitry Andric   /// is ordered so that it can be binary searched.
193f73363f1SDimitry Andric   typedef std::map<lldb::addr_t, lldb_private::AddressClass>
19414f1b3e8SDimitry Andric       FileAddressToAddressClassMap;
1955e95aa85SEd Maste 
196f034231aSEd Maste   /// Version of this reader common to all plugins based on this class.
197f034231aSEd Maste   static const uint32_t m_plugin_version = 1;
1980cac4ca3SEd Maste   static const uint32_t g_core_uuid_magic;
199f034231aSEd Maste 
200f034231aSEd Maste   /// ELF file header.
201f034231aSEd Maste   elf::ELFHeader m_header;
202f034231aSEd Maste 
203f034231aSEd Maste   /// ELF build ID.
204f034231aSEd Maste   lldb_private::UUID m_uuid;
205f034231aSEd Maste 
206f034231aSEd Maste   /// ELF .gnu_debuglink file and crc data if available.
207f034231aSEd Maste   std::string m_gnu_debuglink_file;
208ead24645SDimitry Andric   uint32_t m_gnu_debuglink_crc = 0;
209f034231aSEd Maste 
210f034231aSEd Maste   /// Collection of program headers.
211f034231aSEd Maste   ProgramHeaderColl m_program_headers;
212f034231aSEd Maste 
213f034231aSEd Maste   /// Collection of section headers.
214f034231aSEd Maste   SectionHeaderColl m_section_headers;
215f034231aSEd Maste 
216f034231aSEd Maste   /// Collection of symbols from the dynamic table.
217f034231aSEd Maste   DynamicSymbolColl m_dynamic_symbols;
218f034231aSEd Maste 
219ead24645SDimitry Andric   /// Object file parsed from .gnu_debugdata section (\sa
220ead24645SDimitry Andric   /// GetGnuDebugDataObjectFile())
221ead24645SDimitry Andric   std::shared_ptr<ObjectFileELF> m_gnu_debug_data_object_file;
222ead24645SDimitry Andric 
223f034231aSEd Maste   /// List of file specifications corresponding to the modules (shared
224f034231aSEd Maste   /// libraries) on which this object file depends.
2255f29bb8aSDimitry Andric   mutable std::unique_ptr<lldb_private::FileSpecList> m_filespec_up;
226f034231aSEd Maste 
227f034231aSEd Maste   /// Cached value of the entry point for this module.
228f034231aSEd Maste   lldb_private::Address m_entry_point_address;
229f034231aSEd Maste 
2300cac4ca3SEd Maste   /// The architecture detected from parsing elf file contents.
2310cac4ca3SEd Maste   lldb_private::ArchSpec m_arch_spec;
2320cac4ca3SEd Maste 
2335e95aa85SEd Maste   /// The address class for each symbol in the elf file
2345e95aa85SEd Maste   FileAddressToAddressClassMap m_address_class_map;
2355e95aa85SEd Maste 
23694994d37SDimitry Andric   /// Returns the index of the given section header.
23714f1b3e8SDimitry Andric   size_t SectionIndex(const SectionHeaderCollIter &I);
238f034231aSEd Maste 
23994994d37SDimitry Andric   /// Returns the index of the given section header.
24014f1b3e8SDimitry Andric   size_t SectionIndex(const SectionHeaderCollConstIter &I) const;
241f034231aSEd Maste 
2420cac4ca3SEd Maste   // Parses the ELF program headers.
24314f1b3e8SDimitry Andric   static size_t GetProgramHeaderInfo(ProgramHeaderColl &program_headers,
244fdea456aSDimitry Andric                                      lldb_private::DataExtractor &object_data,
2450cac4ca3SEd Maste                                      const elf::ELFHeader &header);
2460cac4ca3SEd Maste 
2470cac4ca3SEd Maste   // Finds PT_NOTE segments and calculates their crc sum.
2480cac4ca3SEd Maste   static uint32_t
2490cac4ca3SEd Maste   CalculateELFNotesSegmentsCRC32(const ProgramHeaderColl &program_headers,
2500cac4ca3SEd Maste                                  lldb_private::DataExtractor &data);
2510cac4ca3SEd Maste 
252f034231aSEd Maste   /// Parses all section headers present in this object file and populates
253f034231aSEd Maste   /// m_program_headers.  This method will compute the header list only once.
25494994d37SDimitry Andric   /// Returns true iff the headers have been successfully parsed.
25594994d37SDimitry Andric   bool ParseProgramHeaders();
256f034231aSEd Maste 
257f034231aSEd Maste   /// Parses all section headers present in this object file and populates
258f034231aSEd Maste   /// m_section_headers.  This method will compute the header list only once.
259f034231aSEd Maste   /// Returns the number of headers parsed.
26014f1b3e8SDimitry Andric   size_t ParseSectionHeaders();
261f034231aSEd Maste 
26294994d37SDimitry Andric   lldb::SectionType GetSectionType(const ELFSectionHeaderInfo &H) const;
26394994d37SDimitry Andric 
26414f1b3e8SDimitry Andric   static void ParseARMAttributes(lldb_private::DataExtractor &data,
26514f1b3e8SDimitry Andric                                  uint64_t length,
266f3fbd1c0SDimitry Andric                                  lldb_private::ArchSpec &arch_spec);
267f3fbd1c0SDimitry Andric 
268f73363f1SDimitry Andric   /// Parses the elf section headers and returns the uuid, debug link name,
269f73363f1SDimitry Andric   /// crc, archspec.
27014f1b3e8SDimitry Andric   static size_t GetSectionHeaderInfo(SectionHeaderColl &section_headers,
271fdea456aSDimitry Andric                                      lldb_private::DataExtractor &object_data,
272f034231aSEd Maste                                      const elf::ELFHeader &header,
273f034231aSEd Maste                                      lldb_private::UUID &uuid,
274f034231aSEd Maste                                      std::string &gnu_debuglink_file,
2750cac4ca3SEd Maste                                      uint32_t &gnu_debuglink_crc,
2760cac4ca3SEd Maste                                      lldb_private::ArchSpec &arch_spec);
277f034231aSEd Maste 
278f034231aSEd Maste   /// Scans the dynamic section and locates all dependent modules (shared
2795f29bb8aSDimitry Andric   /// libraries) populating m_filespec_up.  This method will compute the
280f034231aSEd Maste   /// dependent module list only once.  Returns the number of dependent
281f034231aSEd Maste   /// modules parsed.
28214f1b3e8SDimitry Andric   size_t ParseDependentModules();
283f034231aSEd Maste 
284f034231aSEd Maste   /// Parses the dynamic symbol table and populates m_dynamic_symbols.  The
285f034231aSEd Maste   /// vector retains the order as found in the object file.  Returns the
286f034231aSEd Maste   /// number of dynamic symbols parsed.
28714f1b3e8SDimitry Andric   size_t ParseDynamicSymbols();
288f034231aSEd Maste 
289f65dcba8SDimitry Andric   /// Populates the symbol table with all non-dynamic linker symbols.  This
290f65dcba8SDimitry Andric   /// method will parse the symbols only once.  Returns the number of symbols
291ac9a064cSDimitry Andric   /// parsed and a map of address types (used by targets like Arm that have
292ac9a064cSDimitry Andric   /// an alternative ISA mode like Thumb).
293ac9a064cSDimitry Andric   std::pair<unsigned, FileAddressToAddressClassMap>
294ac9a064cSDimitry Andric   ParseSymbolTable(lldb_private::Symtab *symbol_table, lldb::user_id_t start_id,
295f034231aSEd Maste                    lldb_private::Section *symtab);
296f034231aSEd Maste 
297f034231aSEd Maste   /// Helper routine for ParseSymbolTable().
298ac9a064cSDimitry Andric   std::pair<unsigned, FileAddressToAddressClassMap>
299ac9a064cSDimitry Andric   ParseSymbols(lldb_private::Symtab *symbol_table, lldb::user_id_t start_id,
300f034231aSEd Maste                lldb_private::SectionList *section_list,
301f034231aSEd Maste                const size_t num_symbols,
302f034231aSEd Maste                const lldb_private::DataExtractor &symtab_data,
303f034231aSEd Maste                const lldb_private::DataExtractor &strtab_data);
304f034231aSEd Maste 
305f034231aSEd Maste   /// Scans the relocation entries and adds a set of artificial symbols to the
306f034231aSEd Maste   /// given symbol table for each PLT slot.  Returns the number of symbols
307f034231aSEd Maste   /// added.
30814f1b3e8SDimitry Andric   unsigned ParseTrampolineSymbols(lldb_private::Symtab *symbol_table,
309f034231aSEd Maste                                   lldb::user_id_t start_id,
310f034231aSEd Maste                                   const ELFSectionHeaderInfo *rela_hdr,
311f034231aSEd Maste                                   lldb::user_id_t section_id);
312f034231aSEd Maste 
31314f1b3e8SDimitry Andric   void ParseUnwindSymbols(lldb_private::Symtab *symbol_table,
314f3fbd1c0SDimitry Andric                           lldb_private::DWARFCallFrameInfo *eh_frame);
315f3fbd1c0SDimitry Andric 
3160cac4ca3SEd Maste   /// Relocates debug sections
31714f1b3e8SDimitry Andric   unsigned RelocateDebugSections(const elf::ELFSectionHeader *rel_hdr,
318ef5d0b5eSDimitry Andric                                  lldb::user_id_t rel_id,
319ef5d0b5eSDimitry Andric                                  lldb_private::Symtab *thetab);
3200cac4ca3SEd Maste 
321ef5d0b5eSDimitry Andric   unsigned ApplyRelocations(lldb_private::Symtab *symtab,
32214f1b3e8SDimitry Andric                             const elf::ELFHeader *hdr,
32314f1b3e8SDimitry Andric                             const elf::ELFSectionHeader *rel_hdr,
32414f1b3e8SDimitry Andric                             const elf::ELFSectionHeader *symtab_hdr,
32514f1b3e8SDimitry Andric                             const elf::ELFSectionHeader *debug_hdr,
32614f1b3e8SDimitry Andric                             lldb_private::DataExtractor &rel_data,
32714f1b3e8SDimitry Andric                             lldb_private::DataExtractor &symtab_data,
32814f1b3e8SDimitry Andric                             lldb_private::DataExtractor &debug_data,
32914f1b3e8SDimitry Andric                             lldb_private::Section *rel_section);
3300cac4ca3SEd Maste 
3310cac4ca3SEd Maste   /// Loads the section name string table into m_shstr_data.  Returns the
3320cac4ca3SEd Maste   /// number of bytes constituting the table.
33314f1b3e8SDimitry Andric   size_t GetSectionHeaderStringTable();
3340cac4ca3SEd Maste 
3350cac4ca3SEd Maste   /// Utility method for looking up a section given its name.  Returns the
3360cac4ca3SEd Maste   /// index of the corresponding section or zero if no section with the given
3370cac4ca3SEd Maste   /// name can be found (note that section indices are always 1 based, and so
3380cac4ca3SEd Maste   /// section index 0 is never valid).
33914f1b3e8SDimitry Andric   lldb::user_id_t GetSectionIndexByName(const char *name);
3400cac4ca3SEd Maste 
341f034231aSEd Maste   /// Returns the section header with the given id or NULL.
34214f1b3e8SDimitry Andric   const ELFSectionHeaderInfo *GetSectionHeaderByIndex(lldb::user_id_t id);
343f034231aSEd Maste 
3445f29bb8aSDimitry Andric   /// \name  ELF header dump routines
345f034231aSEd Maste   //@{
34614f1b3e8SDimitry Andric   static void DumpELFHeader(lldb_private::Stream *s,
34714f1b3e8SDimitry Andric                             const elf::ELFHeader &header);
348f034231aSEd Maste 
34914f1b3e8SDimitry Andric   static void DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s,
350f034231aSEd Maste                                             unsigned char ei_data);
351f034231aSEd Maste 
35214f1b3e8SDimitry Andric   static void DumpELFHeader_e_type(lldb_private::Stream *s,
35314f1b3e8SDimitry Andric                                    elf::elf_half e_type);
354f034231aSEd Maste   //@}
355f034231aSEd Maste 
3565f29bb8aSDimitry Andric   /// \name ELF program header dump routines
357f034231aSEd Maste   //@{
35814f1b3e8SDimitry Andric   void DumpELFProgramHeaders(lldb_private::Stream *s);
359f034231aSEd Maste 
36014f1b3e8SDimitry Andric   static void DumpELFProgramHeader(lldb_private::Stream *s,
361f034231aSEd Maste                                    const elf::ELFProgramHeader &ph);
362f034231aSEd Maste 
36314f1b3e8SDimitry Andric   static void DumpELFProgramHeader_p_type(lldb_private::Stream *s,
36414f1b3e8SDimitry Andric                                           elf::elf_word p_type);
365f034231aSEd Maste 
36614f1b3e8SDimitry Andric   static void DumpELFProgramHeader_p_flags(lldb_private::Stream *s,
367f034231aSEd Maste                                            elf::elf_word p_flags);
368f034231aSEd Maste   //@}
369f034231aSEd Maste 
3705f29bb8aSDimitry Andric   /// \name ELF section header dump routines
371f034231aSEd Maste   //@{
37214f1b3e8SDimitry Andric   void DumpELFSectionHeaders(lldb_private::Stream *s);
373f034231aSEd Maste 
37414f1b3e8SDimitry Andric   static void DumpELFSectionHeader(lldb_private::Stream *s,
375f034231aSEd Maste                                    const ELFSectionHeaderInfo &sh);
376f034231aSEd Maste 
37714f1b3e8SDimitry Andric   static void DumpELFSectionHeader_sh_type(lldb_private::Stream *s,
378f034231aSEd Maste                                            elf::elf_word sh_type);
379f034231aSEd Maste 
38014f1b3e8SDimitry Andric   static void DumpELFSectionHeader_sh_flags(lldb_private::Stream *s,
381f034231aSEd Maste                                             elf::elf_xword sh_flags);
382f034231aSEd Maste   //@}
383f034231aSEd Maste 
384f034231aSEd Maste   /// ELF dependent module dump routine.
38514f1b3e8SDimitry Andric   void DumpDependentModules(lldb_private::Stream *s);
386f034231aSEd Maste 
38714f1b3e8SDimitry Andric   const elf::ELFDynamic *FindDynamicSymbol(unsigned tag);
388f034231aSEd Maste 
38914f1b3e8SDimitry Andric   unsigned PLTRelocationType();
3900cac4ca3SEd Maste 
391b76161e4SDimitry Andric   static lldb_private::Status
39214f1b3e8SDimitry Andric   RefineModuleDetailsFromNote(lldb_private::DataExtractor &data,
39314f1b3e8SDimitry Andric                               lldb_private::ArchSpec &arch_spec,
39414f1b3e8SDimitry Andric                               lldb_private::UUID &uuid);
395f73363f1SDimitry Andric 
396f73363f1SDimitry Andric   bool AnySegmentHasPhysicalAddress();
397ead24645SDimitry Andric 
398ead24645SDimitry Andric   /// Takes the .gnu_debugdata and returns the decompressed object file that is
399ead24645SDimitry Andric   /// stored within that section.
400ead24645SDimitry Andric   ///
401ead24645SDimitry Andric   /// \returns either the decompressed object file stored within the
402ead24645SDimitry Andric   /// .gnu_debugdata section or \c nullptr if an error occured or if there's no
403ead24645SDimitry Andric   /// section with that name.
404ead24645SDimitry Andric   std::shared_ptr<ObjectFileELF> GetGnuDebugDataObjectFile();
405f034231aSEd Maste };
406f034231aSEd Maste 
407cfca06d7SDimitry Andric #endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H
408