• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- DWARFAddressRange.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_DWARF_DWARFADDRESSRANGE_H
11 #define LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
12 
13 #include "llvm/DebugInfo/DIContext.h"
14 #include <cstdint>
15 #include <tuple>
16 #include <vector>
17 
18 namespace llvm {
19 
20 class raw_ostream;
21 
22 struct DWARFAddressRange {
23   uint64_t LowPC;
24   uint64_t HighPC;
25   uint64_t SectionIndex;
26 
27   DWARFAddressRange() = default;
28 
29   /// Used for unit testing.
30   DWARFAddressRange(uint64_t LowPC, uint64_t HighPC, uint64_t SectionIndex = 0)
LowPCDWARFAddressRange31       : LowPC(LowPC), HighPC(HighPC), SectionIndex(SectionIndex) {}
32 
33   /// Returns true if LowPC is smaller or equal to HighPC. This accounts for
34   /// dead-stripped ranges.
validDWARFAddressRange35   bool valid() const { return LowPC <= HighPC; }
36 
37   /// Returns true if [LowPC, HighPC) intersects with [RHS.LowPC, RHS.HighPC).
intersectsDWARFAddressRange38   bool intersects(const DWARFAddressRange &RHS) const {
39     assert(valid() && RHS.valid());
40     // Empty ranges can't intersect.
41     if (LowPC == HighPC || RHS.LowPC == RHS.HighPC)
42       return false;
43     return LowPC < RHS.HighPC && RHS.LowPC < HighPC;
44   }
45 
46   /// Returns true if [LowPC, HighPC) fully contains [RHS.LowPC, RHS.HighPC).
containsDWARFAddressRange47   bool contains(const DWARFAddressRange &RHS) const {
48     assert(valid() && RHS.valid());
49     return LowPC <= RHS.LowPC && RHS.HighPC <= HighPC;
50   }
51 
52   void dump(raw_ostream &OS, uint32_t AddressSize,
53             DIDumpOptions DumpOpts = {}) const;
54 };
55 
56 static inline bool operator<(const DWARFAddressRange &LHS,
57                              const DWARFAddressRange &RHS) {
58   return std::tie(LHS.LowPC, LHS.HighPC) < std::tie(RHS.LowPC, RHS.HighPC);
59 }
60 
61 raw_ostream &operator<<(raw_ostream &OS, const DWARFAddressRange &R);
62 
63 /// DWARFAddressRangesVector - represents a set of absolute address ranges.
64 using DWARFAddressRangesVector = std::vector<DWARFAddressRange>;
65 
66 } // end namespace llvm
67 
68 #endif // LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
69