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-private.h"
16 namespace lldb_private {
18 //----------------------------------------------------------------------
19 // A vm address range. These can represent offsets ranges or actual
21 //----------------------------------------------------------------------
26 typedef std::vector<VMRange> collection;
27 typedef collection::iterator iterator;
28 typedef collection::const_iterator const_iterator;
36 VMRange(lldb::addr_t start_addr, lldb::addr_t end_addr) :
37 m_base_addr(start_addr),
38 m_byte_size(end_addr > start_addr ? end_addr - start_addr : 0)
53 // Set the start and end values
55 Reset (lldb::addr_t start_addr, lldb::addr_t end_addr)
57 SetBaseAddress (start_addr);
58 SetEndAddress (end_addr);
61 // Set the start value for the range, and keep the same size
63 SetBaseAddress (lldb::addr_t base_addr)
65 m_base_addr = base_addr;
69 SetEndAddress (lldb::addr_t end_addr)
71 const lldb::addr_t base_addr = GetBaseAddress();
72 if (end_addr > base_addr)
73 m_byte_size = end_addr - base_addr;
85 SetByteSize (lldb::addr_t byte_size)
87 m_byte_size = byte_size;
91 GetBaseAddress () const
97 GetEndAddress () const
99 return GetBaseAddress() + m_byte_size;
105 return m_byte_size > 0;
109 Contains (lldb::addr_t addr) const
111 return (GetBaseAddress() <= addr) && (addr < GetEndAddress());
115 Contains (const VMRange& range) const
117 if (Contains(range.GetBaseAddress()))
119 lldb::addr_t range_end = range.GetEndAddress();
120 return (GetBaseAddress() <= range_end) && (range_end <= GetEndAddress());
126 Dump (Stream *s, lldb::addr_t base_addr = 0, uint32_t addr_width = 8) const;
128 class ValueInRangeUnaryPredicate
131 ValueInRangeUnaryPredicate(lldb::addr_t value) :
135 bool operator()(const VMRange& range) const
137 return range.Contains(_value);
142 class RangeInRangeUnaryPredicate
145 RangeInRangeUnaryPredicate(VMRange range) :
149 bool operator()(const VMRange& range) const
151 return range.Contains(_range);
153 const VMRange& _range;
157 ContainsValue(const VMRange::collection& coll, lldb::addr_t value);
160 ContainsRange(const VMRange::collection& coll, const VMRange& range);
162 // Returns a valid index into coll when a match is found, else UINT32_MAX
165 FindRangeIndexThatContainsValue (const VMRange::collection& coll, lldb::addr_t value);
168 lldb::addr_t m_base_addr;
169 lldb::addr_t m_byte_size;
172 bool operator== (const VMRange& lhs, const VMRange& rhs);
173 bool operator!= (const VMRange& lhs, const VMRange& rhs);
174 bool operator< (const VMRange& lhs, const VMRange& rhs);
175 bool operator<= (const VMRange& lhs, const VMRange& rhs);
176 bool operator> (const VMRange& lhs, const VMRange& rhs);
177 bool operator>= (const VMRange& lhs, const VMRange& rhs);
179 } // namespace lldb_private
181 #endif // liblldb_VMRange_h_