1 //===- DWARFDebugRangeList.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_DWARF_DWARFDEBUGRANGELIST_H 11 #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGRANGELIST_H 12 13 #include "llvm/Support/DataExtractor.h" 14 #include <cassert> 15 #include <cstdint> 16 #include <utility> 17 #include <vector> 18 19 namespace llvm { 20 21 class raw_ostream; 22 23 /// DWARFAddressRangesVector - represents a set of absolute address ranges. 24 typedef std::vector<std::pair<uint64_t, uint64_t>> DWARFAddressRangesVector; 25 26 class DWARFDebugRangeList { 27 public: 28 struct RangeListEntry { 29 // A beginning address offset. This address offset has the size of an 30 // address and is relative to the applicable base address of the 31 // compilation unit referencing this range list. It marks the beginning 32 // of an address range. 33 uint64_t StartAddress; 34 // An ending address offset. This address offset again has the size of 35 // an address and is relative to the applicable base address of the 36 // compilation unit referencing this range list. It marks the first 37 // address past the end of the address range. The ending address must 38 // be greater than or equal to the beginning address. 39 uint64_t EndAddress; 40 41 // The end of any given range list is marked by an end of list entry, 42 // which consists of a 0 for the beginning address offset 43 // and a 0 for the ending address offset. 44 bool isEndOfListEntry() const { 45 return (StartAddress == 0) && (EndAddress == 0); 46 } 47 48 // A base address selection entry consists of: 49 // 1. The value of the largest representable address offset 50 // (for example, 0xffffffff when the size of an address is 32 bits). 51 // 2. An address, which defines the appropriate base address for 52 // use in interpreting the beginning and ending address offsets of 53 // subsequent entries of the location list. 54 bool isBaseAddressSelectionEntry(uint8_t AddressSize) const { 55 assert(AddressSize == 4 || AddressSize == 8); 56 if (AddressSize == 4) 57 return StartAddress == -1U; 58 else 59 return StartAddress == -1ULL; 60 } 61 }; 62 63 private: 64 // Offset in .debug_ranges section. 65 uint32_t Offset; 66 uint8_t AddressSize; 67 std::vector<RangeListEntry> Entries; 68 69 public: 70 DWARFDebugRangeList() { clear(); } 71 72 void clear(); 73 void dump(raw_ostream &OS) const; 74 bool extract(DataExtractor data, uint32_t *offset_ptr); 75 const std::vector<RangeListEntry> &getEntries() { return Entries; } 76 77 /// getAbsoluteRanges - Returns absolute address ranges defined by this range 78 /// list. Has to be passed base address of the compile unit referencing this 79 /// range list. 80 DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress) const; 81 }; 82 83 } // end namespace llvm 84 85 #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGRANGELIST_H 86