blob: 5eccd292a851ee3414043be4e9605275f3c6eb71 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Turner4479ac12017-04-06 18:12:24 +000010#include "lldb/Utility/VMRange.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000011
Zachary Turnerbf9a7732017-02-02 21:39:50 +000012#include "lldb/Utility/Stream.h"
Zachary Turner4479ac12017-04-06 18:12:24 +000013#include "lldb/lldb-types.h" // for addr_t
14
Eli Friedman88966972010-06-09 08:50:27 +000015#include <algorithm>
Zachary Turner4479ac12017-04-06 18:12:24 +000016#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 Lattner30fdc8d2010-06-08 16:52:24 +000021
22using namespace lldb;
23using namespace lldb_private;
24
Kate Stoneb9c1b512016-09-06 20:57:50 +000025bool 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
36bool 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
47size_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
58void 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
63bool lldb_private::operator==(const VMRange &lhs, const VMRange &rhs) {
64 return lhs.GetBaseAddress() == rhs.GetBaseAddress() &&
65 lhs.GetEndAddress() == rhs.GetEndAddress();
66}
67
68bool lldb_private::operator!=(const VMRange &lhs, const VMRange &rhs) {
69 return lhs.GetBaseAddress() != rhs.GetBaseAddress() ||
70 lhs.GetEndAddress() != rhs.GetEndAddress();
71}
72
73bool 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 Lattner30fdc8d2010-06-08 16:52:24 +000077 return false;
Kate Stoneb9c1b512016-09-06 20:57:50 +000078 return lhs.GetEndAddress() < rhs.GetEndAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079}
80
Kate Stoneb9c1b512016-09-06 20:57:50 +000081bool 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 Lattner30fdc8d2010-06-08 16:52:24 +000085 return false;
Kate Stoneb9c1b512016-09-06 20:57:50 +000086 return lhs.GetEndAddress() <= rhs.GetEndAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087}
88
Kate Stoneb9c1b512016-09-06 20:57:50 +000089bool 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 Clayton1b72fcb2010-08-24 00:45:41 +000095}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096
Kate Stoneb9c1b512016-09-06 20:57:50 +000097bool 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 Lattner30fdc8d2010-06-08 16:52:24 +0000103}