1 //===-- VMRange.cpp ---------------------------------------------*- 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 #include "lldb/Utility/VMRange.h"
12 #include "lldb/Utility/Stream.h"
13 #include "lldb/lldb-types.h" // for addr_t
16 #include <iterator> // for distance
17 #include <vector> // for const_iterator
19 #include <stddef.h> // for size_t
20 #include <stdint.h> // for UINT32_MAX, uint32_t
23 using namespace lldb_private;
25 bool VMRange::ContainsValue(const VMRange::collection &coll,
27 ValueInRangeUnaryPredicate in_range_predicate(value);
28 VMRange::const_iterator pos;
29 VMRange::const_iterator end = coll.end();
30 pos = std::find_if(coll.begin(), end, in_range_predicate);
36 bool VMRange::ContainsRange(const VMRange::collection &coll,
37 const VMRange &range) {
38 RangeInRangeUnaryPredicate in_range_predicate(range);
39 VMRange::const_iterator pos;
40 VMRange::const_iterator end = coll.end();
41 pos = std::find_if(coll.begin(), end, in_range_predicate);
47 size_t VMRange::FindRangeIndexThatContainsValue(const VMRange::collection &coll,
49 ValueInRangeUnaryPredicate in_range_predicate(value);
50 VMRange::const_iterator begin = coll.begin();
51 VMRange::const_iterator end = coll.end();
52 VMRange::const_iterator pos = std::find_if(begin, end, in_range_predicate);
54 return std::distance(begin, pos);
58 void VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const {
59 s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(),
63 bool lldb_private::operator==(const VMRange &lhs, const VMRange &rhs) {
64 return lhs.GetBaseAddress() == rhs.GetBaseAddress() &&
65 lhs.GetEndAddress() == rhs.GetEndAddress();
68 bool lldb_private::operator!=(const VMRange &lhs, const VMRange &rhs) {
69 return lhs.GetBaseAddress() != rhs.GetBaseAddress() ||
70 lhs.GetEndAddress() != rhs.GetEndAddress();
73 bool lldb_private::operator<(const VMRange &lhs, const VMRange &rhs) {
74 if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
76 else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
78 return lhs.GetEndAddress() < rhs.GetEndAddress();
81 bool lldb_private::operator<=(const VMRange &lhs, const VMRange &rhs) {
82 if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
84 else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
86 return lhs.GetEndAddress() <= rhs.GetEndAddress();
89 bool lldb_private::operator>(const VMRange &lhs, const VMRange &rhs) {
90 if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
92 else if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
94 return lhs.GetEndAddress() > rhs.GetEndAddress();
97 bool lldb_private::operator>=(const VMRange &lhs, const VMRange &rhs) {
98 if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
100 else if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
102 return lhs.GetEndAddress() >= rhs.GetEndAddress();