blob: 1509ffad41f1d0d8fce4c63a60367b1862b47feb [file] [log] [blame]
Benjamin Kramer358f4fd2011-09-14 01:09:52 +00001//===-- 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"
Alexey Samsonov63a450a2012-11-16 08:36:25 +000014#include "llvm/ADT/DenseSet.h"
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000015#include <list>
16
17namespace llvm {
18
19class DWARFContext;
20
21class DWARFDebugAranges {
22public:
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
Alexey Samsonov63a450a2012-11-16 08:36:25 +000064 void clear() {
65 Aranges.clear();
66 ParsedCUOffsets.clear();
67 }
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000068 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);
Benjamin Kramer10df8062011-09-14 20:52:27 +000071 bool generate(DWARFContext *ctx);
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000072
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;
Alexey Samsonov63a450a2012-11-16 08:36:25 +000095 typedef DenseSet<uint32_t> ParsedCUOffsetColl;
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000096
97private:
98 RangeColl Aranges;
Alexey Samsonov63a450a2012-11-16 08:36:25 +000099 ParsedCUOffsetColl ParsedCUOffsets;
Benjamin Kramer358f4fd2011-09-14 01:09:52 +0000100};
101
102}
103
104#endif