blob: 7e35d3ef0c65b12c827bc7a77bc62b3b4d36c5c4 [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) {
Leonard Mosescu3da16f82018-08-04 02:15:26 +000027 return llvm::find_if(coll, [&](const VMRange &r) {
28 return r.Contains(value);
29 }) != coll.end();
Kate Stoneb9c1b512016-09-06 20:57:50 +000030}
31
32bool VMRange::ContainsRange(const VMRange::collection &coll,
33 const VMRange &range) {
Leonard Mosescu3da16f82018-08-04 02:15:26 +000034 return llvm::find_if(coll, [&](const VMRange &r) {
35 return r.Contains(range);
36 }) != coll.end();
Kate Stoneb9c1b512016-09-06 20:57:50 +000037}
38
Kate Stoneb9c1b512016-09-06 20:57:50 +000039void VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const {
40 s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(),
41 addr_width);
42}
43
44bool lldb_private::operator==(const VMRange &lhs, const VMRange &rhs) {
45 return lhs.GetBaseAddress() == rhs.GetBaseAddress() &&
46 lhs.GetEndAddress() == rhs.GetEndAddress();
47}
48
49bool lldb_private::operator!=(const VMRange &lhs, const VMRange &rhs) {
Davide Italianoe8111772017-06-09 20:49:11 +000050 return !(lhs == rhs);
Kate Stoneb9c1b512016-09-06 20:57:50 +000051}
52
53bool lldb_private::operator<(const VMRange &lhs, const VMRange &rhs) {
54 if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
55 return true;
56 else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057 return false;
Kate Stoneb9c1b512016-09-06 20:57:50 +000058 return lhs.GetEndAddress() < rhs.GetEndAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059}
60
Kate Stoneb9c1b512016-09-06 20:57:50 +000061bool lldb_private::operator<=(const VMRange &lhs, const VMRange &rhs) {
Davide Italianoe8111772017-06-09 20:49:11 +000062 return !(lhs > rhs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063}
64
Kate Stoneb9c1b512016-09-06 20:57:50 +000065bool lldb_private::operator>(const VMRange &lhs, const VMRange &rhs) {
Davide Italianoe8111772017-06-09 20:49:11 +000066 return rhs < lhs;
Greg Clayton1b72fcb2010-08-24 00:45:41 +000067}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068
Kate Stoneb9c1b512016-09-06 20:57:50 +000069bool lldb_private::operator>=(const VMRange &lhs, const VMRange &rhs) {
Davide Italianoe8111772017-06-09 20:49:11 +000070 return !(lhs < rhs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071}