File indexing completed on 2026-05-10 08:42:59
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_UTILITY_VMRANGE_H
0010 #define LLDB_UTILITY_VMRANGE_H
0011
0012 #include "lldb/lldb-types.h"
0013 #include "llvm/Support/raw_ostream.h"
0014
0015 #include <cstddef>
0016 #include <cstdint>
0017 #include <vector>
0018
0019 namespace lldb_private {
0020
0021
0022
0023 class VMRange {
0024 public:
0025 typedef std::vector<VMRange> collection;
0026 typedef collection::iterator iterator;
0027 typedef collection::const_iterator const_iterator;
0028
0029 VMRange() = default;
0030
0031 VMRange(lldb::addr_t start_addr, lldb::addr_t end_addr)
0032 : m_base_addr(start_addr),
0033 m_byte_size(end_addr > start_addr ? end_addr - start_addr : 0) {}
0034
0035 ~VMRange() = default;
0036
0037 void Clear() {
0038 m_base_addr = 0;
0039 m_byte_size = 0;
0040 }
0041
0042
0043 void Reset(lldb::addr_t start_addr, lldb::addr_t end_addr) {
0044 SetBaseAddress(start_addr);
0045 SetEndAddress(end_addr);
0046 }
0047
0048
0049 void SetBaseAddress(lldb::addr_t base_addr) { m_base_addr = base_addr; }
0050
0051 void SetEndAddress(lldb::addr_t end_addr) {
0052 const lldb::addr_t base_addr = GetBaseAddress();
0053 if (end_addr > base_addr)
0054 m_byte_size = end_addr - base_addr;
0055 else
0056 m_byte_size = 0;
0057 }
0058
0059 lldb::addr_t GetByteSize() const { return m_byte_size; }
0060
0061 void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }
0062
0063 lldb::addr_t GetBaseAddress() const { return m_base_addr; }
0064
0065 lldb::addr_t GetEndAddress() const { return GetBaseAddress() + m_byte_size; }
0066
0067 bool IsValid() const { return m_byte_size > 0; }
0068
0069 bool Contains(lldb::addr_t addr) const {
0070 return (GetBaseAddress() <= addr) && (addr < GetEndAddress());
0071 }
0072
0073 bool Contains(const VMRange &range) const {
0074 if (Contains(range.GetBaseAddress())) {
0075 lldb::addr_t range_end = range.GetEndAddress();
0076 return (GetBaseAddress() <= range_end) && (range_end <= GetEndAddress());
0077 }
0078 return false;
0079 }
0080
0081 void Dump(llvm::raw_ostream &s, lldb::addr_t base_addr = 0,
0082 uint32_t addr_width = 8) const;
0083
0084 static bool ContainsValue(const VMRange::collection &coll,
0085 lldb::addr_t value);
0086
0087 static bool ContainsRange(const VMRange::collection &coll,
0088 const VMRange &range);
0089
0090 protected:
0091 lldb::addr_t m_base_addr = 0;
0092 lldb::addr_t m_byte_size = 0;
0093 };
0094
0095 bool operator==(const VMRange &lhs, const VMRange &rhs);
0096 bool operator!=(const VMRange &lhs, const VMRange &rhs);
0097 bool operator<(const VMRange &lhs, const VMRange &rhs);
0098 bool operator<=(const VMRange &lhs, const VMRange &rhs);
0099 bool operator>(const VMRange &lhs, const VMRange &rhs);
0100 bool operator>=(const VMRange &lhs, const VMRange &rhs);
0101
0102 }
0103
0104 #endif