llvm.org GIT mirror llvm / ab8c64c
dwarfdump: Dump the contents of DWP indexes git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252842 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 4 years ago
4 changed file(s) with 121 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
1717 namespace llvm {
1818
1919 class DWARFUnitIndex {
20 class Header {
20 struct Header {
2121 uint32_t Version;
2222 uint32_t NumColumns;
2323 uint32_t NumUnits;
2424 uint32_t NumBuckets;
2525
26 public:
2726 bool parse(DataExtractor IndexData, uint32_t *OffsetPtr);
2827 void dump(raw_ostream &OS) const;
2928 };
3029
31 class Header Header;
30 struct HashRow {
31 uint64_t Signature;
32 struct SectionContribution {
33 uint32_t Offset;
34 uint32_t Size;
35 };
36 std::unique_ptr Contributions;
37 };
38
39 enum DwarfSection {
40 DW_SECT_INFO = 1,
41 DW_SECT_TYPES,
42 DW_SECT_ABBREV,
43 DW_SECT_LINE,
44 DW_SECT_LOC,
45 DW_SECT_STR_OFFSETS,
46 DW_SECT_MACINFO,
47 DW_SECT_MACRO,
48 };
49
50 struct Header Header;
51
52 std::unique_ptr ColumnKinds;
53 std::unique_ptr Rows;
54
55 static StringRef getColumnHeader(DwarfSection DS);
3256
3357 public:
3458 bool parse(DataExtractor IndexData);
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
10
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/Support/ErrorHandling.h"
1013
1114 namespace llvm {
1215
2023 }
2124
2225 void DWARFUnitIndex::Header::dump(raw_ostream &OS) const {
23 OS << "Index header:\n" << format(" version: %u\n", Version)
24 << format(" columns: %u\n", NumColumns)
25 << format(" units: %u\n", NumUnits)
26 << format(" buckets: %u\n", NumBuckets);
26 OS << format("version = %u slots = %u\n\n", Version, NumBuckets);
2727 }
2828
2929 bool DWARFUnitIndex::parse(DataExtractor IndexData) {
3131 if (!Header.parse(IndexData, &Offset))
3232 return false;
3333
34 Rows = llvm::make_unique(Header.NumBuckets);
35 auto Contribs =
36 llvm::make_unique(Header.NumUnits);
37 ColumnKinds = llvm::make_unique(Header.NumColumns);
38
39 // Read Hash Table of Signatures
40 for (unsigned i = 0; i != Header.NumBuckets; ++i)
41 Rows[i].Signature = IndexData.getU64(&Offset);
42
43 // Read Parallel Table of Indexes
44 for (unsigned i = 0; i != Header.NumBuckets; ++i) {
45 auto Index = IndexData.getU32(&Offset);
46 if (!Index)
47 continue;
48 Rows[i].Contributions =
49 llvm::make_unique(Header.NumColumns);
50 Contribs[Index - 1] = Rows[i].Contributions.get();
51 }
52
53 // Read the Column Headers
54 for (unsigned i = 0; i != Header.NumColumns; ++i)
55 ColumnKinds[i] = static_cast(IndexData.getU32(&Offset));
56
57 // Read Table of Section Offsets
58 for (unsigned i = 0; i != Header.NumUnits; ++i) {
59 auto *Contrib = Contribs[i];
60 for (unsigned i = 0; i != Header.NumColumns; ++i) {
61 Contrib[i].Offset = IndexData.getU32(&Offset);
62 }
63 }
64
65 // Read Table of Section Sizes
66 for (unsigned i = 0; i != Header.NumUnits; ++i) {
67 auto *Contrib = Contribs[i];
68 for (unsigned i = 0; i != Header.NumColumns; ++i) {
69 Contrib[i].Size = IndexData.getU32(&Offset);
70 }
71 }
72
3473 return true;
3574 }
3675
37 void DWARFUnitIndex::dump(raw_ostream &OS) const { Header.dump(OS); }
76 StringRef DWARFUnitIndex::getColumnHeader(DwarfSection DS) {
77 #define CASE(DS) \
78 case DW_SECT_##DS: \
79 return #DS;
80 switch (DS) {
81 CASE(INFO);
82 CASE(TYPES);
83 CASE(ABBREV);
84 CASE(LINE);
85 CASE(LOC);
86 CASE(STR_OFFSETS);
87 CASE(MACINFO);
88 CASE(MACRO);
89 }
90 llvm_unreachable("unknown DwarfSection");
3891 }
92
93 void DWARFUnitIndex::dump(raw_ostream &OS) const {
94 Header.dump(OS);
95 OS << "Index Signature ";
96 for (unsigned i = 0; i != Header.NumColumns; ++i)
97 OS << format(" %-24s", getColumnHeader(ColumnKinds[i]));
98 OS << "\n----- ------------------";
99 for (unsigned i = 0; i != Header.NumColumns; ++i)
100 OS << " ------------------------";
101 OS << '\n';
102 for (unsigned i = 0; i != Header.NumBuckets; ++i) {
103 auto &Row = Rows[i];
104 if (auto *Contribs = Row.Contributions.get()) {
105 OS << format("%5u 0x%016" PRIx64 " ", i, Row.Signature);
106 for (unsigned i = 0; i != Header.NumColumns; ++i) {
107 auto &Contrib = Contribs[i];
108 OS << format("[0x%08u, 0x%08u) ", Contrib.Offset,
109 Contrib.Offset + Contrib.Size);
110 }
111 OS << '\n';
112 }
113 }
114 }
115 }
44 ; struct foo { };
55 ; foo a;
66 ; b.cpp:
7 ; struct foo { };
8 ; foo b;
7 ; struct bar { };
8 ; bar b;
99
1010 ; CHECK: .debug_cu_index contents:
11 ; CHECK-NEXT: Index header:
12 ; CHECK-NEXT: version: 2
13 ; CHECK-NEXT: columns: 4
14 ; CHECK-NEXT: units: 2
15 ; CHECK-NEXT: buckets: 16
11 ; CHECK-NEXT: version = 2 slots = 16
12 ; CHECK: Index Signature INFO ABBREV LINE STR_OFFSETS
13 ; CHECK-NEXT: ----- ------------------ ------------------------ ------------------------ ------------------------ ------------------------
14 ; CHECK-NEXT: 8 0x03c30756e2d45008 [0x00000000, 0x00000045) [0x00000000, 0x00000067) [0x00000000, 0x00000026) [0x00000000, 0x00000016)
15 ; CHECK-NEXT: 12 0x9aeb3a61ed48510c [0x00000045, 0x00000090) [0x00000067, 0x00000134) [0x00000026, 0x00000052) [0x00000016, 0x00000032)
1616
1717 ; CHECK: .debug_tu_index contents:
18 ; CHECK-NEXT: Index header:
19 ; CHECK-NEXT: version: 2
20 ; CHECK-NEXT: columns: 4
21 ; CHECK-NEXT: units: 1
22 ; CHECK-NEXT: buckets: 16
18 ; CHECK-NEXT: version = 2 slots = 16
19 ; CHECK: Index Signature TYPES ABBREV LINE STR_OFFSETS
20 ; CHECK-NEXT: ----- ------------------ ------------------------ ------------------------ ------------------------ ------------------------
21 ; CHECK-NEXT: 8 0x1d02f3be30cc5688 [0x00000036, 0x00000072) [0x00000067, 0x00000134) [0x00000026, 0x00000052) [0x00000016, 0x00000032)
22 ; CHECK-NEXT: 12 0x3875c0e21cda63fc [0x00000000, 0x00000036) [0x00000000, 0x00000067) [0x00000000, 0x00000026) [0x00000000, 0x00000016)
2323
24 ; TODO: dump the index contents
2524 ; TODO: use the index section offset info to correctly dump debug_info