DWARF: Port support for parsing .debug_aranges section from LLDB and wire it up to...
[oota-llvm.git] / lib / DebugInfo / DWARFDebugAranges.h
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)
25       : LoPC(lo), Length(hi-lo), Offset(off) {}
26
27     void clear() {
28       LoPC = -1ULL;
29       Length = 0;
30       Offset = -1U;
31     }
32
33     void setHiPC(uint64_t HiPC) {
34       if (HiPC == -1ULL || HiPC <= LoPC)
35         Length = 0;
36       else
37         Length = HiPC - LoPC;
38     }
39     uint64_t HiPC() const {
40       if (Length)
41         return LoPC + Length;
42       return -1ULL;
43     }
44     bool isValidRange() const { return Length > 0; }
45
46     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
53     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
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
68   // Use append range multiple times and then call sort
69   void appendRange(uint32_t cu_offset, uint64_t low_pc, uint64_t high_pc);
70   void sort(bool minimize, uint32_t n);
71
72   const Range *rangeAtIndex(uint32_t idx) const {
73     if (idx < Aranges.size())
74       return &Aranges[idx];
75     return NULL;
76   }
77   void dump(raw_ostream &OS) const;
78   uint32_t findAddress(uint64_t address) const;
79   bool isEmpty() const { return Aranges.empty(); }
80   uint32_t getNumRanges() const { return Aranges.size(); }
81
82   uint32_t offsetAtIndex(uint32_t idx) const {
83     if (idx < Aranges.size())
84       return Aranges[idx].Offset;
85     return -1U;
86   }
87
88   typedef std::vector<Range>              RangeColl;
89   typedef RangeColl::const_iterator       RangeCollIterator;
90
91 private:
92   RangeColl Aranges;
93 };
94
95 }
96
97 #endif