blob: 112106b6e5c12fddeb0d74472bdc5f0e33efbadd [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);
Davide Italiano5ccf12e2017-06-09 19:14:59 +000028 return llvm::find_if(coll, in_range_predicate) != coll.end();
Kate Stoneb9c1b512016-09-06 20:57:50 +000029}
30
31bool VMRange::ContainsRange(const VMRange::collection &coll,
32 const VMRange &range) {
33 RangeInRangeUnaryPredicate in_range_predicate(range);
Davide Italiano5ccf12e2017-06-09 19:14:59 +000034 return llvm::find_if(coll, in_range_predicate) != coll.end();
Kate Stoneb9c1b512016-09-06 20:57:50 +000035}
36
37size_t VMRange::FindRangeIndexThatContainsValue(const VMRange::collection &coll,
38 lldb::addr_t value) {
39 ValueInRangeUnaryPredicate in_range_predicate(value);
40 VMRange::const_iterator begin = coll.begin();
41 VMRange::const_iterator end = coll.end();
42 VMRange::const_iterator pos = std::find_if(begin, end, in_range_predicate);
43 if (pos != end)
44 return std::distance(begin, pos);
45 return UINT32_MAX;
46}
47
48void VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const {
49 s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(),
50 addr_width);
51}
52
53bool lldb_private::operator==(const VMRange &lhs, const VMRange &rhs) {
54 return lhs.GetBaseAddress() == rhs.GetBaseAddress() &&
55 lhs.GetEndAddress() == rhs.GetEndAddress();
56}
57
58bool lldb_private::operator!=(const VMRange &lhs, const VMRange &rhs) {
Davide Italianoe8111772017-06-09 20:49:11 +000059 return !(lhs == rhs);
Kate Stoneb9c1b512016-09-06 20:57:50 +000060}
61
62bool lldb_private::operator<(const VMRange &lhs, const VMRange &rhs) {
63 if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
64 return true;
65 else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066 return false;
Kate Stoneb9c1b512016-09-06 20:57:50 +000067 return lhs.GetEndAddress() < rhs.GetEndAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068}
69
Kate Stoneb9c1b512016-09-06 20:57:50 +000070bool lldb_private::operator<=(const VMRange &lhs, const VMRange &rhs) {
Davide Italianoe8111772017-06-09 20:49:11 +000071 return !(lhs > rhs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072}
73
Kate Stoneb9c1b512016-09-06 20:57:50 +000074bool lldb_private::operator>(const VMRange &lhs, const VMRange &rhs) {
Davide Italianoe8111772017-06-09 20:49:11 +000075 return rhs < lhs;
Greg Clayton1b72fcb2010-08-24 00:45:41 +000076}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077
Kate Stoneb9c1b512016-09-06 20:57:50 +000078bool lldb_private::operator>=(const VMRange &lhs, const VMRange &rhs) {
Davide Italianoe8111772017-06-09 20:49:11 +000079 return !(lhs < rhs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080}