blob: 31a8b462ef71048733c9b4f74f8b8b6c6b0f9d5b [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"
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020013#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010014#include <cstdint>
15#include <vector>
16
17namespace llvm {
18
19class DWARFContext;
20
21class DWARFDebugAranges {
22public:
23 void generate(DWARFContext *CTX);
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020024 uint64_t findAddress(uint64_t Address) const;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010025
26private:
27 void clear();
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020028 void extract(DWARFDataExtractor DebugArangesData,
29 function_ref<void(Error)> RecoverableErrorHandler);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010030
31 /// Call appendRange multiple times and then call construct.
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020032 void appendRange(uint64_t CUOffset, uint64_t LowPC, uint64_t HighPC);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010033 void construct();
34
35 struct Range {
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020036 explicit Range(uint64_t LowPC, uint64_t HighPC, uint64_t CUOffset)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010037 : 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010052 bool operator<(const Range &other) const {
53 return LowPC < other.LowPC;
54 }
55
56 uint64_t LowPC; /// Start of address range.
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020057 uint64_t Length; /// End of address range (not including this address).
58 uint64_t CUOffset; /// Offset of the compile unit or die.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010059 };
60
61 struct RangeEndpoint {
62 uint64_t Address;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020063 uint64_t CUOffset;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010064 bool IsRangeStart;
65
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020066 RangeEndpoint(uint64_t Address, uint64_t CUOffset, bool IsRangeStart)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010067 : Address(Address), CUOffset(CUOffset), IsRangeStart(IsRangeStart) {}
68
69 bool operator<(const RangeEndpoint &Other) const {
70 return Address < Other.Address;
71 }
72 };
73
74 using RangeColl = std::vector<Range>;
75 using RangeCollIterator = RangeColl::const_iterator;
76
77 std::vector<RangeEndpoint> Endpoints;
78 RangeColl Aranges;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020079 DenseSet<uint64_t> ParsedCUOffsets;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010080};
81
82} // end namespace llvm
83
84#endif // LLVM_DEBUGINFO_DWARFDEBUGARANGES_H