1178825Sdfr//===-- SBMemoryRegionInfo.cpp ----------------------------------*- C++ -*-===// 2233294Sstas// 3233294Sstas// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4233294Sstas// See https://llvm.org/LICENSE.txt for license information. 5178825Sdfr// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6233294Sstas// 7233294Sstas//===----------------------------------------------------------------------===// 8233294Sstas 9178825Sdfr#include "lldb/API/SBMemoryRegionInfo.h" 10233294Sstas#include "SBReproducerPrivate.h" 11233294Sstas#include "Utils.h" 12178825Sdfr#include "lldb/API/SBDefines.h" 13233294Sstas#include "lldb/API/SBError.h" 14233294Sstas#include "lldb/API/SBStream.h" 15233294Sstas#include "lldb/Target/MemoryRegionInfo.h" 16178825Sdfr#include "lldb/Utility/StreamString.h" 17233294Sstas 18233294Sstasusing namespace lldb; 19233294Sstasusing namespace lldb_private; 20178825Sdfr 21233294SstasSBMemoryRegionInfo::SBMemoryRegionInfo() : m_opaque_up(new MemoryRegionInfo()) { 22233294Sstas LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBMemoryRegionInfo); 23233294Sstas} 24233294Sstas 25233294SstasSBMemoryRegionInfo::SBMemoryRegionInfo(const MemoryRegionInfo *lldb_object_ptr) 26233294Sstas : m_opaque_up(new MemoryRegionInfo()) { 27233294Sstas if (lldb_object_ptr) 28233294Sstas ref() = *lldb_object_ptr; 29233294Sstas} 30233294Sstas 31233294SstasSBMemoryRegionInfo::SBMemoryRegionInfo(const SBMemoryRegionInfo &rhs) 32178825Sdfr : m_opaque_up() { 33178825Sdfr LLDB_RECORD_CONSTRUCTOR(SBMemoryRegionInfo, 34233294Sstas (const lldb::SBMemoryRegionInfo &), rhs); 35178825Sdfr m_opaque_up = clone(rhs.m_opaque_up); 36178825Sdfr} 37178825Sdfr 38178825Sdfrconst SBMemoryRegionInfo &SBMemoryRegionInfo:: 39178825Sdfroperator=(const SBMemoryRegionInfo &rhs) { 40178825Sdfr LLDB_RECORD_METHOD( 41178825Sdfr const lldb::SBMemoryRegionInfo &, 42178825Sdfr SBMemoryRegionInfo, operator=,(const lldb::SBMemoryRegionInfo &), rhs); 43178825Sdfr 44178825Sdfr if (this != &rhs) 45178825Sdfr m_opaque_up = clone(rhs.m_opaque_up); 46178825Sdfr return LLDB_RECORD_RESULT(*this); 47178825Sdfr} 48178825Sdfr 49178825SdfrSBMemoryRegionInfo::~SBMemoryRegionInfo() {} 50178825Sdfr 51178825Sdfrvoid SBMemoryRegionInfo::Clear() { 52178825Sdfr LLDB_RECORD_METHOD_NO_ARGS(void, SBMemoryRegionInfo, Clear); 53178825Sdfr 54233294Sstas m_opaque_up->Clear(); 55178825Sdfr} 56178825Sdfr 57178825Sdfrbool SBMemoryRegionInfo::operator==(const SBMemoryRegionInfo &rhs) const { 58233294Sstas LLDB_RECORD_METHOD_CONST( 59178825Sdfr bool, SBMemoryRegionInfo, operator==,(const lldb::SBMemoryRegionInfo &), 60233294Sstas rhs); 61233294Sstas 62233294Sstas return ref() == rhs.ref(); 63233294Sstas} 64233294Sstas 65178825Sdfrbool SBMemoryRegionInfo::operator!=(const SBMemoryRegionInfo &rhs) const { 66178825Sdfr LLDB_RECORD_METHOD_CONST( 67233294Sstas bool, SBMemoryRegionInfo, operator!=,(const lldb::SBMemoryRegionInfo &), 68178825Sdfr rhs); 69233294Sstas 70233294Sstas return ref() != rhs.ref(); 71233294Sstas} 72233294Sstas 73233294SstasMemoryRegionInfo &SBMemoryRegionInfo::ref() { return *m_opaque_up; } 74178825Sdfr 75178825Sdfrconst MemoryRegionInfo &SBMemoryRegionInfo::ref() const { return *m_opaque_up; } 76233294Sstas 77233294Sstaslldb::addr_t SBMemoryRegionInfo::GetRegionBase() { 78178825Sdfr LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBMemoryRegionInfo, GetRegionBase); 79178825Sdfr 80178825Sdfr return m_opaque_up->GetRange().GetRangeBase(); 81178825Sdfr} 82178825Sdfr 83178825Sdfrlldb::addr_t SBMemoryRegionInfo::GetRegionEnd() { 84178825Sdfr LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBMemoryRegionInfo, GetRegionEnd); 85178825Sdfr 86178825Sdfr return m_opaque_up->GetRange().GetRangeEnd(); 87178825Sdfr} 88178825Sdfr 89178825Sdfrbool SBMemoryRegionInfo::IsReadable() { 90 LLDB_RECORD_METHOD_NO_ARGS(bool, SBMemoryRegionInfo, IsReadable); 91 92 return m_opaque_up->GetReadable() == MemoryRegionInfo::eYes; 93} 94 95bool SBMemoryRegionInfo::IsWritable() { 96 LLDB_RECORD_METHOD_NO_ARGS(bool, SBMemoryRegionInfo, IsWritable); 97 98 return m_opaque_up->GetWritable() == MemoryRegionInfo::eYes; 99} 100 101bool SBMemoryRegionInfo::IsExecutable() { 102 LLDB_RECORD_METHOD_NO_ARGS(bool, SBMemoryRegionInfo, IsExecutable); 103 104 return m_opaque_up->GetExecutable() == MemoryRegionInfo::eYes; 105} 106 107bool SBMemoryRegionInfo::IsMapped() { 108 LLDB_RECORD_METHOD_NO_ARGS(bool, SBMemoryRegionInfo, IsMapped); 109 110 return m_opaque_up->GetMapped() == MemoryRegionInfo::eYes; 111} 112 113const char *SBMemoryRegionInfo::GetName() { 114 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBMemoryRegionInfo, GetName); 115 116 return m_opaque_up->GetName().AsCString(); 117} 118 119bool SBMemoryRegionInfo::GetDescription(SBStream &description) { 120 LLDB_RECORD_METHOD(bool, SBMemoryRegionInfo, GetDescription, 121 (lldb::SBStream &), description); 122 123 Stream &strm = description.ref(); 124 const addr_t load_addr = m_opaque_up->GetRange().base; 125 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" : "-"); 131 strm.Printf("]"); 132 133 return true; 134} 135 136namespace lldb_private { 137namespace repro { 138 139template <> 140void 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( 149 bool, 150 SBMemoryRegionInfo, operator==,(const lldb::SBMemoryRegionInfo &)); 151 LLDB_REGISTER_METHOD_CONST( 152 bool, 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, 162 (lldb::SBStream &)); 163} 164 165} 166} 167