ELFSectionHeader.hxx revision efae30af6a2d9deedf961942e4834163f686871c
1#ifndef ELF_SECTION_HEADER_HXX 2#define ELF_SECTION_HEADER_HXX 3 4#include "utils/raw_ostream.h" 5#include <llvm/Support/Format.h> 6#include <llvm/Support/raw_ostream.h> 7 8#include "ELFObject.h" 9 10template <unsigned Bitwidth> 11char const *ELFSectionHeader_CRTP<Bitwidth>::getName() const { 12 return owner->getSectionName(getNameIndex()); 13} 14 15template <unsigned Bitwidth> 16template <typename Archiver> 17typename ELFSectionHeader_CRTP<Bitwidth>::ConcreteELFSectionHeader * 18ELFSectionHeader_CRTP<Bitwidth>::read(Archiver &AR, 19 ELFObject<Bitwidth> const *owner, 20 size_t index) { 21 22 if (!AR) { 23 // Archiver is in bad state before calling read function. 24 // Return NULL and do nothing. 25 return 0; 26 } 27 28 llvm::OwningPtr<ConcreteELFSectionHeader> sh( 29 new ConcreteELFSectionHeader()); 30 31 if (!sh->serialize(AR)) { 32 // Unable to read the structure. Return NULL. 33 return 0; 34 } 35 36 if (!sh->isValid()) { 37 // Header read from archiver is not valid. Return NULL. 38 return 0; 39 } 40 41 // Set the section header index 42 sh->index = index; 43 44 // Set the owner elf object 45 sh->owner = owner; 46 47 return sh.take(); 48} 49 50template <unsigned Bitwidth> 51void ELFSectionHeader_CRTP<Bitwidth>::print(bool shouldPrintHeader) const { 52 using namespace llvm; 53 54 if (shouldPrintHeader) { 55 out() << '\n' << fillformat('=', 79) << '\n'; 56 out().changeColor(raw_ostream::WHITE, true); 57 out() << "ELF Section Header " 58 << this->getIndex() << '\n'; 59 out().resetColor(); 60 out() << fillformat('-', 79) << '\n'; 61 } else { 62 out() << fillformat('-', 79) << '\n'; 63 out().changeColor(raw_ostream::YELLOW, true); 64 out() << "ELF Section Header " 65 << this->getIndex() << " : " << '\n'; 66 out().resetColor(); 67 } 68 69#define PRINT_LINT(title, value) \ 70 out() << format(" %-13s : ", (char const *)(title)) << (value) << '\n' 71 PRINT_LINT("Name", getName() ); 72 PRINT_LINT("Type", getSectionTypeStr(getType())); 73 PRINT_LINT("Flags", concrete()->getFlags()); 74 PRINT_LINT("Address", getAddress()); 75 PRINT_LINT("Offset", getOffset()); 76 PRINT_LINT("Size", concrete()->getSize()); 77 PRINT_LINT("Link", getLink()); 78 PRINT_LINT("Extra Info", getExtraInfo()); 79 PRINT_LINT("Address Align", concrete()->getAddressAlign()); 80 PRINT_LINT("Entry Size", concrete()->getEntrySize()); 81#undef PRINT_LINT 82 83 if (shouldPrintHeader) { 84 out() << fillformat('=', 79) << '\n'; 85 } 86} 87 88#endif // ELF_SECTION_HEADER_HXX 89