1 //===-- SBMemoryRegionInfo.cpp --------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBMemoryRegionInfo.h"
10 #include "SBReproducerPrivate.h"
12 #include "lldb/API/SBDefines.h"
13 #include "lldb/API/SBError.h"
14 #include "lldb/API/SBStream.h"
15 #include "lldb/Target/MemoryRegionInfo.h"
16 #include "lldb/Utility/StreamString.h"
19 using namespace lldb_private;
21 SBMemoryRegionInfo::SBMemoryRegionInfo() : m_opaque_up(new MemoryRegionInfo()) {
22 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBMemoryRegionInfo);
25 SBMemoryRegionInfo::SBMemoryRegionInfo(const MemoryRegionInfo *lldb_object_ptr)
26 : m_opaque_up(new MemoryRegionInfo()) {
28 ref() = *lldb_object_ptr;
31 SBMemoryRegionInfo::SBMemoryRegionInfo(const SBMemoryRegionInfo &rhs)
33 LLDB_RECORD_CONSTRUCTOR(SBMemoryRegionInfo,
34 (const lldb::SBMemoryRegionInfo &), rhs);
35 m_opaque_up = clone(rhs.m_opaque_up);
38 const SBMemoryRegionInfo &SBMemoryRegionInfo::
39 operator=(const SBMemoryRegionInfo &rhs) {
41 const lldb::SBMemoryRegionInfo &,
42 SBMemoryRegionInfo, operator=,(const lldb::SBMemoryRegionInfo &), rhs);
45 m_opaque_up = clone(rhs.m_opaque_up);
46 return LLDB_RECORD_RESULT(*this);
49 SBMemoryRegionInfo::~SBMemoryRegionInfo() = default;
51 void SBMemoryRegionInfo::Clear() {
52 LLDB_RECORD_METHOD_NO_ARGS(void, SBMemoryRegionInfo, Clear);
57 bool SBMemoryRegionInfo::operator==(const SBMemoryRegionInfo &rhs) const {
58 LLDB_RECORD_METHOD_CONST(
59 bool, SBMemoryRegionInfo, operator==,(const lldb::SBMemoryRegionInfo &),
62 return ref() == rhs.ref();
65 bool SBMemoryRegionInfo::operator!=(const SBMemoryRegionInfo &rhs) const {
66 LLDB_RECORD_METHOD_CONST(
67 bool, SBMemoryRegionInfo, operator!=,(const lldb::SBMemoryRegionInfo &),
70 return ref() != rhs.ref();
73 MemoryRegionInfo &SBMemoryRegionInfo::ref() { return *m_opaque_up; }
75 const MemoryRegionInfo &SBMemoryRegionInfo::ref() const { return *m_opaque_up; }
77 lldb::addr_t SBMemoryRegionInfo::GetRegionBase() {
78 LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBMemoryRegionInfo, GetRegionBase);
80 return m_opaque_up->GetRange().GetRangeBase();
83 lldb::addr_t SBMemoryRegionInfo::GetRegionEnd() {
84 LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBMemoryRegionInfo, GetRegionEnd);
86 return m_opaque_up->GetRange().GetRangeEnd();
89 bool SBMemoryRegionInfo::IsReadable() {
90 LLDB_RECORD_METHOD_NO_ARGS(bool, SBMemoryRegionInfo, IsReadable);
92 return m_opaque_up->GetReadable() == MemoryRegionInfo::eYes;
95 bool SBMemoryRegionInfo::IsWritable() {
96 LLDB_RECORD_METHOD_NO_ARGS(bool, SBMemoryRegionInfo, IsWritable);
98 return m_opaque_up->GetWritable() == MemoryRegionInfo::eYes;
101 bool SBMemoryRegionInfo::IsExecutable() {
102 LLDB_RECORD_METHOD_NO_ARGS(bool, SBMemoryRegionInfo, IsExecutable);
104 return m_opaque_up->GetExecutable() == MemoryRegionInfo::eYes;
107 bool SBMemoryRegionInfo::IsMapped() {
108 LLDB_RECORD_METHOD_NO_ARGS(bool, SBMemoryRegionInfo, IsMapped);
110 return m_opaque_up->GetMapped() == MemoryRegionInfo::eYes;
113 const char *SBMemoryRegionInfo::GetName() {
114 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBMemoryRegionInfo, GetName);
116 return m_opaque_up->GetName().AsCString();
119 bool SBMemoryRegionInfo::HasDirtyMemoryPageList() {
120 LLDB_RECORD_METHOD_NO_ARGS(bool, SBMemoryRegionInfo, HasDirtyMemoryPageList);
122 return m_opaque_up->GetDirtyPageList().hasValue();
125 uint32_t SBMemoryRegionInfo::GetNumDirtyPages() {
126 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBMemoryRegionInfo, GetNumDirtyPages);
128 uint32_t num_dirty_pages = 0;
129 llvm::Optional<std::vector<addr_t>> dirty_page_list =
130 m_opaque_up->GetDirtyPageList();
131 if (dirty_page_list.hasValue())
132 num_dirty_pages = dirty_page_list.getValue().size();
134 return num_dirty_pages;
137 addr_t SBMemoryRegionInfo::GetDirtyPageAddressAtIndex(uint32_t idx) {
138 LLDB_RECORD_METHOD(addr_t, SBMemoryRegionInfo, GetDirtyPageAddressAtIndex,
141 addr_t dirty_page_addr = LLDB_INVALID_ADDRESS;
142 const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
143 m_opaque_up->GetDirtyPageList();
144 if (dirty_page_list.hasValue() && idx < dirty_page_list.getValue().size())
145 dirty_page_addr = dirty_page_list.getValue()[idx];
147 return dirty_page_addr;
150 int SBMemoryRegionInfo::GetPageSize() {
151 LLDB_RECORD_METHOD_NO_ARGS(int, SBMemoryRegionInfo, GetPageSize);
152 return m_opaque_up->GetPageSize();
155 bool SBMemoryRegionInfo::GetDescription(SBStream &description) {
156 LLDB_RECORD_METHOD(bool, SBMemoryRegionInfo, GetDescription,
157 (lldb::SBStream &), description);
159 Stream &strm = description.ref();
160 const addr_t load_addr = m_opaque_up->GetRange().base;
162 strm.Printf("[0x%16.16" PRIx64 "-0x%16.16" PRIx64 " ", load_addr,
163 load_addr + m_opaque_up->GetRange().size);
164 strm.Printf(m_opaque_up->GetReadable() ? "R" : "-");
165 strm.Printf(m_opaque_up->GetWritable() ? "W" : "-");
166 strm.Printf(m_opaque_up->GetExecutable() ? "X" : "-");
172 namespace lldb_private {
176 void RegisterMethods<SBMemoryRegionInfo>(Registry &R) {
177 LLDB_REGISTER_CONSTRUCTOR(SBMemoryRegionInfo, ());
178 LLDB_REGISTER_CONSTRUCTOR(SBMemoryRegionInfo,
179 (const lldb::SBMemoryRegionInfo &));
180 LLDB_REGISTER_METHOD(
181 const lldb::SBMemoryRegionInfo &,
182 SBMemoryRegionInfo, operator=,(const lldb::SBMemoryRegionInfo &));
183 LLDB_REGISTER_METHOD(void, SBMemoryRegionInfo, Clear, ());
184 LLDB_REGISTER_METHOD_CONST(
186 SBMemoryRegionInfo, operator==,(const lldb::SBMemoryRegionInfo &));
187 LLDB_REGISTER_METHOD_CONST(
189 SBMemoryRegionInfo, operator!=,(const lldb::SBMemoryRegionInfo &));
190 LLDB_REGISTER_METHOD(lldb::addr_t, SBMemoryRegionInfo, GetRegionBase, ());
191 LLDB_REGISTER_METHOD(lldb::addr_t, SBMemoryRegionInfo, GetRegionEnd, ());
192 LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, IsReadable, ());
193 LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, IsWritable, ());
194 LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, IsExecutable, ());
195 LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, IsMapped, ());
196 LLDB_REGISTER_METHOD(const char *, SBMemoryRegionInfo, GetName, ());
197 LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, GetDescription,