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