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_LIB_DEBUGINFO_DWARFDEBUGARANGES_H 11 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGES_H 12 13 #include "llvm/ADT/DenseSet.h" 14 #include "llvm/Support/DataExtractor.h" 15 #include <vector> 16 17 namespace llvm { 18 19 class DWARFContext; 20 21 class DWARFDebugAranges { 22 public: 23 void generate(DWARFContext *CTX); 24 uint32_t findAddress(uint64_t Address) const; 25 26 private: 27 void clear(); 28 void extract(DataExtractor DebugArangesData); 29 30 // Call appendRange multiple times and then call construct. 31 void appendRange(uint32_t CUOffset, uint64_t LowPC, uint64_t HighPC); 32 void construct(); 33 34 struct Range { 35 explicit Range(uint64_t LowPC = -1ULL, uint64_t HighPC = -1ULL, 36 uint32_t CUOffset = -1U) 37 : LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {} 38 39 void setHighPC(uint64_t HighPC) { 40 if (HighPC == -1ULL || HighPC <= LowPC) 41 Length = 0; 42 else 43 Length = HighPC - LowPC; 44 } 45 uint64_t HighPC() const { 46 if (Length) 47 return LowPC + Length; 48 return -1ULL; 49 } 50 51 bool containsAddress(uint64_t Address) const { 52 return LowPC <= Address && Address < HighPC(); 53 } 54 bool operator<(const Range &other) const { 55 return LowPC < other.LowPC; 56 } 57 58 uint64_t LowPC; // Start of address range. 59 uint32_t Length; // End of address range (not including this address). 60 uint32_t CUOffset; // Offset of the compile unit or die. 61 }; 62 63 struct RangeEndpoint { 64 uint64_t Address; 65 uint32_t CUOffset; 66 bool IsRangeStart; 67 68 RangeEndpoint(uint64_t Address, uint32_t CUOffset, bool IsRangeStart) 69 : Address(Address), CUOffset(CUOffset), IsRangeStart(IsRangeStart) {} 70 71 bool operator<(const RangeEndpoint &Other) const { 72 return Address < Other.Address; 73 } 74 }; 75 76 77 typedef std::vector<Range> RangeColl; 78 typedef RangeColl::const_iterator RangeCollIterator; 79 80 std::vector<RangeEndpoint> Endpoints; 81 RangeColl Aranges; 82 DenseSet<uint32_t> ParsedCUOffsets; 83 }; 84 85 } 86 87 #endif 88