summaryrefslogtreecommitdiff
path: root/tools/llvm-readobj
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2014-03-18 06:53:02 +0000
committerAlexey Samsonov <samsonov@google.com>2014-03-18 06:53:02 +0000
commit5b645797db05926bffdd6214e94a527267445cc9 (patch)
tree654d72ff2ee5049fd99780d13934c64cb1bd76bf /tools/llvm-readobj
parent3bdef4b6dc8098d86c74c445c8478c28598a3a05 (diff)
downloadllvm-5b645797db05926bffdd6214e94a527267445cc9.tar.gz
llvm-5b645797db05926bffdd6214e94a527267445cc9.tar.bz2
llvm-5b645797db05926bffdd6214e94a527267445cc9.tar.xz
[C++11] Change the interface of getCOFF{Section,Relocation,Symbol} to make it work with range-based for loops.
Reviewers: ruiu Reviewed By: ruiu CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D3097 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204120 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-readobj')
-rw-r--r--tools/llvm-readobj/COFFDumper.cpp91
1 files changed, 40 insertions, 51 deletions
diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp
index 34115f481a..e790e5ca0c 100644
--- a/tools/llvm-readobj/COFFDumper.cpp
+++ b/tools/llvm-readobj/COFFDumper.cpp
@@ -55,8 +55,8 @@ public:
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();
@@ -74,9 +74,9 @@ private:
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();
@@ -188,7 +188,7 @@ static error_code resolveSectionAndAddress(const COFFObjectFile *Obj,
if (error_code EC = Sym.getSection(iter))
return EC;
- ResolvedSection = Obj->getCOFFSection(iter);
+ ResolvedSection = Obj->getCOFFSection(*iter);
return object_error::success;
}
@@ -540,11 +540,10 @@ error_code COFFDumper::getSection(
}
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.
@@ -653,9 +652,10 @@ void COFFDumper::printBaseOfDataField(const pe32_header *Hdr) {
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;
@@ -706,8 +706,8 @@ void COFFDumper::printCodeViewLineTables(section_iterator SecI) {
}
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) {
@@ -814,15 +814,13 @@ void COFFDumper::printCodeViewLineTables(section_iterator SecI) {
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);
@@ -841,29 +839,28 @@ void COFFDumper::printSections() {
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);
}
@@ -874,23 +871,21 @@ void COFFDumper::printRelocations() {
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) {
@@ -900,7 +895,7 @@ void COFFDumper::printRelocations() {
}
}
-void COFFDumper::printRelocation(section_iterator SecI,
+void COFFDumper::printRelocation(const SectionRef &Section,
const RelocationRef &Reloc) {
uint64_t Offset;
uint64_t RelocType;
@@ -916,7 +911,7 @@ void COFFDumper::printRelocation(section_iterator SecI,
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) {
@@ -936,19 +931,16 @@ void COFFDumper::printRelocation(section_iterator SecI,
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";
@@ -1095,20 +1087,17 @@ void COFFDumper::printUnwindInfo() {
}
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(