File indexing completed on 2026-05-10 08:43:41
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
0010 #define LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
0011
0012 #include "llvm/DebugInfo/DIContext.h"
0013 #include "llvm/Object/ObjectFile.h"
0014 #include <algorithm>
0015 #include <cassert>
0016 #include <cstdint>
0017 #include <tuple>
0018 #include <vector>
0019
0020 namespace llvm {
0021
0022 class raw_ostream;
0023 class DWARFObject;
0024
0025 struct DWARFAddressRange {
0026 uint64_t LowPC;
0027 uint64_t HighPC;
0028 uint64_t SectionIndex;
0029
0030 DWARFAddressRange() = default;
0031
0032
0033 DWARFAddressRange(
0034 uint64_t LowPC, uint64_t HighPC,
0035 uint64_t SectionIndex = object::SectionedAddress::UndefSection)
0036 : LowPC(LowPC), HighPC(HighPC), SectionIndex(SectionIndex) {}
0037
0038
0039
0040 bool valid() const { return LowPC <= HighPC; }
0041
0042
0043 bool intersects(const DWARFAddressRange &RHS) const {
0044 assert(valid() && RHS.valid());
0045 if (SectionIndex != RHS.SectionIndex)
0046 return false;
0047
0048 if (LowPC == HighPC || RHS.LowPC == RHS.HighPC)
0049 return false;
0050 return LowPC < RHS.HighPC && RHS.LowPC < HighPC;
0051 }
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 bool merge(const DWARFAddressRange &RHS) {
0064 if (!intersects(RHS))
0065 return false;
0066 LowPC = std::min<uint64_t>(LowPC, RHS.LowPC);
0067 HighPC = std::max<uint64_t>(HighPC, RHS.HighPC);
0068 return true;
0069 }
0070
0071 void dump(raw_ostream &OS, uint32_t AddressSize, DIDumpOptions DumpOpts = {},
0072 const DWARFObject *Obj = nullptr) const;
0073 };
0074
0075 inline bool operator<(const DWARFAddressRange &LHS,
0076 const DWARFAddressRange &RHS) {
0077 return std::tie(LHS.SectionIndex, LHS.LowPC, LHS.HighPC) < std::tie(RHS.SectionIndex, RHS.LowPC, RHS.HighPC);
0078 }
0079
0080 inline bool operator==(const DWARFAddressRange &LHS,
0081 const DWARFAddressRange &RHS) {
0082 return std::tie(LHS.SectionIndex, LHS.LowPC, LHS.HighPC) == std::tie(RHS.SectionIndex, RHS.LowPC, RHS.HighPC);
0083 }
0084
0085 raw_ostream &operator<<(raw_ostream &OS, const DWARFAddressRange &R);
0086
0087
0088 using DWARFAddressRangesVector = std::vector<DWARFAddressRange>;
0089
0090 }
0091
0092 #endif