Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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" |
Eli Friedman | a408326 | 2010-06-09 08:50:27 +0000 | [diff] [blame] | 14 | #include <algorithm> |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | |
| 16 | using namespace lldb; |
| 17 | using namespace lldb_private; |
| 18 | |
| 19 | bool |
| 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 |
| 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 | |
Greg Clayton | 36da2aa | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 43 | size_t |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 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 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | |
| 55 | void |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 56 | VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | { |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 58 | s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(), addr_width); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | bool |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 | |