1 //===-- VMRange.h -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_VMRange_h_
11 #define liblldb_VMRange_h_
13 #include "lldb/lldb-types.h" // for addr_t
15 #include <stddef.h> // for size_t
16 #include <stdint.h> // for uint32_t
19 namespace lldb_private {
23 namespace lldb_private {
25 //----------------------------------------------------------------------
26 // A vm address range. These can represent offsets ranges or actual
28 //----------------------------------------------------------------------
31 typedef std::vector<VMRange> collection;
32 typedef collection::iterator iterator;
33 typedef collection::const_iterator const_iterator;
35 VMRange() : m_base_addr(0), m_byte_size(0) {}
37 VMRange(lldb::addr_t start_addr, lldb::addr_t end_addr)
38 : m_base_addr(start_addr),
39 m_byte_size(end_addr > start_addr ? end_addr - start_addr : 0) {}
48 // Set the start and end values
49 void Reset(lldb::addr_t start_addr, lldb::addr_t end_addr) {
50 SetBaseAddress(start_addr);
51 SetEndAddress(end_addr);
54 // Set the start value for the range, and keep the same size
55 void SetBaseAddress(lldb::addr_t base_addr) { m_base_addr = base_addr; }
57 void SetEndAddress(lldb::addr_t end_addr) {
58 const lldb::addr_t base_addr = GetBaseAddress();
59 if (end_addr > base_addr)
60 m_byte_size = end_addr - base_addr;
65 lldb::addr_t GetByteSize() const { return m_byte_size; }
67 void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }
69 lldb::addr_t GetBaseAddress() const { return m_base_addr; }
71 lldb::addr_t GetEndAddress() const { return GetBaseAddress() + m_byte_size; }
73 bool IsValid() const { return m_byte_size > 0; }
75 bool Contains(lldb::addr_t addr) const {
76 return (GetBaseAddress() <= addr) && (addr < GetEndAddress());
79 bool Contains(const VMRange &range) const {
80 if (Contains(range.GetBaseAddress())) {
81 lldb::addr_t range_end = range.GetEndAddress();
82 return (GetBaseAddress() <= range_end) && (range_end <= GetEndAddress());
87 void Dump(Stream *s, lldb::addr_t base_addr = 0,
88 uint32_t addr_width = 8) const;
90 class ValueInRangeUnaryPredicate {
92 ValueInRangeUnaryPredicate(lldb::addr_t value) : _value(value) {}
93 bool operator()(const VMRange &range) const {
94 return range.Contains(_value);
99 class RangeInRangeUnaryPredicate {
101 RangeInRangeUnaryPredicate(VMRange range) : _range(range) {}
102 bool operator()(const VMRange &range) const {
103 return range.Contains(_range);
105 const VMRange &_range;
108 static bool ContainsValue(const VMRange::collection &coll,
111 static bool ContainsRange(const VMRange::collection &coll,
112 const VMRange &range);
115 lldb::addr_t m_base_addr;
116 lldb::addr_t m_byte_size;
119 bool operator==(const VMRange &lhs, const VMRange &rhs);
120 bool operator!=(const VMRange &lhs, const VMRange &rhs);
121 bool operator<(const VMRange &lhs, const VMRange &rhs);
122 bool operator<=(const VMRange &lhs, const VMRange &rhs);
123 bool operator>(const VMRange &lhs, const VMRange &rhs);
124 bool operator>=(const VMRange &lhs, const VMRange &rhs);
126 } // namespace lldb_private
128 #endif // liblldb_VMRange_h_