1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
//===-- VMRange.h -----------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_VMRange_h_
#define liblldb_VMRange_h_
#include "lldb/lldb-private.h"
#include <vector>
namespace lldb_private {
//----------------------------------------------------------------------
// A vm address range. These can represent offsets ranges or actual
// addresses.
//----------------------------------------------------------------------
class VMRange
{
public:
typedef std::vector<VMRange> collection;
typedef collection::iterator iterator;
typedef collection::const_iterator const_iterator;
VMRange() :
m_base_addr(0),
m_byte_size(0)
{
}
VMRange(lldb::addr_t start_addr, lldb::addr_t end_addr) :
m_base_addr(start_addr),
m_byte_size(end_addr > start_addr ? end_addr - start_addr : 0)
{
}
~VMRange()
{
}
void
Clear ()
{
m_base_addr = 0;
m_byte_size = 0;
}
// Set the start and end values
void
Reset (lldb::addr_t start_addr, lldb::addr_t end_addr)
{
SetBaseAddress (start_addr);
SetEndAddress (end_addr);
}
// Set the start value for the range, and keep the same size
void
SetBaseAddress (lldb::addr_t base_addr)
{
m_base_addr = base_addr;
}
void
SetEndAddress (lldb::addr_t end_addr)
{
const lldb::addr_t base_addr = GetBaseAddress();
if (end_addr > base_addr)
m_byte_size = end_addr - base_addr;
else
m_byte_size = 0;
}
lldb::addr_t
GetByteSize () const
{
return m_byte_size;
}
void
SetByteSize (lldb::addr_t byte_size)
{
m_byte_size = byte_size;
}
lldb::addr_t
GetBaseAddress () const
{
return m_base_addr;
}
lldb::addr_t
GetEndAddress () const
{
return GetBaseAddress() + m_byte_size;
}
bool
IsValid() const
{
return m_byte_size > 0;
}
bool
Contains (lldb::addr_t addr) const
{
return (GetBaseAddress() <= addr) && (addr < GetEndAddress());
}
bool
Contains (const VMRange& range) const
{
if (Contains(range.GetBaseAddress()))
{
lldb::addr_t range_end = range.GetEndAddress();
return (GetBaseAddress() <= range_end) && (range_end <= GetEndAddress());
}
return false;
}
void
Dump (Stream *s, lldb::addr_t base_addr = 0, uint32_t addr_width = 8) const;
class ValueInRangeUnaryPredicate
{
public:
ValueInRangeUnaryPredicate(lldb::addr_t value) :
_value(value)
{
}
bool operator()(const VMRange& range) const
{
return range.Contains(_value);
}
lldb::addr_t _value;
};
class RangeInRangeUnaryPredicate
{
public:
RangeInRangeUnaryPredicate(VMRange range) :
_range(range)
{
}
bool operator()(const VMRange& range) const
{
return range.Contains(_range);
}
const VMRange& _range;
};
static bool
ContainsValue(const VMRange::collection& coll, lldb::addr_t value);
static bool
ContainsRange(const VMRange::collection& coll, const VMRange& range);
// Returns a valid index into coll when a match is found, else UINT32_MAX
// is returned
static size_t
FindRangeIndexThatContainsValue (const VMRange::collection& coll, lldb::addr_t value);
protected:
lldb::addr_t m_base_addr;
lldb::addr_t m_byte_size;
};
bool operator== (const VMRange& lhs, const VMRange& rhs);
bool operator!= (const VMRange& lhs, const VMRange& rhs);
bool operator< (const VMRange& lhs, const VMRange& rhs);
bool operator<= (const VMRange& lhs, const VMRange& rhs);
bool operator> (const VMRange& lhs, const VMRange& rhs);
bool operator>= (const VMRange& lhs, const VMRange& rhs);
} // namespace lldb_private
#endif // liblldb_VMRange_h_
|