summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/VMRange.cpp
blob: d77908d3faaf2500df8ad2d1453ffb6dcc73d685 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//===-- VMRange.cpp ---------------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/lldb-private.h"

#include "lldb/Core/VMRange.h"
#include "lldb/Utility/Stream.h"
#include <algorithm>

using namespace lldb;
using namespace lldb_private;

bool VMRange::ContainsValue(const VMRange::collection &coll,
                            lldb::addr_t value) {
  ValueInRangeUnaryPredicate in_range_predicate(value);
  VMRange::const_iterator pos;
  VMRange::const_iterator end = coll.end();
  pos = std::find_if(coll.begin(), end, in_range_predicate);
  if (pos != end)
    return true;
  return false;
}

bool VMRange::ContainsRange(const VMRange::collection &coll,
                            const VMRange &range) {
  RangeInRangeUnaryPredicate in_range_predicate(range);
  VMRange::const_iterator pos;
  VMRange::const_iterator end = coll.end();
  pos = std::find_if(coll.begin(), end, in_range_predicate);
  if (pos != end)
    return true;
  return false;
}

size_t VMRange::FindRangeIndexThatContainsValue(const VMRange::collection &coll,
                                                lldb::addr_t value) {
  ValueInRangeUnaryPredicate in_range_predicate(value);
  VMRange::const_iterator begin = coll.begin();
  VMRange::const_iterator end = coll.end();
  VMRange::const_iterator pos = std::find_if(begin, end, in_range_predicate);
  if (pos != end)
    return std::distance(begin, pos);
  return UINT32_MAX;
}

void VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const {
  s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(),
                  addr_width);
}

bool lldb_private::operator==(const VMRange &lhs, const VMRange &rhs) {
  return lhs.GetBaseAddress() == rhs.GetBaseAddress() &&
         lhs.GetEndAddress() == rhs.GetEndAddress();
}

bool lldb_private::operator!=(const VMRange &lhs, const VMRange &rhs) {
  return lhs.GetBaseAddress() != rhs.GetBaseAddress() ||
         lhs.GetEndAddress() != rhs.GetEndAddress();
}

bool lldb_private::operator<(const VMRange &lhs, const VMRange &rhs) {
  if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
    return true;
  else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
    return false;
  return lhs.GetEndAddress() < rhs.GetEndAddress();
}

bool lldb_private::operator<=(const VMRange &lhs, const VMRange &rhs) {
  if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
    return true;
  else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
    return false;
  return lhs.GetEndAddress() <= rhs.GetEndAddress();
}

bool lldb_private::operator>(const VMRange &lhs, const VMRange &rhs) {
  if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
    return true;
  else if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
    return false;
  return lhs.GetEndAddress() > rhs.GetEndAddress();
}

bool lldb_private::operator>=(const VMRange &lhs, const VMRange &rhs) {
  if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
    return true;
  else if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
    return false;
  return lhs.GetEndAddress() >= rhs.GetEndAddress();
}
OpenPOWER on IntegriCloud