blob: f3f4ae7efc3c1be62f4cbcb2c395b07089d35505 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- VMRange.cpp ---------------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006//
7//===----------------------------------------------------------------------===//
8
Zachary Turner4479ac12017-04-06 18:12:24 +00009#include "lldb/Utility/VMRange.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000010
Zachary Turnerbf9a7732017-02-02 21:39:50 +000011#include "lldb/Utility/Stream.h"
Jonas Devlieghere672d2c12018-11-11 23:16:43 +000012#include "lldb/lldb-types.h"
Zachary Turner4479ac12017-04-06 18:12:24 +000013
Eli Friedman88966972010-06-09 08:50:27 +000014#include <algorithm>
Jonas Devlieghere672d2c12018-11-11 23:16:43 +000015#include <iterator>
16#include <vector>
Zachary Turner4479ac12017-04-06 18:12:24 +000017
Jonas Devlieghere672d2c12018-11-11 23:16:43 +000018#include <stddef.h>
19#include <stdint.h>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
21using namespace lldb;
22using namespace lldb_private;
23
Kate Stoneb9c1b512016-09-06 20:57:50 +000024bool VMRange::ContainsValue(const VMRange::collection &coll,
25 lldb::addr_t value) {
Leonard Mosescu3da16f82018-08-04 02:15:26 +000026 return llvm::find_if(coll, [&](const VMRange &r) {
27 return r.Contains(value);
28 }) != coll.end();
Kate Stoneb9c1b512016-09-06 20:57:50 +000029}
30
31bool VMRange::ContainsRange(const VMRange::collection &coll,
32 const VMRange &range) {
Leonard Mosescu3da16f82018-08-04 02:15:26 +000033 return llvm::find_if(coll, [&](const VMRange &r) {
34 return r.Contains(range);
35 }) != coll.end();
Kate Stoneb9c1b512016-09-06 20:57:50 +000036}
37
Kate Stoneb9c1b512016-09-06 20:57:50 +000038void VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const {
39 s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(),
40 addr_width);
41}
42
43bool lldb_private::operator==(const VMRange &lhs, const VMRange &rhs) {
44 return lhs.GetBaseAddress() == rhs.GetBaseAddress() &&
45 lhs.GetEndAddress() == rhs.GetEndAddress();
46}
47
48bool lldb_private::operator!=(const VMRange &lhs, const VMRange &rhs) {
Davide Italianoe8111772017-06-09 20:49:11 +000049 return !(lhs == rhs);
Kate Stoneb9c1b512016-09-06 20:57:50 +000050}
51
52bool lldb_private::operator<(const VMRange &lhs, const VMRange &rhs) {
53 if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
54 return true;
55 else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056 return false;
Kate Stoneb9c1b512016-09-06 20:57:50 +000057 return lhs.GetEndAddress() < rhs.GetEndAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058}
59
Kate Stoneb9c1b512016-09-06 20:57:50 +000060bool lldb_private::operator<=(const VMRange &lhs, const VMRange &rhs) {
Davide Italianoe8111772017-06-09 20:49:11 +000061 return !(lhs > rhs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062}
63
Kate Stoneb9c1b512016-09-06 20:57:50 +000064bool lldb_private::operator>(const VMRange &lhs, const VMRange &rhs) {
Davide Italianoe8111772017-06-09 20:49:11 +000065 return rhs < lhs;
Greg Clayton1b72fcb2010-08-24 00:45:41 +000066}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067
Kate Stoneb9c1b512016-09-06 20:57:50 +000068bool lldb_private::operator>=(const VMRange &lhs, const VMRange &rhs) {
Davide Italianoe8111772017-06-09 20:49:11 +000069 return !(lhs < rhs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070}