| Chris Lattner | 30fdc8d | 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 | |
| Zachary Turner | 4479ac1 | 2017-04-06 18:12:24 +0000 | [diff] [blame^] | 10 | #include "lldb/Utility/VMRange.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | |
| Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 12 | #include "lldb/Utility/Stream.h" |
| Zachary Turner | 4479ac1 | 2017-04-06 18:12:24 +0000 | [diff] [blame^] | 13 | #include "lldb/lldb-types.h" // for addr_t |
| 14 | |
| Eli Friedman | 8896697 | 2010-06-09 08:50:27 +0000 | [diff] [blame] | 15 | #include <algorithm> |
| Zachary Turner | 4479ac1 | 2017-04-06 18:12:24 +0000 | [diff] [blame^] | 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 |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace lldb; |
| 23 | using namespace lldb_private; |
| 24 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | return false; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | return lhs.GetEndAddress() < rhs.GetEndAddress(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 85 | return false; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 86 | return lhs.GetEndAddress() <= rhs.GetEndAddress(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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(); |
| Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 95 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 96 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | } |