Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ObjectFileELF.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_ObjectFileELF_h_ |
| 11 | #define liblldb_ObjectFileELF_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 ObjectFileELF : |
| 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 | static bool |
| 52 | MagicBytesMatch (lldb::DataBufferSP& dataSP); |
| 53 | |
| 54 | //------------------------------------------------------------------ |
| 55 | // Member Functions |
| 56 | //------------------------------------------------------------------ |
| 57 | ObjectFileELF (lldb_private::Module* module, |
| 58 | lldb::DataBufferSP& dataSP, |
| 59 | const lldb_private::FileSpec* file, |
| 60 | lldb::addr_t offset, |
| 61 | lldb::addr_t length); |
| 62 | |
| 63 | virtual |
| 64 | ~ObjectFileELF(); |
| 65 | |
| 66 | virtual bool |
| 67 | ParseHeader (); |
| 68 | |
| 69 | virtual lldb::ByteOrder |
| 70 | GetByteOrder () const; |
| 71 | |
| 72 | virtual size_t |
| 73 | GetAddressByteSize () const; |
| 74 | |
| 75 | virtual lldb_private::Symtab * |
| 76 | GetSymtab(); |
| 77 | |
| 78 | virtual lldb_private::SectionList * |
| 79 | GetSectionList(); |
| 80 | |
| 81 | virtual void |
| 82 | Dump (lldb_private::Stream *s); |
| 83 | |
| 84 | virtual bool |
| 85 | GetTargetTriple (lldb_private::ConstString &target_triple); |
| 86 | |
| 87 | virtual bool |
| 88 | GetUUID (lldb_private::UUID* uuid); |
| 89 | |
| 90 | virtual uint32_t |
| 91 | GetDependentModules(lldb_private::FileSpecList& files); |
| 92 | |
| 93 | //------------------------------------------------------------------ |
| 94 | // PluginInterface protocol |
| 95 | //------------------------------------------------------------------ |
| 96 | virtual const char * |
| 97 | GetPluginName(); |
| 98 | |
| 99 | virtual const char * |
| 100 | GetShortPluginName(); |
| 101 | |
| 102 | virtual uint32_t |
| 103 | GetPluginVersion(); |
| 104 | |
| 105 | virtual void |
| 106 | GetPluginCommandHelp (const char *command, lldb_private::Stream *strm); |
| 107 | |
| 108 | virtual lldb_private::Error |
| 109 | ExecutePluginCommand (lldb_private::Args &command, lldb_private::Stream *strm); |
| 110 | |
| 111 | virtual lldb_private::Log * |
| 112 | EnablePluginLogging (lldb_private::Stream *strm, lldb_private::Args &command); |
| 113 | |
| 114 | |
| 115 | |
| 116 | protected: |
| 117 | typedef std::vector<Elf32_Phdr> ProgramHeaderColl; |
| 118 | typedef ProgramHeaderColl::iterator ProgramHeaderCollIter; |
| 119 | typedef ProgramHeaderColl::const_iterator ProgramHeaderCollConstIter; |
| 120 | |
| 121 | typedef std::vector<Elf32_Shdr> SectionHeaderColl; |
| 122 | typedef SectionHeaderColl::iterator SectionHeaderCollIter; |
| 123 | typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter; |
| 124 | |
| 125 | Elf32_Ehdr m_header; |
| 126 | ProgramHeaderColl m_program_headers; |
| 127 | SectionHeaderColl m_section_headers; |
| 128 | mutable std::auto_ptr<lldb_private::SectionList> m_sections_ap; |
| 129 | mutable std::auto_ptr<lldb_private::Symtab> m_symtab_ap; |
| 130 | lldb_private::DataExtractor m_shstr_data; |
| 131 | |
| 132 | size_t |
| 133 | ParseSections (); |
| 134 | |
| 135 | size_t |
| 136 | ParseSymtab (bool minimize); |
| 137 | |
| 138 | private: |
| 139 | |
| 140 | // ELF header dump routines |
| 141 | static void |
| 142 | DumpELFHeader (lldb_private::Stream *s, |
| 143 | const Elf32_Ehdr& header); |
| 144 | |
| 145 | static void |
| 146 | DumpELFHeader_e_ident_EI_DATA (lldb_private::Stream *s, |
| 147 | uint16_t ei_data); |
| 148 | static void |
| 149 | DumpELFHeader_e_type (lldb_private::Stream *s, |
| 150 | uint16_t e_type); |
| 151 | |
| 152 | // ELF program header dump routines |
| 153 | void |
| 154 | DumpELFProgramHeaders (lldb_private::Stream *s); |
| 155 | |
| 156 | static void |
| 157 | DumpELFProgramHeader (lldb_private::Stream *s, |
| 158 | const Elf32_Phdr& ph); |
| 159 | |
| 160 | static void |
| 161 | DumpELFProgramHeader_p_type (lldb_private::Stream *s, |
| 162 | Elf32_Word p_type); |
| 163 | |
| 164 | static void |
| 165 | DumpELFProgramHeader_p_flags (lldb_private::Stream *s, |
| 166 | Elf32_Word p_flags); |
| 167 | |
| 168 | // ELF section header dump routines |
| 169 | void |
| 170 | DumpELFSectionHeaders (lldb_private::Stream *s); |
| 171 | |
| 172 | static void |
| 173 | DumpELFSectionHeader (lldb_private::Stream *s, |
| 174 | const Elf32_Shdr& sh); |
| 175 | |
| 176 | static void |
| 177 | DumpELFSectionHeader_sh_type (lldb_private::Stream *s, |
| 178 | Elf32_Word sh_type); |
| 179 | |
| 180 | static void |
| 181 | DumpELFSectionHeader_sh_flags (lldb_private::Stream *s, |
| 182 | Elf32_Word sh_flags); |
| 183 | |
| 184 | size_t |
| 185 | ParseProgramHeaders (); |
| 186 | |
| 187 | size_t |
| 188 | ParseSectionHeaders (); |
| 189 | |
| 190 | size_t |
| 191 | GetSectionHeaderStringTable (); |
| 192 | |
| 193 | uint32_t |
| 194 | GetSectionIndexByName (const char *name); |
| 195 | }; |
| 196 | |
| 197 | #endif // #ifndef liblldb_ObjectFileELF_h_ |