Mercurial > hg > CbC > CbC_llvm
comparison lib/DebugInfo/DWARF/DWARFDebugAranges.cpp @ 121:803732b1fca8
LLVM 5.0
author | kono |
---|---|
date | Fri, 27 Oct 2017 17:07:41 +0900 |
parents | 60c9769439b8 |
children | c2174574ed3a |
comparison
equal
deleted
inserted
replaced
120:1172e4bd9c6f | 121:803732b1fca8 |
---|---|
1 //===-- DWARFDebugAranges.cpp -----------------------------------*- C++ -*-===// | 1 //===- DWARFDebugAranges.cpp ----------------------------------------------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
9 | 9 |
10 #include "llvm/DebugInfo/DWARF/DWARFDebugAranges.h" | 10 #include "llvm/DebugInfo/DWARF/DWARFDebugAranges.h" |
11 #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" | 11 #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" |
12 #include "llvm/DebugInfo/DWARF/DWARFContext.h" | 12 #include "llvm/DebugInfo/DWARF/DWARFContext.h" |
13 #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h" | 13 #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h" |
14 #include "llvm/Support/Format.h" | 14 #include "llvm/Support/DataExtractor.h" |
15 #include "llvm/Support/raw_ostream.h" | |
16 #include <algorithm> | 15 #include <algorithm> |
17 #include <cassert> | 16 #include <cassert> |
17 #include <cstdint> | |
18 #include <set> | 18 #include <set> |
19 #include <vector> | |
20 | |
19 using namespace llvm; | 21 using namespace llvm; |
20 | 22 |
21 void DWARFDebugAranges::extract(DataExtractor DebugArangesData) { | 23 void DWARFDebugAranges::extract(DataExtractor DebugArangesData) { |
22 if (!DebugArangesData.isValidOffset(0)) | 24 if (!DebugArangesData.isValidOffset(0)) |
23 return; | 25 return; |
39 clear(); | 41 clear(); |
40 if (!CTX) | 42 if (!CTX) |
41 return; | 43 return; |
42 | 44 |
43 // Extract aranges from .debug_aranges section. | 45 // Extract aranges from .debug_aranges section. |
44 DataExtractor ArangesData(CTX->getARangeSection(), CTX->isLittleEndian(), 0); | 46 DataExtractor ArangesData(CTX->getDWARFObj().getARangeSection(), |
47 CTX->isLittleEndian(), 0); | |
45 extract(ArangesData); | 48 extract(ArangesData); |
46 | 49 |
47 // Generate aranges from DIEs: even if .debug_aranges section is present, | 50 // Generate aranges from DIEs: even if .debug_aranges section is present, |
48 // it may describe only a small subset of compilation units, so we need to | 51 // it may describe only a small subset of compilation units, so we need to |
49 // manually build aranges for the rest of them. | 52 // manually build aranges for the rest of them. |
50 for (const auto &CU : CTX->compile_units()) { | 53 for (const auto &CU : CTX->compile_units()) { |
51 uint32_t CUOffset = CU->getOffset(); | 54 uint32_t CUOffset = CU->getOffset(); |
52 if (ParsedCUOffsets.insert(CUOffset).second) { | 55 if (ParsedCUOffsets.insert(CUOffset).second) { |
53 DWARFAddressRangesVector CURanges; | 56 DWARFAddressRangesVector CURanges; |
54 CU->collectAddressRanges(CURanges); | 57 CU->collectAddressRanges(CURanges); |
55 for (const auto &R : CURanges) { | 58 for (const auto &R : CURanges) |
56 appendRange(CUOffset, R.first, R.second); | 59 appendRange(CUOffset, R.LowPC, R.HighPC); |
57 } | |
58 } | 60 } |
59 } | 61 } |
60 | 62 |
61 construct(); | 63 construct(); |
62 } | 64 } |
79 std::multiset<uint32_t> ValidCUs; // Maintain the set of CUs describing | 81 std::multiset<uint32_t> ValidCUs; // Maintain the set of CUs describing |
80 // a current address range. | 82 // a current address range. |
81 std::sort(Endpoints.begin(), Endpoints.end()); | 83 std::sort(Endpoints.begin(), Endpoints.end()); |
82 uint64_t PrevAddress = -1ULL; | 84 uint64_t PrevAddress = -1ULL; |
83 for (const auto &E : Endpoints) { | 85 for (const auto &E : Endpoints) { |
84 if (PrevAddress < E.Address && ValidCUs.size() > 0) { | 86 if (PrevAddress < E.Address && !ValidCUs.empty()) { |
85 // If the address range between two endpoints is described by some | 87 // If the address range between two endpoints is described by some |
86 // CU, first try to extend the last range in Aranges. If we can't | 88 // CU, first try to extend the last range in Aranges. If we can't |
87 // do it, start a new range. | 89 // do it, start a new range. |
88 if (!Aranges.empty() && Aranges.back().HighPC() == PrevAddress && | 90 if (!Aranges.empty() && Aranges.back().HighPC() == PrevAddress && |
89 ValidCUs.find(Aranges.back().CUOffset) != ValidCUs.end()) { | 91 ValidCUs.find(Aranges.back().CUOffset) != ValidCUs.end()) { |
103 PrevAddress = E.Address; | 105 PrevAddress = E.Address; |
104 } | 106 } |
105 assert(ValidCUs.empty()); | 107 assert(ValidCUs.empty()); |
106 | 108 |
107 // Endpoints are not needed now. | 109 // Endpoints are not needed now. |
108 std::vector<RangeEndpoint> EmptyEndpoints; | 110 Endpoints.clear(); |
109 EmptyEndpoints.swap(Endpoints); | 111 Endpoints.shrink_to_fit(); |
110 } | 112 } |
111 | 113 |
112 uint32_t DWARFDebugAranges::findAddress(uint64_t Address) const { | 114 uint32_t DWARFDebugAranges::findAddress(uint64_t Address) const { |
113 if (!Aranges.empty()) { | 115 if (!Aranges.empty()) { |
114 Range range(Address); | 116 Range range(Address); |