llvm.org GIT mirror llvm / d1fc0f8
[DebugInfo] Remove unused functions from DWARFDebugAranges and fix code style. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191778 91177308-0d34-0410-b5e6-96231b3b80d8 Alexey Samsonov 6 years ago
2 changed file(s) with 42 addition(s) and 91 deletion(s). Raw diff Collapse all Expand all
6262 };
6363 }
6464
65 bool DWARFDebugAranges::extract(DataExtractor debug_aranges_data) {
66 if (debug_aranges_data.isValidOffset(0)) {
67 uint32_t offset = 0;
65 void DWARFDebugAranges::extract(DataExtractor DebugArangesData) {
66 if (!DebugArangesData.isValidOffset(0))
67 return;
68 uint32_t offset = 0;
6869
69 typedef std::vector SetCollection;
70 SetCollection sets;
70 typedef std::vector SetCollection;
71 SetCollection sets;
7172
72 DWARFDebugArangeSet set;
73 Range range;
74 while (set.extract(debug_aranges_data, &offset))
75 sets.push_back(set);
73 DWARFDebugArangeSet set;
74 Range range;
75 while (set.extract(DebugArangesData, &offset))
76 sets.push_back(set);
7677
77 uint32_t count = 0;
78 uint32_t count = 0;
7879
79 std::for_each(sets.begin(), sets.end(), CountArangeDescriptors(count));
80 std::for_each(sets.begin(), sets.end(), CountArangeDescriptors(count));
8081
81 if (count > 0) {
82 Aranges.reserve(count);
83 AddArangeDescriptors range_adder(Aranges, ParsedCUOffsets);
84 std::for_each(sets.begin(), sets.end(), range_adder);
85 }
82 if (count > 0) {
83 Aranges.reserve(count);
84 AddArangeDescriptors range_adder(Aranges, ParsedCUOffsets);
85 std::for_each(sets.begin(), sets.end(), range_adder);
8686 }
87 return false;
8887 }
8988
90 bool DWARFDebugAranges::generate(DWARFContext *ctx) {
91 if (ctx) {
92 const uint32_t num_compile_units = ctx->getNumCompileUnits();
89 void DWARFDebugAranges::generate(DWARFContext *CTX) {
90 if (CTX) {
91 const uint32_t num_compile_units = CTX->getNumCompileUnits();
9392 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
94 if (DWARFCompileUnit *cu = ctx->getCompileUnitAtIndex(cu_idx)) {
93 if (DWARFCompileUnit *cu = CTX->getCompileUnitAtIndex(cu_idx)) {
9594 uint32_t CUOffset = cu->getOffset();
9695 if (ParsedCUOffsets.insert(CUOffset).second)
9796 cu->buildAddressRangeTable(this, true, CUOffset);
9998 }
10099 }
101100 sort(true, /* overlap size */ 0);
102 return !isEmpty();
103101 }
104102
105103 void DWARFDebugAranges::dump(raw_ostream &OS) const {
106 const uint32_t num_ranges = getNumRanges();
107 for (uint32_t i = 0; i < num_ranges; ++i) {
108 const Range &range = Aranges[i];
109 OS << format("0x%8.8x: [0x%8.8" PRIx64 " - 0x%8.8" PRIx64 ")\n",
110 range.Offset, (uint64_t)range.LoPC, (uint64_t)range.HiPC());
104 for (RangeCollIterator I = Aranges.begin(), E = Aranges.end(); I != E; ++I) {
105 I->dump(OS);
111106 }
112107 }
113108
116111 Offset, LoPC, HiPC());
117112 }
118113
119 void DWARFDebugAranges::appendRange(uint32_t offset, uint64_t low_pc,
120 uint64_t high_pc) {
114 void DWARFDebugAranges::appendRange(uint32_t CUOffset, uint64_t LowPC,
115 uint64_t HighPC) {
121116 if (!Aranges.empty()) {
122 if (Aranges.back().Offset == offset && Aranges.back().HiPC() == low_pc) {
123 Aranges.back().setHiPC(high_pc);
117 if (Aranges.back().Offset == CUOffset && Aranges.back().HiPC() == LowPC) {
118 Aranges.back().setHiPC(HighPC);
124119 return;
125120 }
126121 }
127 Aranges.push_back(Range(low_pc, high_pc, offset));
122 Aranges.push_back(Range(LowPC, HighPC, CUOffset));
128123 }
129124
130 void DWARFDebugAranges::sort(bool minimize, uint32_t n) {
125 void DWARFDebugAranges::sort(bool Minimize, uint32_t OverlapSize) {
131126 const size_t orig_arange_size = Aranges.size();
132127 // Size of one? If so, no sorting is needed
133128 if (orig_arange_size <= 1)
135130 // Sort our address range entries
136131 std::stable_sort(Aranges.begin(), Aranges.end(), RangeLessThan);
137132
138 if (!minimize)
133 if (!Minimize)
139134 return;
140135
141136 // Most address ranges are contiguous from function to function
150145 // copy the new minimal stuff over to the new collection.
151146 size_t minimal_size = 1;
152147 for (size_t i = 1; i < orig_arange_size; ++i) {
153 if (!Range::SortedOverlapCheck(Aranges[i-1], Aranges[i], n))
148 if (!Range::SortedOverlapCheck(Aranges[i-1], Aranges[i], OverlapSize))
154149 ++minimal_size;
155150 }
156151
165160 uint32_t j = 0;
166161 minimal_aranges[j] = Aranges[0];
167162 for (size_t i = 1; i < orig_arange_size; ++i) {
168 if(Range::SortedOverlapCheck (minimal_aranges[j], Aranges[i], n)) {
163 if (Range::SortedOverlapCheck(minimal_aranges[j], Aranges[i],
164 OverlapSize)) {
169165 minimal_aranges[j].setHiPC (Aranges[i].HiPC());
170166 } else {
171167 // Only increment j if we aren't merging
180176 minimal_aranges.swap(Aranges);
181177 }
182178
183 uint32_t DWARFDebugAranges::findAddress(uint64_t address) const {
179 uint32_t DWARFDebugAranges::findAddress(uint64_t Address) const {
184180 if (!Aranges.empty()) {
185 Range range(address);
181 Range range(Address);
186182 RangeCollIterator begin = Aranges.begin();
187183 RangeCollIterator end = Aranges.end();
188184 RangeCollIterator pos = std::lower_bound(begin, end, range, RangeLessThan);
189185
190 if (pos != end && pos->LoPC <= address && address < pos->HiPC()) {
186 if (pos != end && pos->LoPC <= Address && Address < pos->HiPC()) {
191187 return pos->Offset;
192188 } else if (pos != begin) {
193189 --pos;
194 if (pos->LoPC <= address && address < pos->HiPC())
190 if (pos->LoPC <= Address && Address < pos->HiPC())
195191 return (*pos).Offset;
196192 }
197193 }
198194 return -1U;
199195 }
200
201 bool
202 DWARFDebugAranges::allRangesAreContiguous(uint64_t &LoPC, uint64_t &HiPC) const{
203 if (Aranges.empty())
204 return false;
205
206 uint64_t next_addr = 0;
207 RangeCollIterator begin = Aranges.begin();
208 for (RangeCollIterator pos = begin, end = Aranges.end(); pos != end;
209 ++pos) {
210 if (pos != begin && pos->LoPC != next_addr)
211 return false;
212 next_addr = pos->HiPC();
213 }
214 // We checked for empty at the start of function so front() will be valid.
215 LoPC = Aranges.front().LoPC;
216 // We checked for empty at the start of function so back() will be valid.
217 HiPC = Aranges.back().HiPC();
218 return true;
219 }
220
221 bool DWARFDebugAranges::getMaxRange(uint64_t &LoPC, uint64_t &HiPC) const {
222 if (Aranges.empty())
223 return false;
224 // We checked for empty at the start of function so front() will be valid.
225 LoPC = Aranges.front().LoPC;
226 // We checked for empty at the start of function so back() will be valid.
227 HiPC = Aranges.back().HiPC();
228 return true;
229 }
6464 Aranges.clear();
6565 ParsedCUOffsets.clear();
6666 }
67 bool allRangesAreContiguous(uint64_t& LoPC, uint64_t& HiPC) const;
68 bool getMaxRange(uint64_t& LoPC, uint64_t& HiPC) const;
69 bool extract(DataExtractor debug_aranges_data);
70 bool generate(DWARFContext *ctx);
67 void extract(DataExtractor DebugArangesData);
68 void generate(DWARFContext *CTX);
7169
72 // Use append range multiple times and then call sort
73 void appendRange(uint32_t cu_offset, uint64_t low_pc, uint64_t high_pc);
74 void sort(bool minimize, uint32_t n);
70 // Use appendRange multiple times and then call sort.
71 void appendRange(uint32_t CUOffset, uint64_t LowPC, uint64_t HighPC);
72 void sort(bool Minimize, uint32_t OverlapSize);
7573
76 const Range *rangeAtIndex(uint32_t idx) const {
77 if (idx < Aranges.size())
78 return &Aranges[idx];
79 return NULL;
80 }
8174 void dump(raw_ostream &OS) const;
82 uint32_t findAddress(uint64_t address) const;
83 bool isEmpty() const { return Aranges.empty(); }
84 uint32_t getNumRanges() const { return Aranges.size(); }
85
86 uint32_t offsetAtIndex(uint32_t idx) const {
87 if (idx < Aranges.size())
88 return Aranges[idx].Offset;
89 return -1U;
90 }
75 uint32_t findAddress(uint64_t Address) const;
9176
9277 typedef std::vector RangeColl;
9378 typedef RangeColl::const_iterator RangeCollIterator;