xref: /freebsd/contrib/llvm-project/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
10b57cec5SDimitry Andric //===- DWARFDebugAranges.h --------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
9fe6060f1SDimitry Andric #ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGARANGES_H
10fe6060f1SDimitry Andric #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGARANGES_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "llvm/ADT/DenseSet.h"
13*81ad6265SDimitry Andric #include "llvm/ADT/STLFunctionalExtras.h"
140b57cec5SDimitry Andric #include <cstdint>
150b57cec5SDimitry Andric #include <vector>
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric namespace llvm {
18*81ad6265SDimitry Andric class DWARFDataExtractor;
19*81ad6265SDimitry Andric class Error;
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric class DWARFContext;
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric class DWARFDebugAranges {
240b57cec5SDimitry Andric public:
250b57cec5SDimitry Andric   void generate(DWARFContext *CTX);
26480093f4SDimitry Andric   uint64_t findAddress(uint64_t Address) const;
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric private:
290b57cec5SDimitry Andric   void clear();
305ffd83dbSDimitry Andric   void extract(DWARFDataExtractor DebugArangesData,
31*81ad6265SDimitry Andric                function_ref<void(Error)> RecoverableErrorHandler,
32*81ad6265SDimitry Andric                function_ref<void(Error)> WarningHandler);
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric   /// Call appendRange multiple times and then call construct.
358bcb0991SDimitry Andric   void appendRange(uint64_t CUOffset, uint64_t LowPC, uint64_t HighPC);
360b57cec5SDimitry Andric   void construct();
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric   struct Range {
RangeRange395ffd83dbSDimitry Andric     explicit Range(uint64_t LowPC, uint64_t HighPC, uint64_t CUOffset)
400b57cec5SDimitry Andric       : LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {}
410b57cec5SDimitry Andric 
setHighPCRange420b57cec5SDimitry Andric     void setHighPC(uint64_t HighPC) {
430b57cec5SDimitry Andric       if (HighPC == -1ULL || HighPC <= LowPC)
440b57cec5SDimitry Andric         Length = 0;
450b57cec5SDimitry Andric       else
460b57cec5SDimitry Andric         Length = HighPC - LowPC;
470b57cec5SDimitry Andric     }
480b57cec5SDimitry Andric 
HighPCRange490b57cec5SDimitry Andric     uint64_t HighPC() const {
500b57cec5SDimitry Andric       if (Length)
510b57cec5SDimitry Andric         return LowPC + Length;
520b57cec5SDimitry Andric       return -1ULL;
530b57cec5SDimitry Andric     }
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric     bool operator<(const Range &other) const {
560b57cec5SDimitry Andric       return LowPC < other.LowPC;
570b57cec5SDimitry Andric     }
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric     uint64_t LowPC; /// Start of address range.
60480093f4SDimitry Andric     uint64_t Length; /// End of address range (not including this address).
61480093f4SDimitry Andric     uint64_t CUOffset; /// Offset of the compile unit or die.
620b57cec5SDimitry Andric   };
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric   struct RangeEndpoint {
650b57cec5SDimitry Andric     uint64_t Address;
668bcb0991SDimitry Andric     uint64_t CUOffset;
670b57cec5SDimitry Andric     bool IsRangeStart;
680b57cec5SDimitry Andric 
RangeEndpointRangeEndpoint698bcb0991SDimitry Andric     RangeEndpoint(uint64_t Address, uint64_t CUOffset, bool IsRangeStart)
700b57cec5SDimitry Andric         : Address(Address), CUOffset(CUOffset), IsRangeStart(IsRangeStart) {}
710b57cec5SDimitry Andric 
720b57cec5SDimitry Andric     bool operator<(const RangeEndpoint &Other) const {
730b57cec5SDimitry Andric       return Address < Other.Address;
740b57cec5SDimitry Andric     }
750b57cec5SDimitry Andric   };
760b57cec5SDimitry Andric 
770b57cec5SDimitry Andric   using RangeColl = std::vector<Range>;
780b57cec5SDimitry Andric   using RangeCollIterator = RangeColl::const_iterator;
790b57cec5SDimitry Andric 
800b57cec5SDimitry Andric   std::vector<RangeEndpoint> Endpoints;
810b57cec5SDimitry Andric   RangeColl Aranges;
828bcb0991SDimitry Andric   DenseSet<uint64_t> ParsedCUOffsets;
830b57cec5SDimitry Andric };
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric } // end namespace llvm
860b57cec5SDimitry Andric 
87fe6060f1SDimitry Andric #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGARANGES_H
88