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"
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 static bool ContainsValue(const VMRange::collection &coll,
93 static bool ContainsRange(const VMRange::collection &coll,
94 const VMRange &range);
97 lldb::addr_t m_base_addr;
98 lldb::addr_t m_byte_size;
101 bool operator==(const VMRange &lhs, const VMRange &rhs);
102 bool operator!=(const VMRange &lhs, const VMRange &rhs);
103 bool operator<(const VMRange &lhs, const VMRange &rhs);
104 bool operator<=(const VMRange &lhs, const VMRange &rhs);
105 bool operator>(const VMRange &lhs, const VMRange &rhs);
106 bool operator>=(const VMRange &lhs, const VMRange &rhs);
108 } // namespace lldb_private
110 #endif // liblldb_VMRange_h_