VMRange.cpp revision 360784
1652Sjkh//===-- VMRange.cpp ---------------------------------------------*- C++ -*-===//
233473Sscrappy//
3139825Simp// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4139825Simp// See https://llvm.org/LICENSE.txt for license information.
5139825Simp// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6652Sjkh//
733473Sscrappy//===----------------------------------------------------------------------===//
8652Sjkh
9652Sjkh#include "lldb/Utility/VMRange.h"
10652Sjkh
11652Sjkh#include "lldb/Utility/Stream.h"
12652Sjkh#include "lldb/lldb-types.h"
13652Sjkh
1433473Sscrappy#include <algorithm>
1533473Sscrappy#include <iterator>
1633473Sscrappy#include <vector>
1733473Sscrappy
18652Sjkh#include <stddef.h>
1933473Sscrappy#include <stdint.h>
2033473Sscrappy
2133473Sscrappyusing namespace lldb;
2233473Sscrappyusing namespace lldb_private;
2333473Sscrappy
2433473Sscrappybool VMRange::ContainsValue(const VMRange::collection &coll,
2533473Sscrappy                            lldb::addr_t value) {
2633473Sscrappy  return llvm::find_if(coll, [&](const VMRange &r) {
2733473Sscrappy           return r.Contains(value);
2833473Sscrappy         }) != coll.end();
2933473Sscrappy}
3033473Sscrappy
3150734Speterbool VMRange::ContainsRange(const VMRange::collection &coll,
3250734Speter                            const VMRange &range) {
33652Sjkh  return llvm::find_if(coll, [&](const VMRange &r) {
34652Sjkh           return r.Contains(range);
3550906Sdfr         }) != coll.end();
3650906Sdfr}
3765335Scg
38652Sjkhvoid VMRange::Dump(llvm::raw_ostream &s, lldb::addr_t offset,
3965335Scg                   uint32_t addr_width) const {
4013765Smpp  DumpAddressRange(s, offset + GetBaseAddress(), offset + GetEndAddress(),
41652Sjkh                   addr_width);
42652Sjkh}
43652Sjkh
443256Sswallacebool lldb_private::operator==(const VMRange &lhs, const VMRange &rhs) {
4530866Smarkm  return lhs.GetBaseAddress() == rhs.GetBaseAddress() &&
4630866Smarkm         lhs.GetEndAddress() == rhs.GetEndAddress();
4765335Scg}
4882033Sgreid
4930866Smarkmbool lldb_private::operator!=(const VMRange &lhs, const VMRange &rhs) {
5030866Smarkm  return !(lhs == rhs);
5182033Sgreid}
5230866Smarkm
5330866Smarkmbool lldb_private::operator<(const VMRange &lhs, const VMRange &rhs) {
54652Sjkh  if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
55652Sjkh    return true;
5633530Sscrappy  else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
5733530Sscrappy    return false;
5833530Sscrappy  return lhs.GetEndAddress() < rhs.GetEndAddress();
5933530Sscrappy}
6033530Sscrappy
6133530Sscrappybool lldb_private::operator<=(const VMRange &lhs, const VMRange &rhs) {
6233530Sscrappy  return !(lhs > rhs);
6333530Sscrappy}
6433530Sscrappy
6533530Sscrappybool lldb_private::operator>(const VMRange &lhs, const VMRange &rhs) {
6633530Sscrappy  return rhs < lhs;
6733530Sscrappy}
6833530Sscrappy
6933530Sscrappybool lldb_private::operator>=(const VMRange &lhs, const VMRange &rhs) {
7033530Sscrappy  return !(lhs < rhs);
7133530Sscrappy}
7233530Sscrappy