[C++11] Introduce ObjectFile::sections().

Summary:
This adds ObjectFile::section_iterator_range, that allows to write
range-based for-loops running over all sections of a given file.
Several files from lib/ are converted to the new interface. Similar fixes
should be applied to a variety of llvm-* tools.

Reviewers: rafael

Reviewed By: rafael

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D3069

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203799 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexey Samsonov
2014-03-13 13:52:54 +00:00
parent f8909fa140
commit b920dfe02b
5 changed files with 63 additions and 55 deletions

View File

@ -605,16 +605,14 @@ static bool consumeCompressedDebugSectionHeader(StringRef &data,
return true;
}
DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
IsLittleEndian(Obj->isLittleEndian()),
AddressSize(Obj->getBytesInAddress()) {
for (object::section_iterator i = Obj->section_begin(),
e = Obj->section_end();
i != e; ++i) {
DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj)
: IsLittleEndian(Obj->isLittleEndian()),
AddressSize(Obj->getBytesInAddress()) {
for (const SectionRef &Section : Obj->sections()) {
StringRef name;
i->getName(name);
Section.getName(name);
StringRef data;
i->getContents(data);
Section.getContents(data);
name = name.substr(name.find_first_not_of("._")); // Skip . and _ prefixes.
@ -634,7 +632,7 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
UncompressedSections.push_back(std::move(UncompressedSection));
}
StringRef *Section =
StringRef *SectionData =
StringSwitch<StringRef *>(name)
.Case("debug_info", &InfoSection.Data)
.Case("debug_abbrev", &AbbrevSection)
@ -656,8 +654,8 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
.Case("debug_addr", &AddrSection)
// Any more debug info sections go here.
.Default(0);
if (Section) {
*Section = data;
if (SectionData) {
*SectionData = data;
if (name == "debug_ranges") {
// FIXME: Use the other dwo range section when we emit it.
RangeDWOSection = data;
@ -665,12 +663,12 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
} else if (name == "debug_types") {
// Find debug_types data by section rather than name as there are
// multiple, comdat grouped, debug_types sections.
TypesSections[*i].Data = data;
TypesSections[Section].Data = data;
} else if (name == "debug_types.dwo") {
TypesDWOSections[*i].Data = data;
TypesDWOSections[Section].Data = data;
}
section_iterator RelocatedSection = i->getRelocatedSection();
section_iterator RelocatedSection = Section.getRelocatedSection();
if (RelocatedSection == Obj->section_end())
continue;
@ -698,11 +696,11 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
continue;
}
if (i->relocation_begin() != i->relocation_end()) {
if (Section.relocation_begin() != Section.relocation_end()) {
uint64_t SectionSize;
RelocatedSection->getSize(SectionSize);
for (object::relocation_iterator reloc_i = i->relocation_begin(),
reloc_e = i->relocation_end();
for (object::relocation_iterator reloc_i = Section.relocation_begin(),
reloc_e = Section.relocation_end();
reloc_i != reloc_e; ++reloc_i) {
uint64_t Address;
reloc_i->getOffset(Address);