diff options
author | George Rimar <grimar@accesssoftek.com> | 2017-08-15 12:32:54 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2017-08-15 12:32:54 +0000 |
commit | 6957ab5b7b98f7c372313eec6c81601bfa6b5860 (patch) | |
tree | 207e098cf775b363ed57a0451f61ef47918935ea /llvm/lib/DebugInfo/DWARF | |
parent | 67820e015fc79aa115b594269de51d7a9d132682 (diff) | |
download | bcm5719-llvm-6957ab5b7b98f7c372313eec6c81601bfa6b5860.tar.gz bcm5719-llvm-6957ab5b7b98f7c372313eec6c81601bfa6b5860.zip |
[llvm-dwarfdump] - Print section name and index when dumping .debug_info ranges
Teaches llvm-dwarfdump to print section index and name of range
when it dumps .debug_info.
Differential revision: https://reviews.llvm.org/D36313
llvm-svn: 310915
Diffstat (limited to 'llvm/lib/DebugInfo/DWARF')
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp | 14 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFDie.cpp | 52 |
3 files changed, 53 insertions, 19 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp index fdfc95fe24b..703fc894918 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -933,6 +933,7 @@ class DWARFObjInMemory final : public DWARFObject { bool IsLittleEndian; uint8_t AddressSize; StringRef FileName; + const object::ObjectFile *Obj = nullptr; using TypeSectionMap = MapVector<object::SectionRef, DWARFSectionMap, std::map<object::SectionRef, unsigned>>; @@ -1051,7 +1052,8 @@ public: DWARFObjInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L, function_ref<ErrorPolicy(Error)> HandleError) : IsLittleEndian(Obj.isLittleEndian()), - AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()) { + AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()), + Obj(&Obj) { for (const SectionRef &Section : Obj.sections()) { StringRef Name; @@ -1188,6 +1190,8 @@ public: return AI->second; } + const object::ObjectFile *getFile() const override { return Obj; } + bool isLittleEndian() const override { return IsLittleEndian; } StringRef getAbbrevDWOSection() const override { return AbbrevDWOSection; } const DWARFSection &getLineDWOSection() const override { diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp index 0b6ae86fd94..aa1f17934b5 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp @@ -33,20 +33,22 @@ bool DWARFDebugRangeList::extract(const DWARFDataExtractor &data, return false; Offset = *offset_ptr; while (true) { - RangeListEntry entry; + RangeListEntry Entry; + Entry.SectionIndex = -1ULL; + uint32_t prev_offset = *offset_ptr; - entry.StartAddress = - data.getRelocatedAddress(offset_ptr, &entry.SectionIndex); - entry.EndAddress = data.getRelocatedAddress(offset_ptr); + Entry.StartAddress = data.getRelocatedAddress(offset_ptr); + Entry.EndAddress = + data.getRelocatedAddress(offset_ptr, &Entry.SectionIndex); // Check that both values were extracted correctly. if (*offset_ptr != prev_offset + 2 * AddressSize) { clear(); return false; } - if (entry.isEndOfListEntry()) + if (Entry.isEndOfListEntry()) break; - Entries.push_back(entry); + Entries.push_back(Entry); } return true; } diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp index 111f0bbd444..6b557b9e265 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -18,6 +18,7 @@ #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h" #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/DebugInfo/DWARF/DWARFUnit.h" +#include "llvm/Object/ObjectFile.h" #include "llvm/Support/DataExtractor.h" #include "llvm/Support/Format.h" #include "llvm/Support/MathExtras.h" @@ -31,6 +32,7 @@ using namespace llvm; using namespace dwarf; +using namespace object; using namespace syntax; static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) { @@ -51,17 +53,42 @@ static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) { OS << ")"; } -static void dumpRanges(raw_ostream &OS, const DWARFAddressRangesVector& Ranges, - unsigned AddressSize, unsigned Indent) { - if (Ranges.empty()) - return; - - for (const auto &Range: Ranges) { +static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS, + const DWARFAddressRangesVector &Ranges, + unsigned AddressSize, unsigned Indent, + const DIDumpOptions &DumpOpts) { + StringMap<unsigned> SectionAmountMap; + std::vector<StringRef> SectionNames; + if (Obj.getFile() && !DumpOpts.Brief) { + for (const SectionRef &Section : Obj.getFile()->sections()) { + StringRef Name; + if (Section.getName(Name)) + Name = "<error>"; + + ++SectionAmountMap[Name]; + SectionNames.push_back(Name); + } + } + + for (size_t I = 0; I < Ranges.size(); ++I) { + const DWARFAddressRange &R = Ranges[I]; + OS << '\n'; OS.indent(Indent); - OS << format("[0x%0*" PRIx64 " - 0x%0*" PRIx64 ")", - AddressSize*2, Range.LowPC, - AddressSize*2, Range.HighPC); + OS << format("[0x%0*" PRIx64 " - 0x%0*" PRIx64 ")", AddressSize * 2, + R.LowPC, AddressSize * 2, R.HighPC); + + if (SectionNames.empty() || R.SectionIndex == -1ULL) + continue; + + StringRef Name = R.SectionIndex < SectionNames.size() + ? SectionNames[R.SectionIndex] + : "<error>"; + OS << format(" \"%s\"", Name.str().c_str()); + + // Print section index if there is more than one section with this name. + if (SectionAmountMap[Name] > 1) + OS << format(" [%u]", R.SectionIndex); } } @@ -126,10 +153,11 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, if (Optional<uint64_t> OptVal = formValue.getAsUnsignedConstant()) dumpApplePropertyAttribute(OS, *OptVal); } else if (Attr == DW_AT_ranges) { - dumpRanges(OS, Die.getAddressRanges(), U->getAddressByteSize(), - sizeof(BaseIndent)+Indent+4); + const DWARFObject &Obj = Die.getDwarfUnit()->getContext().getDWARFObj(); + dumpRanges(Obj, OS, Die.getAddressRanges(), U->getAddressByteSize(), + sizeof(BaseIndent) + Indent + 4, DumpOpts); } - + OS << ")\n"; } |