llvm.org GIT mirror llvm / 3db24f5
[DebugInfo] Further simplify DWARFDebugAranges public interface git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191813 91177308-0d34-0410-b5e6-96231b3b80d8 Alexey Samsonov 6 years ago
3 changed file(s) with 33 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
230230 if (Aranges)
231231 return Aranges.get();
232232
233 DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
234
235233 Aranges.reset(new DWARFDebugAranges());
236 Aranges->extract(arangesData);
237 // Generate aranges from DIEs: even if .debug_aranges section is present,
238 // it may describe only a small subset of compilation units, so we need to
239 // manually build aranges for the rest of them.
240234 Aranges->generate(this);
241235 return Aranges.get();
242236 }
4444 appendRange(CUOffset, LowPC, HighPC);
4545 }
4646 }
47 sortAndMinimize();
4847 }
4948
5049 void DWARFDebugAranges::generate(DWARFContext *CTX) {
51 if (CTX) {
52 const uint32_t num_compile_units = CTX->getNumCompileUnits();
53 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
54 if (DWARFCompileUnit *cu = CTX->getCompileUnitAtIndex(cu_idx)) {
55 uint32_t CUOffset = cu->getOffset();
56 if (ParsedCUOffsets.insert(CUOffset).second)
57 cu->buildAddressRangeTable(this, true, CUOffset);
58 }
50 clear();
51 if (!CTX)
52 return;
53
54 // Extract aranges from .debug_aranges section.
55 DataExtractor ArangesData(CTX->getARangeSection(), CTX->isLittleEndian(), 0);
56 extract(ArangesData);
57
58 // Generate aranges from DIEs: even if .debug_aranges section is present,
59 // it may describe only a small subset of compilation units, so we need to
60 // manually build aranges for the rest of them.
61 for (uint32_t i = 0, n = CTX->getNumCompileUnits(); i < n; ++i) {
62 if (DWARFCompileUnit *CU = CTX->getCompileUnitAtIndex(i)) {
63 uint32_t CUOffset = CU->getOffset();
64 if (ParsedCUOffsets.insert(CUOffset).second)
65 CU->buildAddressRangeTable(this, true, CUOffset);
5966 }
6067 }
68
6169 sortAndMinimize();
62 }
63
64 void DWARFDebugAranges::dump(raw_ostream &OS) const {
65 for (RangeCollIterator I = Aranges.begin(), E = Aranges.end(); I != E; ++I) {
66 I->dump(OS);
67 }
68 }
69
70 void DWARFDebugAranges::Range::dump(raw_ostream &OS) const {
71 OS << format("{0x%8.8x}: [0x%8.8" PRIx64 " - 0x%8.8" PRIx64 ")\n",
72 CUOffset, LowPC, HighPC());
7370 }
7471
7572 void DWARFDebugAranges::appendRange(uint32_t CUOffset, uint64_t LowPC,
1919
2020 class DWARFDebugAranges {
2121 public:
22 void clear() {
23 Aranges.clear();
24 ParsedCUOffsets.clear();
25 }
26
27 void generate(DWARFContext *CTX);
28
29 // Use appendRange multiple times and then call sortAndMinimize.
30 void appendRange(uint32_t CUOffset, uint64_t LowPC, uint64_t HighPC);
31
32 uint32_t findAddress(uint64_t Address) const;
33
34 private:
35 void extract(DataExtractor DebugArangesData);
36 void sortAndMinimize();
37
2238 struct Range {
2339 explicit Range(uint64_t LowPC = -1ULL, uint64_t HighPC = -1ULL,
2440 uint32_t CUOffset = -1U)
4965 return Left.HighPC() >= Right.LowPC;
5066 }
5167
52 void dump(raw_ostream &OS) const;
5368 uint64_t LowPC; // Start of address range.
5469 uint32_t Length; // End of address range (not including this address).
5570 uint32_t CUOffset; // Offset of the compile unit or die.
5671 };
5772
58 void clear() {
59 Aranges.clear();
60 ParsedCUOffsets.clear();
61 }
62 void extract(DataExtractor DebugArangesData);
63 void generate(DWARFContext *CTX);
64
65 // Use appendRange multiple times and then call sortAndMinimize.
66 void appendRange(uint32_t CUOffset, uint64_t LowPC, uint64_t HighPC);
67 void sortAndMinimize();
68
69 void dump(raw_ostream &OS) const;
70 uint32_t findAddress(uint64_t Address) const;
71
7273 typedef std::vector RangeColl;
7374 typedef RangeColl::const_iterator RangeCollIterator;
7475 typedef DenseSet ParsedCUOffsetColl;
7576
76 private:
7777 RangeColl Aranges;
7878 ParsedCUOffsetColl ParsedCUOffsets;
7979 };