LLDB mainline
VMRange.h
Go to the documentation of this file.
1//===-- VMRange.h -----------------------------------------------*- C++ -*-===//
2//
3// 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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_UTILITY_VMRANGE_H
10#define LLDB_UTILITY_VMRANGE_H
11
12#include "lldb/lldb-types.h"
13#include "llvm/Support/raw_ostream.h"
14
15#include <cstddef>
16#include <cstdint>
17#include <vector>
18
19namespace lldb_private {
20
21// A vm address range. These can represent offsets ranges or actual
22// addresses.
23class VMRange {
24public:
25 typedef std::vector<VMRange> collection;
26 typedef collection::iterator iterator;
27 typedef collection::const_iterator const_iterator;
28
29 VMRange() = default;
30
31 VMRange(lldb::addr_t start_addr, lldb::addr_t end_addr)
32 : m_base_addr(start_addr),
33 m_byte_size(end_addr > start_addr ? end_addr - start_addr : 0) {}
34
35 ~VMRange() = default;
36
37 void Clear() {
38 m_base_addr = 0;
39 m_byte_size = 0;
40 }
41
42 // Set the start and end values
43 void Reset(lldb::addr_t start_addr, lldb::addr_t end_addr) {
44 SetBaseAddress(start_addr);
45 SetEndAddress(end_addr);
46 }
47
48 // Set the start value for the range, and keep the same size
49 void SetBaseAddress(lldb::addr_t base_addr) { m_base_addr = base_addr; }
50
51 void SetEndAddress(lldb::addr_t end_addr) {
52 const lldb::addr_t base_addr = GetBaseAddress();
53 if (end_addr > base_addr)
54 m_byte_size = end_addr - base_addr;
55 else
56 m_byte_size = 0;
57 }
58
60
61 void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }
62
64
66
67 bool IsValid() const { return m_byte_size > 0; }
68
69 bool Contains(lldb::addr_t addr) const {
70 return (GetBaseAddress() <= addr) && (addr < GetEndAddress());
71 }
72
73 bool Contains(const VMRange &range) const {
74 if (Contains(range.GetBaseAddress())) {
75 lldb::addr_t range_end = range.GetEndAddress();
76 return (GetBaseAddress() <= range_end) && (range_end <= GetEndAddress());
77 }
78 return false;
79 }
80
81 void Dump(llvm::raw_ostream &s, lldb::addr_t base_addr = 0,
82 uint32_t addr_width = 8) const;
83
84 static bool ContainsValue(const VMRange::collection &coll,
85 lldb::addr_t value);
86
87 static bool ContainsRange(const VMRange::collection &coll,
88 const VMRange &range);
89
90protected:
93};
94
95bool operator==(const VMRange &lhs, const VMRange &rhs);
96bool operator!=(const VMRange &lhs, const VMRange &rhs);
97bool operator<(const VMRange &lhs, const VMRange &rhs);
98bool operator<=(const VMRange &lhs, const VMRange &rhs);
99bool operator>(const VMRange &lhs, const VMRange &rhs);
100bool operator>=(const VMRange &lhs, const VMRange &rhs);
101
102} // namespace lldb_private
103
104#endif // LLDB_UTILITY_VMRANGE_H
collection::const_iterator const_iterator
Definition: VMRange.h:27
static bool ContainsRange(const VMRange::collection &coll, const VMRange &range)
Definition: VMRange.cpp:30
static bool ContainsValue(const VMRange::collection &coll, lldb::addr_t value)
Definition: VMRange.cpp:24
bool IsValid() const
Definition: VMRange.h:67
void SetEndAddress(lldb::addr_t end_addr)
Definition: VMRange.h:51
lldb::addr_t GetEndAddress() const
Definition: VMRange.h:65
bool Contains(const VMRange &range) const
Definition: VMRange.h:73
lldb::addr_t GetByteSize() const
Definition: VMRange.h:59
void SetByteSize(lldb::addr_t byte_size)
Definition: VMRange.h:61
lldb::addr_t GetBaseAddress() const
Definition: VMRange.h:63
void Reset(lldb::addr_t start_addr, lldb::addr_t end_addr)
Definition: VMRange.h:43
lldb::addr_t m_byte_size
Definition: VMRange.h:92
void SetBaseAddress(lldb::addr_t base_addr)
Definition: VMRange.h:49
bool Contains(lldb::addr_t addr) const
Definition: VMRange.h:69
VMRange(lldb::addr_t start_addr, lldb::addr_t end_addr)
Definition: VMRange.h:31
std::vector< VMRange > collection
Definition: VMRange.h:25
void Dump(llvm::raw_ostream &s, lldb::addr_t base_addr=0, uint32_t addr_width=8) const
Definition: VMRange.cpp:36
lldb::addr_t m_base_addr
Definition: VMRange.h:91
collection::iterator iterator
Definition: VMRange.h:26
A class that represents a running process on the host machine.
bool operator<=(const Scalar &lhs, const Scalar &rhs)
Definition: Scalar.cpp:887
bool operator!=(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1029
bool operator>(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1007
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1023
bool operator<(const Address &lhs, const Address &rhs)
Definition: Address.cpp:992
bool operator>=(const Scalar &lhs, const Scalar &rhs)
Definition: Scalar.cpp:896
uint64_t addr_t
Definition: lldb-types.h:80