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 
19 namespace lldb_private {
20 
21 // A vm address range. These can represent offsets ranges or actual
22 // addresses.
23 class VMRange {
24 public:
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 
59  lldb::addr_t GetByteSize() const { return m_byte_size; }
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 
90 protected:
93 };
94 
95 bool operator==(const VMRange &lhs, const VMRange &rhs);
96 bool operator!=(const VMRange &lhs, const VMRange &rhs);
97 bool operator<(const VMRange &lhs, const VMRange &rhs);
98 bool operator<=(const VMRange &lhs, const VMRange &rhs);
99 bool operator>(const VMRange &lhs, const VMRange &rhs);
100 bool operator>=(const VMRange &lhs, const VMRange &rhs);
101 
102 } // namespace lldb_private
103 
104 #endif // LLDB_UTILITY_VMRANGE_H
lldb_private::VMRange::iterator
collection::iterator iterator
Definition: VMRange.h:26
lldb_private::VMRange::GetEndAddress
lldb::addr_t GetEndAddress() const
Definition: VMRange.h:65
lldb_private::VMRange::ContainsValue
static bool ContainsValue(const VMRange::collection &coll, lldb::addr_t value)
Definition: VMRange.cpp:24
lldb_private::VMRange::collection
std::vector< VMRange > collection
Definition: VMRange.h:25
lldb_private::VMRange::SetByteSize
void SetByteSize(lldb::addr_t byte_size)
Definition: VMRange.h:61
lldb_private::VMRange::SetBaseAddress
void SetBaseAddress(lldb::addr_t base_addr)
Definition: VMRange.h:49
lldb_private::VMRange::ContainsRange
static bool ContainsRange(const VMRange::collection &coll, const VMRange &range)
Definition: VMRange.cpp:30
lldb_private::VMRange::GetBaseAddress
lldb::addr_t GetBaseAddress() const
Definition: VMRange.h:63
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::VMRange::m_base_addr
lldb::addr_t m_base_addr
Definition: VMRange.h:91
lldb_private::VMRange::Contains
bool Contains(const VMRange &range) const
Definition: VMRange.h:73
lldb_private::operator==
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:999
lldb_private::VMRange::const_iterator
collection::const_iterator const_iterator
Definition: VMRange.h:27
lldb_private::VMRange::Dump
void Dump(llvm::raw_ostream &s, lldb::addr_t base_addr=0, uint32_t addr_width=8) const
Definition: VMRange.cpp:36
lldb_private::VMRange::SetEndAddress
void SetEndAddress(lldb::addr_t end_addr)
Definition: VMRange.h:51
lldb_private::operator>
bool operator>(const Address &lhs, const Address &rhs)
Definition: Address.cpp:983
lldb_private::operator!=
bool operator!=(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1005
lldb_private::VMRange::Reset
void Reset(lldb::addr_t start_addr, lldb::addr_t end_addr)
Definition: VMRange.h:43
lldb-types.h
lldb_private::VMRange::Clear
void Clear()
Definition: VMRange.h:37
lldb_private::VMRange::IsValid
bool IsValid() const
Definition: VMRange.h:67
uint32_t
lldb_private::operator<
bool operator<(const Address &lhs, const Address &rhs)
Definition: Address.cpp:968
lldb_private::VMRange::m_byte_size
lldb::addr_t m_byte_size
Definition: VMRange.h:92
lldb_private::VMRange::VMRange
VMRange()=default
lldb_private::VMRange::GetByteSize
lldb::addr_t GetByteSize() const
Definition: VMRange.h:59
lldb_private::VMRange::~VMRange
~VMRange()=default
lldb_private::operator>=
bool operator>=(const Scalar &lhs, const Scalar &rhs)
Definition: Scalar.cpp:864
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::VMRange::VMRange
VMRange(lldb::addr_t start_addr, lldb::addr_t end_addr)
Definition: VMRange.h:31
lldb_private::operator<=
bool operator<=(const Scalar &lhs, const Scalar &rhs)
Definition: Scalar.cpp:856
lldb_private::VMRange
Definition: VMRange.h:23
lldb_private::VMRange::Contains
bool Contains(lldb::addr_t addr) const
Definition: VMRange.h:69