]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Utility/VMRange.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Utility / VMRange.h
1 //===-- VMRange.h -----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_VMRange_h_
11 #define liblldb_VMRange_h_
12
13 #include "lldb/lldb-types.h"
14
15 #include <stddef.h>
16 #include <stdint.h>
17 #include <vector>
18
19 namespace lldb_private {
20 class Stream;
21 }
22
23 namespace lldb_private {
24
25 //----------------------------------------------------------------------
26 // A vm address range. These can represent offsets ranges or actual
27 // addresses.
28 //----------------------------------------------------------------------
29 class VMRange {
30 public:
31   typedef std::vector<VMRange> collection;
32   typedef collection::iterator iterator;
33   typedef collection::const_iterator const_iterator;
34
35   VMRange() : m_base_addr(0), m_byte_size(0) {}
36
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) {}
40
41   ~VMRange() {}
42
43   void Clear() {
44     m_base_addr = 0;
45     m_byte_size = 0;
46   }
47
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);
52   }
53
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; }
56
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;
61     else
62       m_byte_size = 0;
63   }
64
65   lldb::addr_t GetByteSize() const { return m_byte_size; }
66
67   void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }
68
69   lldb::addr_t GetBaseAddress() const { return m_base_addr; }
70
71   lldb::addr_t GetEndAddress() const { return GetBaseAddress() + m_byte_size; }
72
73   bool IsValid() const { return m_byte_size > 0; }
74
75   bool Contains(lldb::addr_t addr) const {
76     return (GetBaseAddress() <= addr) && (addr < GetEndAddress());
77   }
78
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());
83     }
84     return false;
85   }
86
87   void Dump(Stream *s, lldb::addr_t base_addr = 0,
88             uint32_t addr_width = 8) const;
89
90   static bool ContainsValue(const VMRange::collection &coll,
91                             lldb::addr_t value);
92
93   static bool ContainsRange(const VMRange::collection &coll,
94                             const VMRange &range);
95
96 protected:
97   lldb::addr_t m_base_addr;
98   lldb::addr_t m_byte_size;
99 };
100
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);
107
108 } // namespace lldb_private
109
110 #endif // liblldb_VMRange_h_