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/Utility/VMRange.h" 11 12 #include "lldb/Utility/Stream.h" 13 #include "lldb/lldb-types.h" // for addr_t 14 15 #include <algorithm> 16 #include <iterator> // for distance 17 #include <vector> // for const_iterator 18 19 #include <stddef.h> // for size_t 20 #include <stdint.h> // for UINT32_MAX, uint32_t 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 bool VMRange::ContainsValue(const VMRange::collection &coll, 26 lldb::addr_t value) { 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); 31 if (pos != end) 32 return true; 33 return false; 34 } 35 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); 42 if (pos != end) 43 return true; 44 return false; 45 } 46 47 size_t VMRange::FindRangeIndexThatContainsValue(const VMRange::collection &coll, 48 lldb::addr_t value) { 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); 53 if (pos != end) 54 return std::distance(begin, pos); 55 return UINT32_MAX; 56 } 57 58 void VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const { 59 s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(), 60 addr_width); 61 } 62 63 bool lldb_private::operator==(const VMRange &lhs, const VMRange &rhs) { 64 return lhs.GetBaseAddress() == rhs.GetBaseAddress() && 65 lhs.GetEndAddress() == rhs.GetEndAddress(); 66 } 67 68 bool lldb_private::operator!=(const VMRange &lhs, const VMRange &rhs) { 69 return lhs.GetBaseAddress() != rhs.GetBaseAddress() || 70 lhs.GetEndAddress() != rhs.GetEndAddress(); 71 } 72 73 bool lldb_private::operator<(const VMRange &lhs, const VMRange &rhs) { 74 if (lhs.GetBaseAddress() < rhs.GetBaseAddress()) 75 return true; 76 else if (lhs.GetBaseAddress() > rhs.GetBaseAddress()) 77 return false; 78 return lhs.GetEndAddress() < rhs.GetEndAddress(); 79 } 80 81 bool lldb_private::operator<=(const VMRange &lhs, const VMRange &rhs) { 82 if (lhs.GetBaseAddress() < rhs.GetBaseAddress()) 83 return true; 84 else if (lhs.GetBaseAddress() > rhs.GetBaseAddress()) 85 return false; 86 return lhs.GetEndAddress() <= rhs.GetEndAddress(); 87 } 88 89 bool lldb_private::operator>(const VMRange &lhs, const VMRange &rhs) { 90 if (lhs.GetBaseAddress() > rhs.GetBaseAddress()) 91 return true; 92 else if (lhs.GetBaseAddress() < rhs.GetBaseAddress()) 93 return false; 94 return lhs.GetEndAddress() > rhs.GetEndAddress(); 95 } 96 97 bool lldb_private::operator>=(const VMRange &lhs, const VMRange &rhs) { 98 if (lhs.GetBaseAddress() > rhs.GetBaseAddress()) 99 return true; 100 else if (lhs.GetBaseAddress() < rhs.GetBaseAddress()) 101 return false; 102 return lhs.GetEndAddress() >= rhs.GetEndAddress(); 103 } 104