1 //===-- VMRange.cpp ---------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Utility/VMRange.h" 10 11 #include "lldb/Utility/Stream.h" 12 #include "lldb/lldb-types.h" 13 14 #include <algorithm> 15 #include <iterator> 16 #include <vector> 17 18 #include <stddef.h> 19 #include <stdint.h> 20 21 using namespace lldb; 22 using namespace lldb_private; 23 24 bool VMRange::ContainsValue(const VMRange::collection &coll, 25 lldb::addr_t value) { 26 return llvm::find_if(coll, [&](const VMRange &r) { 27 return r.Contains(value); 28 }) != coll.end(); 29 } 30 31 bool VMRange::ContainsRange(const VMRange::collection &coll, 32 const VMRange &range) { 33 return llvm::find_if(coll, [&](const VMRange &r) { 34 return r.Contains(range); 35 }) != coll.end(); 36 } 37 38 void VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const { 39 s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(), 40 addr_width); 41 } 42 43 bool lldb_private::operator==(const VMRange &lhs, const VMRange &rhs) { 44 return lhs.GetBaseAddress() == rhs.GetBaseAddress() && 45 lhs.GetEndAddress() == rhs.GetEndAddress(); 46 } 47 48 bool lldb_private::operator!=(const VMRange &lhs, const VMRange &rhs) { 49 return !(lhs == rhs); 50 } 51 52 bool lldb_private::operator<(const VMRange &lhs, const VMRange &rhs) { 53 if (lhs.GetBaseAddress() < rhs.GetBaseAddress()) 54 return true; 55 else if (lhs.GetBaseAddress() > rhs.GetBaseAddress()) 56 return false; 57 return lhs.GetEndAddress() < rhs.GetEndAddress(); 58 } 59 60 bool lldb_private::operator<=(const VMRange &lhs, const VMRange &rhs) { 61 return !(lhs > rhs); 62 } 63 64 bool lldb_private::operator>(const VMRange &lhs, const VMRange &rhs) { 65 return rhs < lhs; 66 } 67 68 bool lldb_private::operator>=(const VMRange &lhs, const VMRange &rhs) { 69 return !(lhs < rhs); 70 } 71