ELFSectionSymTab.hxx revision 58611fc8193e7386698178f167a2e0cbdd6a4f6f
1#ifndef ELF_SECTION_SYM_TAB_HXX 2#define ELF_SECTION_SYM_TAB_HXX 3 4#include "ELFSectionHeader.h" 5#include "ELFSymbol.h" 6 7template <unsigned Bitwidth> 8ELFSectionSymTab<Bitwidth>::~ELFSectionSymTab() { 9 for (size_t i = 0; i < table.size(); ++i) { 10 delete table[i]; 11 } 12} 13 14template <unsigned Bitwidth> 15template <typename Archiver> 16ELFSectionSymTab<Bitwidth> * 17ELFSectionSymTab<Bitwidth>::read(Archiver &AR, 18 ELFObjectTy *owner, 19 ELFSectionHeaderTy const *sh) { 20 21 llvm::OwningPtr<ELFSectionSymTabTy> st(new ELFSectionSymTabTy()); 22 23 // Assert that entry size will be the same as standard. 24 assert(sh->getEntrySize() == TypeTraits<ELFSymbolTy>::size); 25 26 // Seek to the start of symbol table 27 AR.seek(sh->getOffset(), true); 28 29 // Read all symbol table entry 30 size_t size = sh->getSize() / sh->getEntrySize(); 31 for (size_t i = 0; i < size; ++i) { 32 st->table.push_back(ELFSymbolTy::read(AR, owner, i)); 33 } 34 35 if (!AR) { 36 // Unable to read the table. 37 return 0; 38 } 39 40 return st.take(); 41} 42 43template <unsigned Bitwidth> 44void ELFSectionSymTab<Bitwidth>::print() const { 45 using namespace llvm; 46 47 out() << '\n' << fillformat('=', 79) << '\n'; 48 out().changeColor(raw_ostream::WHITE, true); 49 out() << "Symbol Table" << '\n'; 50 out().resetColor(); 51 52 for (size_t i = 0; i < table.size(); ++i) { 53 table[i]->print(); 54 } 55 56 out() << fillformat('=', 79) << '\n'; 57} 58 59#endif // ELF_SECTION_SYM_TAB_HXX 60