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