// Returns the file offset for the given RVA.
error_code COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res) const {
- for (section_iterator I = section_begin(), E = section_end(); I != E;
- ++I) {
- const coff_section *Section = getCOFFSection(I);
+ for (const SectionRef &S : sections()) {
+ const coff_section *Section = getCOFFSection(S);
uint32_t SectionStart = Section->VirtualAddress;
uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
if (SectionStart <= Addr && Addr < SectionEnd) {
return object_error::success;
}
-const coff_section *COFFObjectFile::getCOFFSection(section_iterator &It) const {
- return toSec(It->getRawDataRefImpl());
+const coff_section *
+COFFObjectFile::getCOFFSection(const SectionRef &Section) const {
+ return toSec(Section.getRawDataRefImpl());
}
-const coff_symbol *COFFObjectFile::getCOFFSymbol(symbol_iterator &It) const {
- return toSymb(It->getRawDataRefImpl());
+const coff_symbol *
+COFFObjectFile::getCOFFSymbol(const SymbolRef &Symbol) const {
+ return toSymb(Symbol.getRawDataRefImpl());
}
const coff_relocation *
-COFFObjectFile::getCOFFRelocation(relocation_iterator &It) const {
- return toRel(It->getRawDataRefImpl());
+COFFObjectFile::getCOFFRelocation(const RelocationRef &Reloc) const {
+ return toRel(Reloc.getRawDataRefImpl());
}
-#define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(enum) \
- case COFF::enum: Res = #enum; break;
+#define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(reloc_type) \
+ case COFF::reloc_type: \
+ Res = #reloc_type; \
+ break;
error_code COFFObjectFile::getRelocationTypeName(DataRefImpl Rel,
SmallVectorImpl<char> &Result) const {
virtual void printUnwindInfo() override;
private:
- void printSymbol(symbol_iterator SymI);
- void printRelocation(section_iterator SecI, const RelocationRef &Reloc);
+ void printSymbol(const SymbolRef &Sym);
+ void printRelocation(const SectionRef &Section, const RelocationRef &Reloc);
void printDataDirectory(uint32_t Index, const std::string &FieldName);
void printX64UnwindInfo();
uint64_t OffsetInSection,
const std::vector<RelocationRef> &Rels);
- void printUnwindCode(const Win64EH::UnwindInfo& UI, ArrayRef<UnwindCode> UCs);
+ void printUnwindCode(const Win64EH::UnwindInfo &UI, ArrayRef<UnwindCode> UCs);
- void printCodeViewLineTables(section_iterator SecI);
+ void printCodeViewLineTables(const SectionRef &Section);
void cacheRelocations();
if (error_code EC = Sym.getSection(iter))
return EC;
- ResolvedSection = Obj->getCOFFSection(iter);
+ ResolvedSection = Obj->getCOFFSection(*iter);
return object_error::success;
}
}
void COFFDumper::cacheRelocations() {
- for (section_iterator SecI = Obj->section_begin(), SecE = Obj->section_end();
- SecI != SecE; ++SecI) {
- const coff_section *Section = Obj->getCOFFSection(SecI);
+ for (const SectionRef &S : Obj->sections()) {
+ const coff_section *Section = Obj->getCOFFSection(S);
- for (const RelocationRef &Reloc : SecI->relocations())
+ for (const RelocationRef &Reloc : S.relocations())
RelocMap[Section].push_back(Reloc);
// Sort relocations by address.
void COFFDumper::printBaseOfDataField(const pe32plus_header *) {}
-void COFFDumper::printCodeViewLineTables(section_iterator SecI) {
+void COFFDumper::printCodeViewLineTables(const SectionRef &Section) {
StringRef Data;
- if (error(SecI->getContents(Data))) return;
+ if (error(Section.getContents(Data)))
+ return;
SmallVector<StringRef, 10> FunctionNames;
StringMap<StringRef> FunctionLineTables;
}
StringRef FunctionName;
- if (error(resolveSymbolName(RelocMap[Obj->getCOFFSection(SecI)], Offset,
- FunctionName)))
+ if (error(resolveSymbolName(RelocMap[Obj->getCOFFSection(Section)],
+ Offset, FunctionName)))
return;
W.printString("FunctionName", FunctionName);
if (FunctionLineTables.count(FunctionName) != 0) {
void COFFDumper::printSections() {
ListScope SectionsD(W, "Sections");
int SectionNumber = 0;
- for (section_iterator SecI = Obj->section_begin(),
- SecE = Obj->section_end();
- SecI != SecE; ++SecI) {
+ for (const SectionRef &Sec : Obj->sections()) {
++SectionNumber;
- const coff_section *Section = Obj->getCOFFSection(SecI);
+ const coff_section *Section = Obj->getCOFFSection(Sec);
StringRef Name;
- if (error(SecI->getName(Name)))
- Name = "";
+ if (error(Sec.getName(Name)))
+ Name = "";
DictScope D(W, "Section");
W.printNumber("Number", SectionNumber);
if (opts::SectionRelocations) {
ListScope D(W, "Relocations");
- for (const RelocationRef &Reloc : SecI->relocations())
- printRelocation(SecI, Reloc);
+ for (const RelocationRef &Reloc : Sec.relocations())
+ printRelocation(Sec, Reloc);
}
if (opts::SectionSymbols) {
ListScope D(W, "Symbols");
- for (symbol_iterator SymI = Obj->symbol_begin(),
- SymE = Obj->symbol_end();
- SymI != SymE; ++SymI) {
+ for (const SymbolRef &Symbol : Obj->symbols()) {
bool Contained = false;
- if (SecI->containsSymbol(*SymI, Contained) || !Contained)
+ if (Sec.containsSymbol(Symbol, Contained) || !Contained)
continue;
- printSymbol(SymI);
+ printSymbol(Symbol);
}
}
if (Name == ".debug$S" && opts::CodeViewLineTables)
- printCodeViewLineTables(SecI);
+ printCodeViewLineTables(Sec);
if (opts::SectionData) {
StringRef Data;
- if (error(SecI->getContents(Data))) break;
+ if (error(Sec.getContents(Data)))
+ break;
W.printBinaryBlock("SectionData", Data);
}
ListScope D(W, "Relocations");
int SectionNumber = 0;
- for (section_iterator SecI = Obj->section_begin(),
- SecE = Obj->section_end();
- SecI != SecE; ++SecI) {
+ for (const SectionRef &Section : Obj->sections()) {
++SectionNumber;
StringRef Name;
- if (error(SecI->getName(Name)))
+ if (error(Section.getName(Name)))
continue;
bool PrintedGroup = false;
- for (const RelocationRef &Reloc : SecI->relocations()) {
+ for (const RelocationRef &Reloc : Section.relocations()) {
if (!PrintedGroup) {
W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n";
W.indent();
PrintedGroup = true;
}
- printRelocation(SecI, Reloc);
+ printRelocation(Section, Reloc);
}
if (PrintedGroup) {
}
}
-void COFFDumper::printRelocation(section_iterator SecI,
+void COFFDumper::printRelocation(const SectionRef &Section,
const RelocationRef &Reloc) {
uint64_t Offset;
uint64_t RelocType;
symbol_iterator Symbol = Reloc.getSymbol();
if (error(Symbol->getName(SymbolName)))
return;
- if (error(SecI->getContents(Contents)))
+ if (error(Section.getContents(Contents)))
return;
if (opts::ExpandRelocs) {
void COFFDumper::printSymbols() {
ListScope Group(W, "Symbols");
- for (symbol_iterator SymI = Obj->symbol_begin(), SymE = Obj->symbol_end();
- SymI != SymE; ++SymI)
- printSymbol(SymI);
+ for (const SymbolRef &Symbol : Obj->symbols())
+ printSymbol(Symbol);
}
-void COFFDumper::printDynamicSymbols() {
- ListScope Group(W, "DynamicSymbols");
-}
+void COFFDumper::printDynamicSymbols() { ListScope Group(W, "DynamicSymbols"); }
-void COFFDumper::printSymbol(symbol_iterator SymI) {
+void COFFDumper::printSymbol(const SymbolRef &Sym) {
DictScope D(W, "Symbol");
- const coff_symbol *Symbol = Obj->getCOFFSymbol(SymI);
+ const coff_symbol *Symbol = Obj->getCOFFSymbol(Sym);
const coff_section *Section;
if (error_code EC = Obj->getSection(Symbol->SectionNumber, Section)) {
W.startLine() << "Invalid section number: " << EC.message() << "\n";
}
void COFFDumper::printX64UnwindInfo() {
- for (section_iterator SecI = Obj->section_begin(),
- SecE = Obj->section_end();
- SecI != SecE; ++SecI) {
+ for (const SectionRef &Section : Obj->sections()) {
StringRef Name;
- if (error(SecI->getName(Name)))
+ if (error(Section.getName(Name)))
continue;
if (Name != ".pdata" && !Name.startswith(".pdata$"))
continue;
- const coff_section *PData = Obj->getCOFFSection(SecI);
+ const coff_section *PData = Obj->getCOFFSection(Section);
ArrayRef<uint8_t> Contents;
- if (error(Obj->getSectionContents(PData, Contents)) ||
- Contents.empty())
+ if (error(Obj->getSectionContents(PData, Contents)) || Contents.empty())
continue;
ArrayRef<RuntimeFunction> RFs(
void COFFDumper::dumpSections(unsigned NumSections) {
std::vector<COFFYAML::Section> &Sections = YAMLObj.Sections;
- for (object::section_iterator iter = Obj.section_begin();
- iter != Obj.section_end(); ++iter) {
- const object::coff_section *Sect = Obj.getCOFFSection(iter);
+ for (const auto &Section : Obj.sections()) {
+ const object::coff_section *Sect = Obj.getCOFFSection(Section);
COFFYAML::Section Sec;
Sec.Name = Sect->Name; // FIXME: check the null termination!
uint32_t Characteristics = Sect->Characteristics;
Sec.SectionData = object::yaml::BinaryRef(sectionData);
std::vector<COFFYAML::Relocation> Relocations;
- for (object::relocation_iterator rIter = iter->relocation_begin();
- rIter != iter->relocation_end(); ++rIter) {
- const object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter);
+ for (const auto &Reloc : Section.relocations()) {
+ const object::coff_relocation *reloc = Obj.getCOFFRelocation(Reloc);
COFFYAML::Relocation Rel;
- object::symbol_iterator Sym = rIter->getSymbol();
+ object::symbol_iterator Sym = Reloc.getSymbol();
Sym->getName(Rel.SymbolName);
Rel.VirtualAddress = reloc->VirtualAddress;
Rel.Type = reloc->Type;
void COFFDumper::dumpSymbols(unsigned NumSymbols) {
std::vector<COFFYAML::Symbol> &Symbols = YAMLObj.Symbols;
- for (object::symbol_iterator iter = Obj.symbol_begin();
- iter != Obj.symbol_end(); ++iter) {
- const object::coff_symbol *Symbol = Obj.getCOFFSymbol(iter);
+ for (const auto &S : Obj.symbols()) {
+ const object::coff_symbol *Symbol = Obj.getCOFFSymbol(S);
COFFYAML::Symbol Sym;
Obj.getSymbolName(Symbol, Sym.Name);
Sym.SimpleType = COFF::SymbolBaseType(Symbol->getBaseType());