[C++11] Convert DWARF parser to range-based for loops

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203766 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexey Samsonov 2014-03-13 07:52:54 +00:00
parent 7c801675f8
commit 72df688950
16 changed files with 162 additions and 164 deletions

View File

@ -18,7 +18,7 @@ void DWARFAbbreviationDeclaration::clear() {
Code = 0;
Tag = 0;
HasChildren = false;
Attributes.clear();
AttributeSpecs.clear();
}
DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() {
@ -51,7 +51,8 @@ DWARFAbbreviationDeclaration::extract(DataExtractor Data, uint32_t* OffsetPtr) {
}
if (Attr == 0 && Form == 0)
break;
Attributes.push_back(AttributeSpec(Attr, Form));
AttributeSpec AS = {Attr, Form};
AttributeSpecs.push_back(AS);
}
if (Tag == 0) {
@ -69,19 +70,19 @@ void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
else
OS << format("DW_TAG_Unknown_%x", getTag());
OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
for (unsigned i = 0, e = Attributes.size(); i != e; ++i) {
for (const AttributeSpec &Spec : AttributeSpecs) {
OS << '\t';
const char *attrString = AttributeString(Attributes[i].Attr);
const char *attrString = AttributeString(Spec.Attr);
if (attrString)
OS << attrString;
else
OS << format("DW_AT_Unknown_%x", Attributes[i].Attr);
OS << format("DW_AT_Unknown_%x", Spec.Attr);
OS << '\t';
const char *formString = FormEncodingString(Attributes[i].Form);
const char *formString = FormEncodingString(Spec.Form);
if (formString)
OS << formString;
else
OS << format("DW_FORM_Unknown_%x", Attributes[i].Form);
OS << format("DW_FORM_Unknown_%x", Spec.Form);
OS << '\n';
}
OS << '\n';
@ -89,8 +90,8 @@ void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
uint32_t
DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const {
for (uint32_t i = 0, e = Attributes.size(); i != e; ++i) {
if (Attributes[i].Attr == attr)
for (uint32_t i = 0, e = AttributeSpecs.size(); i != e; ++i) {
if (AttributeSpecs[i].Attr == attr)
return i;
}
return -1U;

View File

@ -23,23 +23,27 @@ class DWARFAbbreviationDeclaration {
bool HasChildren;
struct AttributeSpec {
AttributeSpec(uint16_t Attr, uint16_t Form) : Attr(Attr), Form(Form) {}
uint16_t Attr;
uint16_t Form;
};
SmallVector<AttributeSpec, 8> Attributes;
typedef SmallVector<AttributeSpec, 8> AttributeSpecVector;
AttributeSpecVector AttributeSpecs;
public:
DWARFAbbreviationDeclaration();
uint32_t getCode() const { return Code; }
uint32_t getTag() const { return Tag; }
bool hasChildren() const { return HasChildren; }
uint32_t getNumAttributes() const { return Attributes.size(); }
uint16_t getAttrByIndex(uint32_t idx) const {
return idx < Attributes.size() ? Attributes[idx].Attr : 0;
typedef iterator_range<AttributeSpecVector::const_iterator>
attr_iterator_range;
attr_iterator_range attributes() const {
return attr_iterator_range(AttributeSpecs.begin(), AttributeSpecs.end());
}
uint16_t getFormByIndex(uint32_t idx) const {
return idx < Attributes.size() ? Attributes[idx].Form : 0;
return idx < AttributeSpecs.size() ? AttributeSpecs[idx].Form : 0;
}
uint32_t findAttributeIndex(uint16_t attr) const;

View File

@ -75,29 +75,29 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType) {
if (DumpType == DIDT_All || DumpType == DIDT_Info) {
OS << "\n.debug_info contents:\n";
for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i)
getCompileUnitAtIndex(i)->dump(OS);
for (const auto &CU : compile_units())
CU->dump(OS);
}
if ((DumpType == DIDT_All || DumpType == DIDT_InfoDwo) &&
getNumDWOCompileUnits()) {
OS << "\n.debug_info.dwo contents:\n";
for (unsigned i = 0, e = getNumDWOCompileUnits(); i != e; ++i)
getDWOCompileUnitAtIndex(i)->dump(OS);
for (const auto &DWOCU : dwo_compile_units())
DWOCU->dump(OS);
}
if ((DumpType == DIDT_All || DumpType == DIDT_Types) && getNumTypeUnits()) {
OS << "\n.debug_types contents:\n";
for (unsigned i = 0, e = getNumTypeUnits(); i != e; ++i)
getTypeUnitAtIndex(i)->dump(OS);
for (const auto &TU : type_units())
TU->dump(OS);
}
if (DumpType == DIDT_All || DumpType == DIDT_TypesDwo)
if (getNumDWOTypeUnits()) {
OS << "\n.debug_types.dwo contents:\n";
for (unsigned i = 0, e = getNumDWOTypeUnits(); i != e; ++i)
getDWOTypeUnitAtIndex(i)->dump(OS);
}
if ((DumpType == DIDT_All || DumpType == DIDT_TypesDwo) &&
getNumDWOTypeUnits()) {
OS << "\n.debug_types.dwo contents:\n";
for (const auto &DWOTU : dwo_type_units())
DWOTU->dump(OS);
}
if (DumpType == DIDT_All || DumpType == DIDT_Loc) {
OS << "\n.debug_loc contents:\n";
@ -121,12 +121,11 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType) {
uint8_t savedAddressByteSize = 0;
if (DumpType == DIDT_All || DumpType == DIDT_Line) {
OS << "\n.debug_line contents:\n";
for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i) {
DWARFCompileUnit *cu = getCompileUnitAtIndex(i);
savedAddressByteSize = cu->getAddressByteSize();
for (const auto &CU : compile_units()) {
savedAddressByteSize = CU->getAddressByteSize();
unsigned stmtOffset =
cu->getCompileUnitDIE()->getAttributeValueAsSectionOffset(
cu, DW_AT_stmt_list, -1U);
CU->getCompileUnitDIE()->getAttributeValueAsSectionOffset(
CU, DW_AT_stmt_list, -1U);
if (stmtOffset != -1U) {
DataExtractor lineData(getLineSection().Data, isLittleEndian(),
savedAddressByteSize);
@ -297,6 +296,8 @@ DWARFContext::getLineTableForCompileUnit(DWARFCompileUnit *cu) {
}
void DWARFContext::parseCompileUnits() {
if (!CUs.empty())
return;
uint32_t offset = 0;
const DataExtractor &DIData = DataExtractor(getInfoSection().Data,
isLittleEndian(), 0);
@ -314,17 +315,17 @@ void DWARFContext::parseCompileUnits() {
}
void DWARFContext::parseTypeUnits() {
const TypeSectionMap &Sections = getTypesSections();
for (TypeSectionMap::const_iterator I = Sections.begin(), E = Sections.end();
I != E; ++I) {
if (!TUs.empty())
return;
for (const auto &I : getTypesSections()) {
uint32_t offset = 0;
const DataExtractor &DIData =
DataExtractor(I->second.Data, isLittleEndian(), 0);
DataExtractor(I.second.Data, isLittleEndian(), 0);
while (DIData.isValidOffset(offset)) {
std::unique_ptr<DWARFTypeUnit> TU(new DWARFTypeUnit(
getDebugAbbrev(), I->second.Data, getAbbrevSection(),
getDebugAbbrev(), I.second.Data, getAbbrevSection(),
getRangeSection(), getStringSection(), StringRef(), getAddrSection(),
&I->second.Relocs, isLittleEndian()));
&I.second.Relocs, isLittleEndian()));
if (!TU->extract(DIData, &offset))
break;
TUs.push_back(TU.release());
@ -334,6 +335,8 @@ void DWARFContext::parseTypeUnits() {
}
void DWARFContext::parseDWOCompileUnits() {
if (!DWOCUs.empty())
return;
uint32_t offset = 0;
const DataExtractor &DIData =
DataExtractor(getInfoDWOSection().Data, isLittleEndian(), 0);
@ -352,17 +355,17 @@ void DWARFContext::parseDWOCompileUnits() {
}
void DWARFContext::parseDWOTypeUnits() {
const TypeSectionMap &Sections = getTypesDWOSections();
for (TypeSectionMap::const_iterator I = Sections.begin(), E = Sections.end();
I != E; ++I) {
if (!DWOTUs.empty())
return;
for (const auto &I : getTypesDWOSections()) {
uint32_t offset = 0;
const DataExtractor &DIData =
DataExtractor(I->second.Data, isLittleEndian(), 0);
DataExtractor(I.second.Data, isLittleEndian(), 0);
while (DIData.isValidOffset(offset)) {
std::unique_ptr<DWARFTypeUnit> TU(new DWARFTypeUnit(
getDebugAbbrevDWO(), I->second.Data, getAbbrevDWOSection(),
getDebugAbbrevDWO(), I.second.Data, getAbbrevDWOSection(),
getRangeDWOSection(), getStringDWOSection(),
getStringOffsetDWOSection(), getAddrSection(), &I->second.Relocs,
getStringOffsetDWOSection(), getAddrSection(), &I.second.Relocs,
isLittleEndian()));
if (!TU->extract(DIData, &offset))
break;
@ -388,8 +391,7 @@ namespace {
}
DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t Offset) {
if (CUs.empty())
parseCompileUnits();
parseCompileUnits();
DWARFCompileUnit **CU =
std::lower_bound(CUs.begin(), CUs.end(), Offset, OffsetComparator());
@ -522,9 +524,7 @@ DILineInfoTable DWARFContext::getLineInfoForAddressRange(uint64_t Address,
if (!LineTable->lookupAddressRange(Address, Size, RowVector))
return Lines;
uint32_t NumRows = RowVector.size();
for (uint32_t i = 0; i < NumRows; ++i) {
uint32_t RowIndex = RowVector[i];
for (uint32_t RowIndex : RowVector) {
// Take file number and line/column from the row.
const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
std::string FileName = "<invalid>";

View File

@ -28,33 +28,38 @@ namespace llvm {
/// information parsing. The actual data is supplied through pure virtual
/// methods that a concrete implementation provides.
class DWARFContext : public DIContext {
SmallVector<DWARFCompileUnit *, 1> CUs;
SmallVector<DWARFTypeUnit *, 1> TUs;
typedef SmallVector<DWARFCompileUnit *, 1> CUVector;
typedef SmallVector<DWARFTypeUnit *, 1> TUVector;
CUVector CUs;
TUVector TUs;
std::unique_ptr<DWARFDebugAbbrev> Abbrev;
std::unique_ptr<DWARFDebugLoc> Loc;
std::unique_ptr<DWARFDebugAranges> Aranges;
std::unique_ptr<DWARFDebugLine> Line;
std::unique_ptr<DWARFDebugFrame> DebugFrame;
SmallVector<DWARFCompileUnit *, 1> DWOCUs;
SmallVector<DWARFTypeUnit *, 1> DWOTUs;
CUVector DWOCUs;
TUVector DWOTUs;
std::unique_ptr<DWARFDebugAbbrev> AbbrevDWO;
DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
/// Read compile units from the debug_info section and store them in CUs.
/// Read compile units from the debug_info section (if necessary)
/// and store them in CUs.
void parseCompileUnits();
/// Read type units from the debug_types sections and store them in CUs.
/// Read type units from the debug_types sections (if necessary)
/// and store them in TUs.
void parseTypeUnits();
/// Read compile units from the debug_info.dwo section and store them in
/// DWOCUs.
/// Read compile units from the debug_info.dwo section (if necessary)
/// and store them in DWOCUs.
void parseDWOCompileUnits();
/// Read type units from the debug_types.dwo section and store them in
/// DWOTUs.
/// Read type units from the debug_types.dwo section (if necessary)
/// and store them in DWOTUs.
void parseDWOTypeUnits();
public:
@ -72,62 +77,69 @@ public:
void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) override;
typedef iterator_range<CUVector::iterator> cu_iterator_range;
typedef iterator_range<TUVector::iterator> tu_iterator_range;
/// Get compile units in this context.
cu_iterator_range compile_units() {
parseCompileUnits();
return cu_iterator_range(CUs.begin(), CUs.end());
}
/// Get type units in this context.
tu_iterator_range type_units() {
parseTypeUnits();
return tu_iterator_range(TUs.begin(), TUs.end());
}
/// Get compile units in the DWO context.
cu_iterator_range dwo_compile_units() {
parseDWOCompileUnits();
return cu_iterator_range(DWOCUs.begin(), DWOCUs.end());
}
/// Get type units in the DWO context.
tu_iterator_range dwo_type_units() {
parseDWOTypeUnits();
return tu_iterator_range(DWOTUs.begin(), DWOTUs.end());
}
/// Get the number of compile units in this context.
unsigned getNumCompileUnits() {
if (CUs.empty())
parseCompileUnits();
parseCompileUnits();
return CUs.size();
}
/// Get the number of compile units in this context.
unsigned getNumTypeUnits() {
if (TUs.empty())
parseTypeUnits();
parseTypeUnits();
return TUs.size();
}
/// Get the number of compile units in the DWO context.
unsigned getNumDWOCompileUnits() {
if (DWOCUs.empty())
parseDWOCompileUnits();
parseDWOCompileUnits();
return DWOCUs.size();
}
/// Get the number of compile units in the DWO context.
unsigned getNumDWOTypeUnits() {
if (DWOTUs.empty())
parseDWOTypeUnits();
parseDWOTypeUnits();
return DWOTUs.size();
}
/// Get the compile unit at the specified index for this compile unit.
DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
if (CUs.empty())
parseCompileUnits();
parseCompileUnits();
return CUs[index];
}
/// Get the type unit at the specified index for this compile unit.
DWARFTypeUnit *getTypeUnitAtIndex(unsigned index) {
if (TUs.empty())
parseTypeUnits();
return TUs[index];
}
/// Get the compile unit at the specified index for the DWO compile units.
DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
if (DWOCUs.empty())
parseDWOCompileUnits();
parseDWOCompileUnits();
return DWOCUs[index];
}
/// Get the type unit at the specified index for the DWO type units.
DWARFTypeUnit *getDWOTypeUnitAtIndex(unsigned index) {
if (DWOTUs.empty())
parseDWOTypeUnits();
return DWOTUs[index];
}
/// Get a pointer to the parsed DebugAbbrev object.
const DWARFDebugAbbrev *getDebugAbbrev();

View File

@ -33,19 +33,17 @@ bool DWARFAbbreviationDeclarationSet::extract(DataExtractor data,
}
void DWARFAbbreviationDeclarationSet::dump(raw_ostream &OS) const {
for (unsigned i = 0, e = Decls.size(); i != e; ++i)
Decls[i].dump(OS);
for (const auto &Decl : Decls)
Decl.dump(OS);
}
const DWARFAbbreviationDeclaration*
DWARFAbbreviationDeclarationSet::getAbbreviationDeclaration(uint32_t abbrCode)
const {
if (IdxOffset == UINT32_MAX) {
DWARFAbbreviationDeclarationCollConstIter pos;
DWARFAbbreviationDeclarationCollConstIter end = Decls.end();
for (pos = Decls.begin(); pos != end; ++pos) {
if (pos->getCode() == abbrCode)
return &(*pos);
for (const auto &Decl : Decls) {
if (Decl.getCode() == abbrCode)
return &Decl;
}
} else {
uint32_t idx = abbrCode - IdxOffset;
@ -81,10 +79,9 @@ void DWARFDebugAbbrev::dump(raw_ostream &OS) const {
return;
}
DWARFAbbreviationDeclarationCollMapConstIter pos;
for (pos = AbbrevCollMap.begin(); pos != AbbrevCollMap.end(); ++pos) {
OS << format("Abbrev table for offset: 0x%8.8" PRIx64 "\n", pos->first);
pos->second.dump(OS);
for (const auto &I : AbbrevCollMap) {
OS << format("Abbrev table for offset: 0x%8.8" PRIx64 "\n", I.first);
I.second.dump(OS);
}
}

View File

@ -94,9 +94,9 @@ void DWARFDebugArangeSet::dump(raw_ostream &OS) const {
HeaderData.CuOffset, HeaderData.AddrSize, HeaderData.SegSize);
const uint32_t hex_width = HeaderData.AddrSize * 2;
for (DescriptorConstIter pos = ArangeDescriptors.begin(),
end = ArangeDescriptors.end(); pos != end; ++pos)
OS << format("[0x%*.*" PRIx64 " -", hex_width, hex_width, pos->Address)
for (const auto &Desc : ArangeDescriptors) {
OS << format("[0x%*.*" PRIx64 " -", hex_width, hex_width, Desc.Address)
<< format(" 0x%*.*" PRIx64 ")\n",
hex_width, hex_width, pos->getEndAddress());
hex_width, hex_width, Desc.getEndAddress());
}
}

View File

@ -10,6 +10,7 @@
#ifndef LLVM_DEBUGINFO_DWARFDEBUGARANGESET_H
#define LLVM_DEBUGINFO_DWARFDEBUGARANGESET_H
#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/DataExtractor.h"
#include <vector>
@ -44,7 +45,7 @@ public:
private:
typedef std::vector<Descriptor> DescriptorColl;
typedef DescriptorColl::const_iterator DescriptorConstIter;
typedef iterator_range<DescriptorColl::const_iterator> desc_iterator_range;
uint32_t Offset;
Header HeaderData;
@ -57,12 +58,12 @@ public:
void dump(raw_ostream &OS) const;
uint32_t getCompileUnitDIEOffset() const { return HeaderData.CuOffset; }
uint32_t getNumDescriptors() const { return ArangeDescriptors.size(); }
const Descriptor *getDescriptor(uint32_t i) const {
if (i < ArangeDescriptors.size())
return &ArangeDescriptors[i];
return NULL;
desc_iterator_range descriptors() const {
return desc_iterator_range(ArangeDescriptors.begin(),
ArangeDescriptors.end());
}
uint32_t getNumDescriptors() const { return ArangeDescriptors.size(); }
};
}

View File

@ -33,15 +33,12 @@ void DWARFDebugAranges::extract(DataExtractor DebugArangesData) {
return;
Aranges.reserve(TotalRanges);
for (RangeSetColl::const_iterator I = Sets.begin(), E = Sets.end(); I != E;
++I) {
uint32_t CUOffset = I->getCompileUnitDIEOffset();
for (const auto &I : Sets) {
uint32_t CUOffset = I.getCompileUnitDIEOffset();
for (uint32_t i = 0, n = I->getNumDescriptors(); i < n; ++i) {
const DWARFDebugArangeSet::Descriptor *ArangeDescPtr =
I->getDescriptor(i);
uint64_t LowPC = ArangeDescPtr->Address;
uint64_t HighPC = LowPC + ArangeDescPtr->Length;
for (const auto &Desc : I.descriptors()) {
uint64_t LowPC = Desc.Address;
uint64_t HighPC = Desc.getEndAddress();
appendRange(CUOffset, LowPC, HighPC);
}
}
@ -59,12 +56,10 @@ void DWARFDebugAranges::generate(DWARFContext *CTX) {
// Generate aranges from DIEs: even if .debug_aranges section is present,
// it may describe only a small subset of compilation units, so we need to
// manually build aranges for the rest of them.
for (uint32_t i = 0, n = CTX->getNumCompileUnits(); i < n; ++i) {
if (DWARFCompileUnit *CU = CTX->getCompileUnitAtIndex(i)) {
uint32_t CUOffset = CU->getOffset();
if (ParsedCUOffsets.insert(CUOffset).second)
CU->buildAddressRangeTable(this, true, CUOffset);
}
for (const auto &CU : CTX->compile_units()) {
uint32_t CUOffset = CU->getOffset();
if (ParsedCUOffsets.insert(CUOffset).second)
CU->buildAddressRangeTable(this, true, CUOffset);
}
sortAndMinimize();

View File

@ -186,10 +186,8 @@ void FrameEntry::parseInstructions(uint32_t *Offset, uint32_t EndOffset) {
void FrameEntry::dumpInstructions(raw_ostream &OS) const {
// TODO: at the moment only instruction names are dumped. Expand this to
// dump operands as well.
for (std::vector<Instruction>::const_iterator I = Instructions.begin(),
E = Instructions.end();
I != E; ++I) {
uint8_t Opcode = I->Opcode;
for (const auto &Instr : Instructions) {
uint8_t Opcode = Instr.Opcode;
if (Opcode & DWARF_CFI_PRIMARY_OPCODE_MASK)
Opcode &= DWARF_CFI_PRIMARY_OPCODE_MASK;
OS << " " << CallFrameString(Opcode) << ":\n";
@ -289,9 +287,8 @@ DWARFDebugFrame::DWARFDebugFrame() {
DWARFDebugFrame::~DWARFDebugFrame() {
for (EntryVector::iterator I = Entries.begin(), E = Entries.end();
I != E; ++I) {
delete *I;
for (const auto &Entry : Entries) {
delete Entry;
}
}
@ -381,9 +378,7 @@ void DWARFDebugFrame::parse(DataExtractor Data) {
void DWARFDebugFrame::dump(raw_ostream &OS) const {
OS << "\n";
for (EntryVector::const_iterator I = Entries.begin(), E = Entries.end();
I != E; ++I) {
FrameEntry *Entry = *I;
for (const auto &Entry : Entries) {
Entry->dumpHeader(OS);
Entry->dumpInstructions(OS);
OS << "\n";

View File

@ -42,5 +42,4 @@ private:
} // namespace llvm
#endif
#endif

View File

@ -40,11 +40,8 @@ void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS, const DWARFUnit *u,
AbbrevDecl->hasChildren() ? '*' : ' ');
// Dump all data in the DIE for the attributes.
const uint32_t numAttributes = AbbrevDecl->getNumAttributes();
for (uint32_t i = 0; i != numAttributes; ++i) {
uint16_t attr = AbbrevDecl->getAttrByIndex(i);
uint16_t form = AbbrevDecl->getFormByIndex(i);
dumpAttribute(OS, u, &offset, attr, form, indent);
for (const auto &AttrSpec : AbbrevDecl->attributes()) {
dumpAttribute(OS, u, &offset, AttrSpec.Attr, AttrSpec.Form, indent);
}
const DWARFDebugInfoEntryMinimal *child = getFirstChild();
@ -116,8 +113,8 @@ bool DWARFDebugInfoEntryMinimal::extractFast(const DWARFUnit *U,
assert(FixedFormSizes.size() > 0);
// Skip all data in the .debug_info for the attributes
for (uint32_t i = 0, n = AbbrevDecl->getNumAttributes(); i < n; ++i) {
uint16_t Form = AbbrevDecl->getFormByIndex(i);
for (const auto &AttrSpec : AbbrevDecl->attributes()) {
uint16_t Form = AttrSpec.Form;
uint8_t FixedFormSize =
(Form < FixedFormSizes.size()) ? FixedFormSizes[Form] : 0;

View File

@ -60,9 +60,6 @@ public:
bool isSubroutineDIE() const;
uint32_t getOffset() const { return Offset; }
uint32_t getNumAttributes() const {
return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
}
bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
// We know we are kept in a vector of contiguous entries, so we know

View File

@ -90,9 +90,9 @@ void DWARFDebugLine::LineTable::dump(raw_ostream &OS) const {
OS << "Address Line Column File ISA Discriminator Flags\n"
<< "------------------ ------ ------ ------ --- ------------- "
"-------------\n";
for (std::vector<Row>::const_iterator pos = Rows.begin(),
end = Rows.end(); pos != end; ++pos)
pos->dump(OS);
for (const Row &R : Rows) {
R.dump(OS);
}
}
}

View File

@ -15,19 +15,19 @@
using namespace llvm;
void DWARFDebugLoc::dump(raw_ostream &OS) const {
for (LocationLists::const_iterator I = Locations.begin(), E = Locations.end(); I != E; ++I) {
OS << format("0x%8.8x: ", I->Offset);
for (const LocationList &L : Locations) {
OS << format("0x%8.8x: ", L.Offset);
const unsigned Indent = 12;
for (SmallVectorImpl<Entry>::const_iterator I2 = I->Entries.begin(), E2 = I->Entries.end(); I2 != E2; ++I2) {
if (I2 != I->Entries.begin())
for (const Entry &E : L.Entries) {
if (&E != L.Entries.begin())
OS.indent(Indent);
OS << "Beginning address offset: " << format("0x%016" PRIx64, I2->Begin)
OS << "Beginning address offset: " << format("0x%016" PRIx64, E.Begin)
<< '\n';
OS.indent(Indent) << " Ending address offset: "
<< format("0x%016" PRIx64, I2->End) << '\n';
<< format("0x%016" PRIx64, E.End) << '\n';
OS.indent(Indent) << " Location description: ";
for (SmallVectorImpl<unsigned char>::const_iterator I3 = I2->Loc.begin(), E3 = I2->Loc.end(); I3 != E3; ++I3) {
OS << format("%2.2x ", *I3);
for (unsigned char Loc : E.Loc) {
OS << format("%2.2x ", Loc);
}
OS << "\n\n";
}

View File

@ -45,22 +45,21 @@ bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr) {
}
void DWARFDebugRangeList::dump(raw_ostream &OS) const {
for (int i = 0, n = Entries.size(); i != n; ++i) {
for (const RangeListEntry &RLE : Entries) {
const char *format_str = (AddressSize == 4
? "%08x %08" PRIx64 " %08" PRIx64 "\n"
: "%08x %016" PRIx64 " %016" PRIx64 "\n");
OS << format(format_str, Offset, Entries[i].StartAddress,
Entries[i].EndAddress);
OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress);
}
OS << format("%08x <End of list>\n", Offset);
}
bool DWARFDebugRangeList::containsAddress(uint64_t BaseAddress,
uint64_t Address) const {
for (int i = 0, n = Entries.size(); i != n; ++i) {
if (Entries[i].isBaseAddressSelectionEntry(AddressSize))
BaseAddress = Entries[i].EndAddress;
else if (Entries[i].containsAddress(BaseAddress, Address))
for (const RangeListEntry &RLE : Entries) {
if (RLE.isBaseAddressSelectionEntry(AddressSize))
BaseAddress = RLE.EndAddress;
else if (RLE.containsAddress(BaseAddress, Address))
return true;
}
return false;

View File

@ -331,11 +331,12 @@ DWARFUnit::buildAddressRangeTable(DWARFDebugAranges *debug_aranges,
const DWARFDebugInfoEntryMinimal *
DWARFUnit::getSubprogramForAddress(uint64_t Address) {
extractDIEsIfNeeded(false);
for (size_t i = 0, n = DieArray.size(); i != n; i++)
if (DieArray[i].isSubprogramDIE() &&
DieArray[i].addressRangeContainsAddress(this, Address)) {
return &DieArray[i];
for (const DWARFDebugInfoEntryMinimal &DIE : DieArray) {
if (DIE.isSubprogramDIE() &&
DIE.addressRangeContainsAddress(this, Address)) {
return &DIE;
}
}
return 0;
}