Home | History | Annotate | Download | only in DebugInfo
      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 "llvm/ADT/DenseSet.h"
     15 #include <list>
     16 
     17 namespace llvm {
     18 
     19 class DWARFContext;
     20 
     21 class DWARFDebugAranges {
     22 public:
     23   struct Range {
     24     explicit Range(uint64_t lo = -1ULL, uint64_t hi = -1ULL,
     25                    uint32_t off = -1U)
     26       : LoPC(lo), Length(hi-lo), Offset(off) {}
     27 
     28     void clear() {
     29       LoPC = -1ULL;
     30       Length = 0;
     31       Offset = -1U;
     32     }
     33 
     34     void setHiPC(uint64_t HiPC) {
     35       if (HiPC == -1ULL || HiPC <= LoPC)
     36         Length = 0;
     37       else
     38         Length = HiPC - LoPC;
     39     }
     40     uint64_t HiPC() const {
     41       if (Length)
     42         return LoPC + Length;
     43       return -1ULL;
     44     }
     45     bool isValidRange() const { return Length > 0; }
     46 
     47     static bool SortedOverlapCheck(const Range &curr_range,
     48                                    const Range &next_range, uint32_t n) {
     49       if (curr_range.Offset != next_range.Offset)
     50         return false;
     51       return curr_range.HiPC() + n >= next_range.LoPC;
     52     }
     53 
     54     bool contains(const Range &range) const {
     55       return LoPC <= range.LoPC && range.HiPC() <= HiPC();
     56     }
     57 
     58     void dump(raw_ostream &OS) const;
     59     uint64_t LoPC; // Start of address range
     60     uint32_t Length; // End of address range (not including this address)
     61     uint32_t Offset; // Offset of the compile unit or die
     62   };
     63 
     64   void clear() {
     65     Aranges.clear();
     66     ParsedCUOffsets.clear();
     67   }
     68   bool allRangesAreContiguous(uint64_t& LoPC, uint64_t& HiPC) const;
     69   bool getMaxRange(uint64_t& LoPC, uint64_t& HiPC) const;
     70   bool extract(DataExtractor debug_aranges_data);
     71   bool generate(DWARFContext *ctx);
     72 
     73   // Use append range multiple times and then call sort
     74   void appendRange(uint32_t cu_offset, uint64_t low_pc, uint64_t high_pc);
     75   void sort(bool minimize, uint32_t n);
     76 
     77   const Range *rangeAtIndex(uint32_t idx) const {
     78     if (idx < Aranges.size())
     79       return &Aranges[idx];
     80     return NULL;
     81   }
     82   void dump(raw_ostream &OS) const;
     83   uint32_t findAddress(uint64_t address) const;
     84   bool isEmpty() const { return Aranges.empty(); }
     85   uint32_t getNumRanges() const { return Aranges.size(); }
     86 
     87   uint32_t offsetAtIndex(uint32_t idx) const {
     88     if (idx < Aranges.size())
     89       return Aranges[idx].Offset;
     90     return -1U;
     91   }
     92 
     93   typedef std::vector<Range>              RangeColl;
     94   typedef RangeColl::const_iterator       RangeCollIterator;
     95   typedef DenseSet<uint32_t>              ParsedCUOffsetColl;
     96 
     97 private:
     98   RangeColl Aranges;
     99   ParsedCUOffsetColl ParsedCUOffsets;
    100 };
    101 
    102 }
    103 
    104 #endif
    105