1 //===-- VMRange.cpp ---------------------------------------------*- 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 #include "lldb/lldb-private.h"
11
12 #include "lldb/Core/Stream.h"
13 #include "lldb/Core/VMRange.h"
14 #include <algorithm>
15
16 using namespace lldb;
17 using namespace lldb_private;
18
19 bool
ContainsValue(const VMRange::collection & coll,lldb::addr_t value)20 VMRange::ContainsValue(const VMRange::collection& coll, lldb::addr_t value)
21 {
22 ValueInRangeUnaryPredicate in_range_predicate(value);
23 VMRange::const_iterator pos;
24 VMRange::const_iterator end = coll.end();
25 pos = std::find_if( coll.begin(), end, in_range_predicate );
26 if (pos != end)
27 return true;
28 return false;
29 }
30
31 bool
ContainsRange(const VMRange::collection & coll,const VMRange & range)32 VMRange::ContainsRange(const VMRange::collection& coll, const VMRange& range)
33 {
34 RangeInRangeUnaryPredicate in_range_predicate(range);
35 VMRange::const_iterator pos;
36 VMRange::const_iterator end = coll.end();
37 pos = std::find_if( coll.begin(), end, in_range_predicate );
38 if (pos != end)
39 return true;
40 return false;
41 }
42
43 size_t
FindRangeIndexThatContainsValue(const VMRange::collection & coll,lldb::addr_t value)44 VMRange::FindRangeIndexThatContainsValue (const VMRange::collection& coll, lldb::addr_t value)
45 {
46 ValueInRangeUnaryPredicate in_range_predicate(value);
47 VMRange::const_iterator begin = coll.begin();
48 VMRange::const_iterator end = coll.end();
49 VMRange::const_iterator pos = std::find_if (begin, end, in_range_predicate);
50 if (pos != end)
51 return std::distance (begin, pos);
52 return UINT32_MAX;
53 }
54
55 void
Dump(Stream * s,lldb::addr_t offset,uint32_t addr_width) const56 VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const
57 {
58 s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(), addr_width);
59 }
60
61 bool
operator ==(const VMRange & lhs,const VMRange & rhs)62 lldb_private::operator== (const VMRange& lhs, const VMRange& rhs)
63 {
64 return lhs.GetBaseAddress() == rhs.GetBaseAddress() && lhs.GetEndAddress() == rhs.GetEndAddress();
65 }
66
67 bool
operator !=(const VMRange & lhs,const VMRange & rhs)68 lldb_private::operator!= (const VMRange& lhs, const VMRange& rhs)
69 {
70 return lhs.GetBaseAddress() != rhs.GetBaseAddress() || lhs.GetEndAddress() != rhs.GetEndAddress();
71 }
72
73 bool
operator <(const VMRange & lhs,const VMRange & rhs)74 lldb_private::operator< (const VMRange& lhs, const VMRange& rhs)
75 {
76 if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
77 return true;
78 else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
79 return false;
80 return lhs.GetEndAddress() < rhs.GetEndAddress();
81 }
82
83 bool
operator <=(const VMRange & lhs,const VMRange & rhs)84 lldb_private::operator<= (const VMRange& lhs, const VMRange& rhs)
85 {
86 if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
87 return true;
88 else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
89 return false;
90 return lhs.GetEndAddress() <= rhs.GetEndAddress();
91 }
92
93 bool
operator >(const VMRange & lhs,const VMRange & rhs)94 lldb_private::operator> (const VMRange& lhs, const VMRange& rhs)
95 {
96 if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
97 return true;
98 else if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
99 return false;
100 return lhs.GetEndAddress() > rhs.GetEndAddress();
101 }
102
103 bool
operator >=(const VMRange & lhs,const VMRange & rhs)104 lldb_private::operator>= (const VMRange& lhs, const VMRange& rhs)
105 {
106 if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
107 return true;
108 else if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
109 return false;
110 return lhs.GetEndAddress() >= rhs.GetEndAddress();
111 }
112
113