xref: /freebsd/contrib/llvm-project/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
1 //===- DWARFDebugAranges.h --------------------------------------*- C++ -*-===//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGARANGES_H
10 #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGARANGES_H
11 
12 #include "llvm/ADT/DenseSet.h"
13 #include "llvm/ADT/STLFunctionalExtras.h"
14 #include <cstdint>
15 #include <vector>
16 
17 namespace llvm {
18 class DWARFDataExtractor;
19 class Error;
20 
21 class DWARFContext;
22 
23 class DWARFDebugAranges {
24 public:
25   void generate(DWARFContext *CTX);
26   uint64_t findAddress(uint64_t Address) const;
27 
28 private:
29   void clear();
30   void extract(DWARFDataExtractor DebugArangesData,
31                function_ref<void(Error)> RecoverableErrorHandler,
32                function_ref<void(Error)> WarningHandler);
33 
34   /// Call appendRange multiple times and then call construct.
35   void appendRange(uint64_t CUOffset, uint64_t LowPC, uint64_t HighPC);
36   void construct();
37 
38   struct Range {
39     explicit Range(uint64_t LowPC, uint64_t HighPC, uint64_t CUOffset)
40       : LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {}
41 
42     void setHighPC(uint64_t HighPC) {
43       if (HighPC == -1ULL || HighPC <= LowPC)
44         Length = 0;
45       else
46         Length = HighPC - LowPC;
47     }
48 
49     uint64_t HighPC() const {
50       if (Length)
51         return LowPC + Length;
52       return -1ULL;
53     }
54 
55     bool operator<(const Range &other) const {
56       return LowPC < other.LowPC;
57     }
58 
59     uint64_t LowPC; /// Start of address range.
60     uint64_t Length; /// End of address range (not including this address).
61     uint64_t CUOffset; /// Offset of the compile unit or die.
62   };
63 
64   struct RangeEndpoint {
65     uint64_t Address;
66     uint64_t CUOffset;
67     bool IsRangeStart;
68 
69     RangeEndpoint(uint64_t Address, uint64_t CUOffset, bool IsRangeStart)
70         : Address(Address), CUOffset(CUOffset), IsRangeStart(IsRangeStart) {}
71 
72     bool operator<(const RangeEndpoint &Other) const {
73       return Address < Other.Address;
74     }
75   };
76 
77   using RangeColl = std::vector<Range>;
78   using RangeCollIterator = RangeColl::const_iterator;
79 
80   std::vector<RangeEndpoint> Endpoints;
81   RangeColl Aranges;
82   DenseSet<uint64_t> ParsedCUOffsets;
83 };
84 
85 } // end namespace llvm
86 
87 #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGARANGES_H
88