1 //===-- ObjectFileELF.h --------------------------------------- -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ObjectFileELF_h_
11 #define liblldb_ObjectFileELF_h_
16 #include "lldb/lldb-private.h"
17 #include "lldb/Host/FileSpec.h"
18 #include "lldb/Symbol/ObjectFile.h"
19 #include "lldb/Core/UUID.h"
21 #include "ELFHeader.h"
23 //------------------------------------------------------------------------------
24 /// @class ObjectFileELF
25 /// @brief Generic ELF object file reader.
27 /// This class provides a generic ELF (32/64 bit) reader plugin implementing the
28 /// ObjectFile protocol.
30 public lldb_private::ObjectFile
33 //------------------------------------------------------------------
35 //------------------------------------------------------------------
42 static lldb_private::ConstString
43 GetPluginNameStatic();
46 GetPluginDescriptionStatic();
48 static lldb_private::ObjectFile *
49 CreateInstance(const lldb::ModuleSP &module_sp,
50 lldb::DataBufferSP& data_sp,
51 lldb::offset_t data_offset,
52 const lldb_private::FileSpec* file,
53 lldb::offset_t file_offset,
54 lldb::offset_t length);
56 static lldb_private::ObjectFile *
57 CreateMemoryInstance (const lldb::ModuleSP &module_sp,
58 lldb::DataBufferSP& data_sp,
59 const lldb::ProcessSP &process_sp,
60 lldb::addr_t header_addr);
63 GetModuleSpecifications (const lldb_private::FileSpec& file,
64 lldb::DataBufferSP& data_sp,
65 lldb::offset_t data_offset,
66 lldb::offset_t file_offset,
67 lldb::offset_t length,
68 lldb_private::ModuleSpecList &specs);
71 MagicBytesMatch (lldb::DataBufferSP& data_sp,
75 //------------------------------------------------------------------
76 // PluginInterface protocol
77 //------------------------------------------------------------------
78 virtual lldb_private::ConstString
84 //------------------------------------------------------------------
85 // ObjectFile Protocol.
86 //------------------------------------------------------------------
93 virtual lldb::ByteOrder
97 IsExecutable () const;
100 GetAddressByteSize() const;
102 virtual lldb_private::Symtab *
109 CreateSections (lldb_private::SectionList &unified_section_list);
112 Dump(lldb_private::Stream *s);
115 GetArchitecture (lldb_private::ArchSpec &arch);
118 GetUUID(lldb_private::UUID* uuid);
120 virtual lldb_private::FileSpecList
121 GetDebugSymbolFilePaths();
124 GetDependentModules(lldb_private::FileSpecList& files);
126 virtual lldb_private::Address
127 GetImageInfoAddress();
129 virtual lldb_private::Address
130 GetEntryPointAddress ();
132 virtual ObjectFile::Type
135 virtual ObjectFile::Strata
138 // Returns number of program headers found in the ELF file.
140 GetProgramHeaderCount();
142 // Returns the program header with the given index.
143 const elf::ELFProgramHeader *
144 GetProgramHeaderByIndex(lldb::user_id_t id);
146 // Returns segment data for the given index.
147 lldb_private::DataExtractor
148 GetSegmentDataByIndex(lldb::user_id_t id);
151 ObjectFileELF(const lldb::ModuleSP &module_sp,
152 lldb::DataBufferSP& data_sp,
153 lldb::offset_t data_offset,
154 const lldb_private::FileSpec* file,
155 lldb::offset_t offset,
156 lldb::offset_t length);
158 typedef std::vector<elf::ELFProgramHeader> ProgramHeaderColl;
159 typedef ProgramHeaderColl::iterator ProgramHeaderCollIter;
160 typedef ProgramHeaderColl::const_iterator ProgramHeaderCollConstIter;
162 struct ELFSectionHeaderInfo : public elf::ELFSectionHeader
164 lldb_private::ConstString section_name;
166 typedef std::vector<ELFSectionHeaderInfo> SectionHeaderColl;
167 typedef SectionHeaderColl::iterator SectionHeaderCollIter;
168 typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;
170 typedef std::vector<elf::ELFDynamic> DynamicSymbolColl;
171 typedef DynamicSymbolColl::iterator DynamicSymbolCollIter;
172 typedef DynamicSymbolColl::const_iterator DynamicSymbolCollConstIter;
174 /// Version of this reader common to all plugins based on this class.
175 static const uint32_t m_plugin_version = 1;
178 elf::ELFHeader m_header;
181 lldb_private::UUID m_uuid;
183 /// ELF .gnu_debuglink file and crc data if available.
184 std::string m_gnu_debuglink_file;
185 uint32_t m_gnu_debuglink_crc;
187 /// Collection of program headers.
188 ProgramHeaderColl m_program_headers;
190 /// Collection of section headers.
191 SectionHeaderColl m_section_headers;
193 /// Collection of symbols from the dynamic table.
194 DynamicSymbolColl m_dynamic_symbols;
196 /// List of file specifications corresponding to the modules (shared
197 /// libraries) on which this object file depends.
198 mutable std::unique_ptr<lldb_private::FileSpecList> m_filespec_ap;
200 /// Cached value of the entry point for this module.
201 lldb_private::Address m_entry_point_address;
203 /// Returns a 1 based index of the given section header.
205 SectionIndex(const SectionHeaderCollIter &I);
207 /// Returns a 1 based index of the given section header.
209 SectionIndex(const SectionHeaderCollConstIter &I) const;
211 /// Parses all section headers present in this object file and populates
212 /// m_program_headers. This method will compute the header list only once.
213 /// Returns the number of headers parsed.
215 ParseProgramHeaders();
217 /// Parses all section headers present in this object file and populates
218 /// m_section_headers. This method will compute the header list only once.
219 /// Returns the number of headers parsed.
221 ParseSectionHeaders();
223 /// Parses the elf section headers and returns the uuid, debug link name, crc.
225 GetSectionHeaderInfo(SectionHeaderColl §ion_headers,
226 lldb_private::DataExtractor &data,
227 const elf::ELFHeader &header,
228 lldb_private::UUID &uuid,
229 std::string &gnu_debuglink_file,
230 uint32_t &gnu_debuglink_crc);
232 /// Scans the dynamic section and locates all dependent modules (shared
233 /// libraries) populating m_filespec_ap. This method will compute the
234 /// dependent module list only once. Returns the number of dependent
237 ParseDependentModules();
239 /// Parses the dynamic symbol table and populates m_dynamic_symbols. The
240 /// vector retains the order as found in the object file. Returns the
241 /// number of dynamic symbols parsed.
243 ParseDynamicSymbols();
245 /// Populates m_symtab_ap will all non-dynamic linker symbols. This method
246 /// will parse the symbols only once. Returns the number of symbols parsed.
248 ParseSymbolTable(lldb_private::Symtab *symbol_table,
249 lldb::user_id_t start_id,
250 lldb_private::Section *symtab);
252 /// Helper routine for ParseSymbolTable().
254 ParseSymbols(lldb_private::Symtab *symbol_table,
255 lldb::user_id_t start_id,
256 lldb_private::SectionList *section_list,
257 const size_t num_symbols,
258 const lldb_private::DataExtractor &symtab_data,
259 const lldb_private::DataExtractor &strtab_data);
261 /// Scans the relocation entries and adds a set of artificial symbols to the
262 /// given symbol table for each PLT slot. Returns the number of symbols
265 ParseTrampolineSymbols(lldb_private::Symtab *symbol_table,
266 lldb::user_id_t start_id,
267 const ELFSectionHeaderInfo *rela_hdr,
268 lldb::user_id_t section_id);
270 /// Returns the section header with the given id or NULL.
271 const ELFSectionHeaderInfo *
272 GetSectionHeaderByIndex(lldb::user_id_t id);
274 /// @name ELF header dump routines
277 DumpELFHeader(lldb_private::Stream *s, const elf::ELFHeader& header);
280 DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s,
281 unsigned char ei_data);
284 DumpELFHeader_e_type(lldb_private::Stream *s, elf::elf_half e_type);
287 /// @name ELF program header dump routines
290 DumpELFProgramHeaders(lldb_private::Stream *s);
293 DumpELFProgramHeader(lldb_private::Stream *s,
294 const elf::ELFProgramHeader &ph);
297 DumpELFProgramHeader_p_type(lldb_private::Stream *s, elf::elf_word p_type);
300 DumpELFProgramHeader_p_flags(lldb_private::Stream *s,
301 elf::elf_word p_flags);
304 /// @name ELF section header dump routines
307 DumpELFSectionHeaders(lldb_private::Stream *s);
310 DumpELFSectionHeader(lldb_private::Stream *s,
311 const ELFSectionHeaderInfo& sh);
314 DumpELFSectionHeader_sh_type(lldb_private::Stream *s,
315 elf::elf_word sh_type);
318 DumpELFSectionHeader_sh_flags(lldb_private::Stream *s,
319 elf::elf_xword sh_flags);
322 /// ELF dependent module dump routine.
324 DumpDependentModules(lldb_private::Stream *s);
326 const elf::ELFDynamic *
327 FindDynamicSymbol(unsigned tag);
333 #endif // #ifndef liblldb_ObjectFileELF_h_