From: David Blaikie Date: Fri, 13 Nov 2015 19:18:49 +0000 (+0000) Subject: dwarfdump: Add support for dumping the table contents of DWP indexes X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=6c420832f338b413ac671cd7f4ee43429bfe2226;p=oota-llvm.git dwarfdump: Add support for dumping the table contents of DWP indexes This is a recommit of 252842 which was reverted in 252859. The issue was using %s format specifier for a StringRef - used Format's left_justify(StringRef, int) instead. It'd be nice to have __attribute__((format(..))) on llvm::format, but apparently it's only implemented for c-style variadics, not C++ variadic templates. Perhaps we could fix that & conditionalize the attribute on such... git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253065 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp b/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp index f97a68f860a..37d78313af9 100644 --- a/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp +++ b/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp @@ -26,10 +26,7 @@ bool DWARFUnitIndex::Header::parse(DataExtractor IndexData, } void DWARFUnitIndex::Header::dump(raw_ostream &OS) const { - OS << "Index header:\n" << format(" version: %u\n", Version) - << format(" columns: %u\n", NumColumns) - << format(" units: %u\n", NumUnits) - << format(" buckets: %u\n", NumBuckets); + OS << format("version = %u slots = %u\n\n", Version, NumBuckets); } bool DWARFUnitIndex::parse(DataExtractor IndexData) { @@ -42,6 +39,45 @@ bool DWARFUnitIndex::parse(DataExtractor IndexData) { (2 * Header.NumUnits + 1) * 4 * Header.NumColumns)) return false; + Rows = llvm::make_unique(Header.NumBuckets); + auto Contribs = + llvm::make_unique(Header.NumUnits); + ColumnKinds = llvm::make_unique(Header.NumColumns); + + // Read Hash Table of Signatures + for (unsigned i = 0; i != Header.NumBuckets; ++i) + Rows[i].Signature = IndexData.getU64(&Offset); + + // Read Parallel Table of Indexes + for (unsigned i = 0; i != Header.NumBuckets; ++i) { + auto Index = IndexData.getU32(&Offset); + if (!Index) + continue; + Rows[i].Contributions = + llvm::make_unique(Header.NumColumns); + Contribs[Index - 1] = Rows[i].Contributions.get(); + } + + // Read the Column Headers + for (unsigned i = 0; i != Header.NumColumns; ++i) + ColumnKinds[i] = static_cast(IndexData.getU32(&Offset)); + + // Read Table of Section Offsets + for (unsigned i = 0; i != Header.NumUnits; ++i) { + auto *Contrib = Contribs[i]; + for (unsigned i = 0; i != Header.NumColumns; ++i) { + Contrib[i].Offset = IndexData.getU32(&Offset); + } + } + + // Read Table of Section Sizes + for (unsigned i = 0; i != Header.NumUnits; ++i) { + auto *Contrib = Contribs[i]; + for (unsigned i = 0; i != Header.NumColumns; ++i) { + Contrib[i].Size = IndexData.getU32(&Offset); + } + } + return true; } @@ -64,6 +100,24 @@ StringRef DWARFUnitIndex::getColumnHeader(DwarfSection DS) { void DWARFUnitIndex::dump(raw_ostream &OS) const { Header.dump(OS); + OS << "Index Signature "; + for (unsigned i = 0; i != Header.NumColumns; ++i) + OS << ' ' << left_justify(getColumnHeader(ColumnKinds[i]), 24); + OS << "\n----- ------------------"; + for (unsigned i = 0; i != Header.NumColumns; ++i) + OS << " ------------------------"; + OS << '\n'; + for (unsigned i = 0; i != Header.NumBuckets; ++i) { + auto &Row = Rows[i]; + if (auto *Contribs = Row.Contributions.get()) { + OS << format("%5u 0x%016" PRIx64 " ", i, Row.Signature); + for (unsigned i = 0; i != Header.NumColumns; ++i) { + auto &Contrib = Contribs[i]; + OS << format("[0x%08u, 0x%08u) ", Contrib.Offset, + Contrib.Offset + Contrib.Size); + } + OS << '\n'; + } + } } - } diff --git a/test/DebugInfo/dwarfdump-dwp.test b/test/DebugInfo/dwarfdump-dwp.test index 07c3b3399f7..953a58cb4af 100644 --- a/test/DebugInfo/dwarfdump-dwp.test +++ b/test/DebugInfo/dwarfdump-dwp.test @@ -9,17 +9,17 @@ RUN: llvm-dwarfdump %p/Inputs/dwarfdump-dwp.x86_64.o | FileCheck %s ; bar b; ; CHECK: .debug_cu_index contents: -; CHECK-NEXT: Index header: -; CHECK-NEXT: version: 2 -; CHECK-NEXT: columns: 4 -; CHECK-NEXT: units: 2 -; CHECK-NEXT: buckets: 16 +; CHECK-NEXT: version = 2 slots = 16 +; CHECK: Index Signature INFO ABBREV LINE STR_OFFSETS +; CHECK-NEXT: ----- ------------------ ------------------------ ------------------------ ------------------------ ------------------------ +; CHECK-NEXT: 8 0x03c30756e2d45008 [0x00000000, 0x00000045) [0x00000000, 0x00000067) [0x00000000, 0x00000026) [0x00000000, 0x00000016) +; CHECK-NEXT: 12 0x9aeb3a61ed48510c [0x00000045, 0x00000090) [0x00000067, 0x00000134) [0x00000026, 0x00000052) [0x00000016, 0x00000032) ; CHECK: .debug_tu_index contents: -; CHECK-NEXT: Index header: -; CHECK-NEXT: version: 2 -; CHECK-NEXT: columns: 4 -; CHECK-NEXT: units: 2 -; CHECK-NEXT: buckets: 16 +; CHECK-NEXT: version = 2 slots = 16 +; CHECK: Index Signature TYPES ABBREV LINE STR_OFFSETS +; CHECK-NEXT: ----- ------------------ ------------------------ ------------------------ ------------------------ ------------------------ +; CHECK-NEXT: 8 0x1d02f3be30cc5688 [0x00000036, 0x00000072) [0x00000067, 0x00000134) [0x00000026, 0x00000052) [0x00000016, 0x00000032) +; CHECK-NEXT: 12 0x3875c0e21cda63fc [0x00000000, 0x00000036) [0x00000000, 0x00000067) [0x00000000, 0x00000026) [0x00000000, 0x00000016) ; TODO: use the index section offset info to correctly dump debug_info