1 //===-- DWARFDebugAranges.h -------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_DEBUGINFO_DWARFDEBUGARANGES_H 11 #define LLVM_DEBUGINFO_DWARFDEBUGARANGES_H 12 13 #include "DWARFDebugArangeSet.h" 14 #include <list> 15 16 namespace llvm { 17 18 class DWARFContext; 19 20 class DWARFDebugAranges { 21 public: 22 struct Range { 23 explicit Range(uint64_t lo = -1ULL, uint64_t hi = -1ULL, 24 uint32_t off = -1U) LoPCRange25 : LoPC(lo), Length(hi-lo), Offset(off) {} 26 clearRange27 void clear() { 28 LoPC = -1ULL; 29 Length = 0; 30 Offset = -1U; 31 } 32 setHiPCRange33 void setHiPC(uint64_t HiPC) { 34 if (HiPC == -1ULL || HiPC <= LoPC) 35 Length = 0; 36 else 37 Length = HiPC - LoPC; 38 } HiPCRange39 uint64_t HiPC() const { 40 if (Length) 41 return LoPC + Length; 42 return -1ULL; 43 } isValidRangeRange44 bool isValidRange() const { return Length > 0; } 45 SortedOverlapCheckRange46 static bool SortedOverlapCheck(const Range &curr_range, 47 const Range &next_range, uint32_t n) { 48 if (curr_range.Offset != next_range.Offset) 49 return false; 50 return curr_range.HiPC() + n >= next_range.LoPC; 51 } 52 containsRange53 bool contains(const Range &range) const { 54 return LoPC <= range.LoPC && range.HiPC() <= HiPC(); 55 } 56 57 void dump(raw_ostream &OS) const; 58 uint64_t LoPC; // Start of address range 59 uint32_t Length; // End of address range (not including this address) 60 uint32_t Offset; // Offset of the compile unit or die 61 }; 62 clear()63 void clear() { Aranges.clear(); } 64 bool allRangesAreContiguous(uint64_t& LoPC, uint64_t& HiPC) const; 65 bool getMaxRange(uint64_t& LoPC, uint64_t& HiPC) const; 66 bool extract(DataExtractor debug_aranges_data); 67 bool generate(DWARFContext *ctx); 68 69 // Use append range multiple times and then call sort 70 void appendRange(uint32_t cu_offset, uint64_t low_pc, uint64_t high_pc); 71 void sort(bool minimize, uint32_t n); 72 rangeAtIndex(uint32_t idx)73 const Range *rangeAtIndex(uint32_t idx) const { 74 if (idx < Aranges.size()) 75 return &Aranges[idx]; 76 return NULL; 77 } 78 void dump(raw_ostream &OS) const; 79 uint32_t findAddress(uint64_t address) const; isEmpty()80 bool isEmpty() const { return Aranges.empty(); } getNumRanges()81 uint32_t getNumRanges() const { return Aranges.size(); } 82 offsetAtIndex(uint32_t idx)83 uint32_t offsetAtIndex(uint32_t idx) const { 84 if (idx < Aranges.size()) 85 return Aranges[idx].Offset; 86 return -1U; 87 } 88 89 typedef std::vector<Range> RangeColl; 90 typedef RangeColl::const_iterator RangeCollIterator; 91 92 private: 93 RangeColl Aranges; 94 }; 95 96 } 97 98 #endif 99