blob: 902489e1ff38e6b548195b7f7c78fe30f94fca5a [file] [log] [blame]
Chris Lattner24943d22010-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
10#include "lldb/lldb-private.h"
11
12#include "lldb/Core/Stream.h"
13#include "lldb/Core/VMRange.h"
Eli Friedmana4083262010-06-09 08:50:27 +000014#include <algorithm>
Chris Lattner24943d22010-06-08 16:52:24 +000015
16using namespace lldb;
17using namespace lldb_private;
18
19bool
20VMRange::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
31bool
32VMRange::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 Clayton36da2aa2013-01-25 18:06:21 +000043size_t
Greg Clayton33ed1702010-08-24 00:45:41 +000044VMRange::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 Lattner24943d22010-06-08 16:52:24 +000054
55void
Greg Clayton12bec712010-06-28 21:30:43 +000056VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const
Chris Lattner24943d22010-06-08 16:52:24 +000057{
Greg Clayton12bec712010-06-28 21:30:43 +000058 s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(), addr_width);
Chris Lattner24943d22010-06-08 16:52:24 +000059}
60
61bool
62lldb_private::operator== (const VMRange& lhs, const VMRange& rhs)
63{
64 return lhs.GetBaseAddress() == rhs.GetBaseAddress() && lhs.GetEndAddress() == rhs.GetEndAddress();
65}
66
67bool
68lldb_private::operator!= (const VMRange& lhs, const VMRange& rhs)
69{
70 return lhs.GetBaseAddress() != rhs.GetBaseAddress() || lhs.GetEndAddress() != rhs.GetEndAddress();
71}
72
73bool
74lldb_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
83bool
84lldb_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
93bool
94lldb_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
103bool
104lldb_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