Greg Clayton | 596ba27 | 2010-07-07 21:52:01 +0000 | [diff] [blame] | 1 | //===-- ObjectFileELF64.h ------------------------------------- -*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef liblldb_ObjectFileELF64_h_ |
| 11 | #define liblldb_ObjectFileELF64_h_ |
| 12 | |
| 13 | #include <stdint.h> |
| 14 | #include <vector> |
| 15 | |
| 16 | #include "lldb/lldb-private.h" |
| 17 | #include "lldb/Core/FileSpec.h" |
| 18 | #include "lldb/Symbol/ObjectFile.h" |
| 19 | |
| 20 | #include "elf.h" |
| 21 | |
| 22 | //---------------------------------------------------------------------- |
| 23 | // This class needs to be hidden as eventually belongs in a plugin that |
| 24 | // will export the ObjectFile protocol |
| 25 | //---------------------------------------------------------------------- |
| 26 | class ObjectFileELF64 : |
| 27 | public lldb_private::ObjectFile |
| 28 | { |
| 29 | public: |
| 30 | //------------------------------------------------------------------ |
| 31 | // Static Functions |
| 32 | //------------------------------------------------------------------ |
| 33 | static void |
| 34 | Initialize(); |
| 35 | |
| 36 | static void |
| 37 | Terminate(); |
| 38 | |
| 39 | static const char * |
| 40 | GetPluginNameStatic(); |
| 41 | |
| 42 | static const char * |
| 43 | GetPluginDescriptionStatic(); |
| 44 | |
| 45 | static lldb_private::ObjectFile * |
| 46 | CreateInstance(lldb_private::Module* module, |
| 47 | lldb::DataBufferSP& dataSP, |
| 48 | const lldb_private::FileSpec* file, |
| 49 | lldb::addr_t offset, |
| 50 | lldb::addr_t length); |
| 51 | |
| 52 | static bool |
| 53 | MagicBytesMatch(lldb::DataBufferSP& dataSP); |
| 54 | |
| 55 | //------------------------------------------------------------------ |
| 56 | // Member Functions |
| 57 | //------------------------------------------------------------------ |
| 58 | ObjectFileELF64(lldb_private::Module* module, |
| 59 | lldb::DataBufferSP& dataSP, |
| 60 | const lldb_private::FileSpec* file, |
| 61 | lldb::addr_t offset, |
| 62 | lldb::addr_t length); |
| 63 | |
| 64 | virtual |
| 65 | ~ObjectFileELF64(); |
| 66 | |
| 67 | virtual bool |
| 68 | ParseHeader(); |
| 69 | |
| 70 | virtual lldb::ByteOrder |
| 71 | GetByteOrder() const; |
| 72 | |
| 73 | virtual size_t |
| 74 | GetAddressByteSize() const; |
| 75 | |
| 76 | virtual lldb_private::Symtab * |
| 77 | GetSymtab(); |
| 78 | |
| 79 | virtual lldb_private::SectionList * |
| 80 | GetSectionList(); |
| 81 | |
| 82 | virtual void |
| 83 | Dump(lldb_private::Stream *s); |
| 84 | |
| 85 | virtual bool |
| 86 | GetTargetTriple(lldb_private::ConstString &target_triple); |
| 87 | |
| 88 | virtual bool |
| 89 | GetUUID(lldb_private::UUID* uuid); |
| 90 | |
| 91 | virtual uint32_t |
| 92 | GetDependentModules(lldb_private::FileSpecList& files); |
| 93 | |
| 94 | //------------------------------------------------------------------ |
| 95 | // PluginInterface protocol |
| 96 | //------------------------------------------------------------------ |
| 97 | virtual const char * |
| 98 | GetPluginName(); |
| 99 | |
| 100 | virtual const char * |
| 101 | GetShortPluginName(); |
| 102 | |
| 103 | virtual uint32_t |
| 104 | GetPluginVersion(); |
| 105 | |
| 106 | virtual void |
| 107 | GetPluginCommandHelp(const char *command, lldb_private::Stream *strm); |
| 108 | |
| 109 | virtual lldb_private::Error |
| 110 | ExecutePluginCommand(lldb_private::Args &command, |
| 111 | lldb_private::Stream *strm); |
| 112 | |
| 113 | virtual lldb_private::Log * |
| 114 | EnablePluginLogging(lldb_private::Stream *strm, |
| 115 | lldb_private::Args &command); |
| 116 | |
| 117 | protected: |
| 118 | typedef std::vector<Elf64_Phdr> ProgramHeaderColl; |
| 119 | typedef ProgramHeaderColl::iterator ProgramHeaderCollIter; |
| 120 | typedef ProgramHeaderColl::const_iterator ProgramHeaderCollConstIter; |
| 121 | |
| 122 | typedef std::vector<Elf64_Shdr> SectionHeaderColl; |
| 123 | typedef SectionHeaderColl::iterator SectionHeaderCollIter; |
| 124 | typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter; |
| 125 | |
| 126 | Elf64_Ehdr m_header; |
| 127 | ProgramHeaderColl m_program_headers; |
| 128 | SectionHeaderColl m_section_headers; |
| 129 | mutable std::auto_ptr<lldb_private::SectionList> m_sections_ap; |
| 130 | mutable std::auto_ptr<lldb_private::Symtab> m_symtab_ap; |
| 131 | mutable std::auto_ptr<lldb_private::FileSpecList> m_filespec_ap; |
| 132 | lldb_private::DataExtractor m_shstr_data; |
| 133 | |
| 134 | size_t |
| 135 | ParseSections(); |
| 136 | |
| 137 | size_t |
| 138 | ParseSymtab(bool minimize); |
| 139 | |
| 140 | private: |
| 141 | // Returns the 1 based index of a section header. |
| 142 | unsigned |
| 143 | SectionIndex(const SectionHeaderCollIter &I); |
| 144 | |
| 145 | unsigned |
| 146 | SectionIndex(const SectionHeaderCollConstIter &I) const; |
| 147 | |
| 148 | // ELF header dump routines |
| 149 | static void |
| 150 | DumpELFHeader(lldb_private::Stream *s, const Elf64_Ehdr& header); |
| 151 | |
| 152 | static void |
| 153 | DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s, |
| 154 | unsigned char ei_data); |
| 155 | |
| 156 | static void |
| 157 | DumpELFHeader_e_type(lldb_private::Stream *s, Elf64_Half e_type); |
| 158 | |
| 159 | // ELF program header dump routines |
| 160 | void |
| 161 | DumpELFProgramHeaders(lldb_private::Stream *s); |
| 162 | |
| 163 | static void |
| 164 | DumpELFProgramHeader(lldb_private::Stream *s, const Elf64_Phdr &ph); |
| 165 | |
| 166 | static void |
| 167 | DumpELFProgramHeader_p_type(lldb_private::Stream *s, Elf64_Word p_type); |
| 168 | |
| 169 | static void |
| 170 | DumpELFProgramHeader_p_flags(lldb_private::Stream *s, Elf64_Word p_flags); |
| 171 | |
| 172 | // ELF section header dump routines |
| 173 | void |
| 174 | DumpELFSectionHeaders(lldb_private::Stream *s); |
| 175 | |
| 176 | static void |
| 177 | DumpELFSectionHeader(lldb_private::Stream *s, const Elf64_Shdr& sh); |
| 178 | |
| 179 | static void |
| 180 | DumpELFSectionHeader_sh_type(lldb_private::Stream *s, Elf64_Word sh_type); |
| 181 | |
| 182 | static void |
| 183 | DumpELFSectionHeader_sh_flags(lldb_private::Stream *s, Elf64_Word sh_flags); |
| 184 | |
| 185 | void |
| 186 | DumpDependentModules(lldb_private::Stream *s); |
| 187 | |
| 188 | size_t |
| 189 | ParseProgramHeaders(); |
| 190 | |
| 191 | size_t |
| 192 | ParseSectionHeaders(); |
| 193 | |
| 194 | size_t |
| 195 | ParseDependentModules(); |
| 196 | |
| 197 | void |
| 198 | ParseSymbolTable(lldb_private::Symtab *symbol_table, |
| 199 | const Elf64_Shdr &symtab_section, |
| 200 | lldb::user_id_t symtab_id); |
| 201 | |
| 202 | size_t |
| 203 | GetSectionHeaderStringTable(); |
| 204 | |
| 205 | uint32_t |
| 206 | GetSectionIndexByName(const char *name); |
| 207 | }; |
| 208 | |
| 209 | #endif // #ifndef liblldb_ObjectFileELF64_h_ |