1 //===-- SBMemoryRegionInfo.cpp ----------------------------------*- C++ -*-===//
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() {}
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::GetDescription(SBStream
&description
) {
120 LLDB_RECORD_METHOD(bool, SBMemoryRegionInfo
, GetDescription
,
121 (lldb::SBStream
&), description
);
123 Stream
&strm
= description
.ref();
124 const addr_t load_addr
= m_opaque_up
->GetRange().base
;
126 strm
.Printf("[0x%16.16" PRIx64
"-0x%16.16" PRIx64
" ", load_addr
,
127 load_addr
+ m_opaque_up
->GetRange().size
);
128 strm
.Printf(m_opaque_up
->GetReadable() ? "R" : "-");
129 strm
.Printf(m_opaque_up
->GetWritable() ? "W" : "-");
130 strm
.Printf(m_opaque_up
->GetExecutable() ? "X" : "-");
136 namespace lldb_private
{
140 void RegisterMethods
<SBMemoryRegionInfo
>(Registry
&R
) {
141 LLDB_REGISTER_CONSTRUCTOR(SBMemoryRegionInfo
, ());
142 LLDB_REGISTER_CONSTRUCTOR(SBMemoryRegionInfo
,
143 (const lldb::SBMemoryRegionInfo
&));
144 LLDB_REGISTER_METHOD(
145 const lldb::SBMemoryRegionInfo
&,
146 SBMemoryRegionInfo
, operator=,(const lldb::SBMemoryRegionInfo
&));
147 LLDB_REGISTER_METHOD(void, SBMemoryRegionInfo
, Clear
, ());
148 LLDB_REGISTER_METHOD_CONST(
150 SBMemoryRegionInfo
, operator==,(const lldb::SBMemoryRegionInfo
&));
151 LLDB_REGISTER_METHOD_CONST(
153 SBMemoryRegionInfo
, operator!=,(const lldb::SBMemoryRegionInfo
&));
154 LLDB_REGISTER_METHOD(lldb::addr_t
, SBMemoryRegionInfo
, GetRegionBase
, ());
155 LLDB_REGISTER_METHOD(lldb::addr_t
, SBMemoryRegionInfo
, GetRegionEnd
, ());
156 LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo
, IsReadable
, ());
157 LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo
, IsWritable
, ());
158 LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo
, IsExecutable
, ());
159 LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo
, IsMapped
, ());
160 LLDB_REGISTER_METHOD(const char *, SBMemoryRegionInfo
, GetName
, ());
161 LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo
, GetDescription
,