LLDB mainline
MemoryRegionInfo.h
Go to the documentation of this file.
1//===-- MemoryRegionInfo.h ---------------------------------------*- C++
2//-*-===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLDB_TARGET_MEMORYREGIONINFO_H
11#define LLDB_TARGET_MEMORYREGIONINFO_H
12
13#include <optional>
14#include <vector>
15
18#include "llvm/Support/FormatProviders.h"
19
20namespace lldb_private {
22public:
24
25 MemoryRegionInfo() = default;
27 LazyBool execute, LazyBool shared, LazyBool mapped,
28 ConstString name)
29 : m_range(range), m_read(read), m_write(write), m_execute(execute),
30 m_shared(shared), m_mapped(mapped), m_name(name) {}
31
32 RangeType &GetRange() { return m_range; }
33
34 void Clear() { *this = MemoryRegionInfo(); }
35
36 const RangeType &GetRange() const { return m_range; }
37
38 LazyBool GetReadable() const { return m_read; }
39
40 LazyBool GetWritable() const { return m_write; }
41
42 LazyBool GetExecutable() const { return m_execute; }
43
44 LazyBool GetShared() const { return m_shared; }
45
46 LazyBool GetMapped() const { return m_mapped; }
47
48 ConstString GetName() const { return m_name; }
49
51
53
54 void SetReadable(LazyBool val) { m_read = val; }
55
56 void SetWritable(LazyBool val) { m_write = val; }
57
58 void SetExecutable(LazyBool val) { m_execute = val; }
59
60 void SetShared(LazyBool val) { m_shared = val; }
61
62 void SetMapped(LazyBool val) { m_mapped = val; }
63
64 void SetName(const char *name) { m_name = ConstString(name); }
65
66 LazyBool GetFlash() const { return m_flash; }
67
68 void SetFlash(LazyBool val) { m_flash = val; }
69
71
72 void SetBlocksize(lldb::offset_t blocksize) { m_blocksize = blocksize; }
73
75 m_memory_tagged = val;
76 return *this;
77 }
78
81 return *this;
82 }
83
84 // Get permissions as a uint32_t that is a mask of one or more bits from the
85 // lldb::Permissions
86 uint32_t GetLLDBPermissions() const {
87 uint32_t permissions = 0;
88 if (m_read == eLazyBoolYes)
89 permissions |= lldb::ePermissionsReadable;
90 if (m_write == eLazyBoolYes)
91 permissions |= lldb::ePermissionsWritable;
93 permissions |= lldb::ePermissionsExecutable;
94 return permissions;
95 }
96
97 // Set permissions from a uint32_t that contains one or more bits from the
98 // lldb::Permissions
99 void SetLLDBPermissions(uint32_t permissions) {
100 m_read =
101 (permissions & lldb::ePermissionsReadable) ? eLazyBoolYes : eLazyBoolNo;
102 m_write =
103 (permissions & lldb::ePermissionsWritable) ? eLazyBoolYes : eLazyBoolNo;
104 m_execute = (permissions & lldb::ePermissionsExecutable) ? eLazyBoolYes
105 : eLazyBoolNo;
106 }
107
108 bool operator==(const MemoryRegionInfo &rhs) const {
109 return m_range == rhs.m_range && m_read == rhs.m_read &&
110 m_write == rhs.m_write && m_execute == rhs.m_execute &&
111 m_shared == rhs.m_shared && m_mapped == rhs.m_mapped &&
112 m_name == rhs.m_name && m_flash == rhs.m_flash &&
113 m_blocksize == rhs.m_blocksize &&
115 m_pagesize == rhs.m_pagesize &&
118 }
119
120 bool operator!=(const MemoryRegionInfo &rhs) const { return !(*this == rhs); }
121
122 /// Get the target system's VM page size in bytes.
123 /// \return
124 /// 0 is returned if this information is unavailable.
125 int GetPageSize() const { return m_pagesize; }
126
127 /// Get a vector of target VM pages that are dirty -- that have been
128 /// modified -- within this memory region. This is an Optional return
129 /// value; it will only be available if the remote stub was able to
130 /// detail this.
131 const std::optional<std::vector<lldb::addr_t>> &GetDirtyPageList() const {
132 return m_dirty_pages;
133 }
134
136
138
139 void SetPageSize(int pagesize) { m_pagesize = pagesize; }
140
141 void SetDirtyPageList(std::vector<lldb::addr_t> pagelist) {
142 if (m_dirty_pages)
143 m_dirty_pages->clear();
144 m_dirty_pages = std::move(pagelist);
145 }
146
147protected:
160 int m_pagesize = 0;
161 std::optional<std::vector<lldb::addr_t>> m_dirty_pages;
162};
163
164inline bool operator<(const MemoryRegionInfo &lhs,
165 const MemoryRegionInfo &rhs) {
166 return lhs.GetRange() < rhs.GetRange();
167}
168
169inline bool operator<(const MemoryRegionInfo &lhs, lldb::addr_t rhs) {
170 return lhs.GetRange().GetRangeBase() < rhs;
171}
172
173inline bool operator<(lldb::addr_t lhs, const MemoryRegionInfo &rhs) {
174 return lhs < rhs.GetRange().GetRangeBase();
175}
176
177llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
178 const MemoryRegionInfo &Info);
179
180// Forward-declarable wrapper.
181class MemoryRegionInfos : public std::vector<lldb_private::MemoryRegionInfo> {
182public:
183 using std::vector<lldb_private::MemoryRegionInfo>::vector;
184};
185
186} // namespace lldb_private
187
188namespace llvm {
189template <>
190/// If Options is empty, prints a textual representation of the value. If
191/// Options is a single character, it uses that character for the "yes" value,
192/// while "no" is printed as "-", and "don't know" as "?". This can be used to
193/// print the permissions in the traditional "rwx" form.
194struct format_provider<lldb_private::LazyBool> {
195 static void format(const lldb_private::LazyBool &B, raw_ostream &OS,
196 StringRef Options);
197};
198} // namespace llvm
199
200#endif // LLDB_TARGET_MEMORYREGIONINFO_H
A uniqued constant string class.
Definition ConstString.h:40
int GetPageSize() const
Get the target system's VM page size in bytes.
MemoryRegionInfo & SetMemoryTagged(LazyBool val)
void SetBlocksize(lldb::offset_t blocksize)
bool operator!=(const MemoryRegionInfo &rhs) const
std::optional< std::vector< lldb::addr_t > > m_dirty_pages
void SetName(const char *name)
bool operator==(const MemoryRegionInfo &rhs) const
Range< lldb::addr_t, lldb::addr_t > RangeType
MemoryRegionInfo & SetIsShadowStack(LazyBool val)
lldb::offset_t GetBlocksize() const
const RangeType & GetRange() const
const std::optional< std::vector< lldb::addr_t > > & GetDirtyPageList() const
Get a vector of target VM pages that are dirty – that have been modified – within this memory region.
MemoryRegionInfo(RangeType range, LazyBool read, LazyBool write, LazyBool execute, LazyBool shared, LazyBool mapped, ConstString name)
void SetDirtyPageList(std::vector< lldb::addr_t > pagelist)
void SetLLDBPermissions(uint32_t permissions)
A class that represents a running process on the host machine.
Stream & operator<<(Stream &s, const Mangled &obj)
bool operator<(const Address &lhs, const Address &rhs)
Definition Address.cpp:979
uint64_t offset_t
Definition lldb-types.h:85
uint64_t addr_t
Definition lldb-types.h:80
BaseType GetRangeBase() const
Definition RangeMap.h:45
static void format(const lldb_private::LazyBool &B, raw_ostream &OS, StringRef Options)