1 //===-- SBMemoryRegionInfo.cpp ----------------------------------*- 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 #include "lldb/API/SBMemoryRegionInfo.h"
10 #include "lldb/API/SBDefines.h"
11 #include "lldb/API/SBError.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Target/MemoryRegionInfo.h"
14 #include "lldb/Utility/StreamString.h"
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
19 SBMemoryRegionInfo::SBMemoryRegionInfo()
20     : m_opaque_ap(new MemoryRegionInfo()) {}
21 
22 SBMemoryRegionInfo::SBMemoryRegionInfo(const MemoryRegionInfo *lldb_object_ptr)
23     : m_opaque_ap(new MemoryRegionInfo()) {
24   if (lldb_object_ptr)
25     ref() = *lldb_object_ptr;
26 }
27 
28 SBMemoryRegionInfo::SBMemoryRegionInfo(const SBMemoryRegionInfo &rhs)
29     : m_opaque_ap(new MemoryRegionInfo()) {
30   ref() = rhs.ref();
31 }
32 
33 const SBMemoryRegionInfo &SBMemoryRegionInfo::
34 operator=(const SBMemoryRegionInfo &rhs) {
35   if (this != &rhs) {
36     ref() = rhs.ref();
37   }
38   return *this;
39 }
40 
41 SBMemoryRegionInfo::~SBMemoryRegionInfo() {}
42 
43 void SBMemoryRegionInfo::Clear() { m_opaque_ap->Clear(); }
44 
45 bool SBMemoryRegionInfo::operator==(const SBMemoryRegionInfo &rhs) const {
46   return ref() == rhs.ref();
47 }
48 
49 bool SBMemoryRegionInfo::operator!=(const SBMemoryRegionInfo &rhs) const {
50   return ref() != rhs.ref();
51 }
52 
53 MemoryRegionInfo &SBMemoryRegionInfo::ref() { return *m_opaque_ap; }
54 
55 const MemoryRegionInfo &SBMemoryRegionInfo::ref() const { return *m_opaque_ap; }
56 
57 lldb::addr_t SBMemoryRegionInfo::GetRegionBase() {
58   return m_opaque_ap->GetRange().GetRangeBase();
59 }
60 
61 lldb::addr_t SBMemoryRegionInfo::GetRegionEnd() {
62   return m_opaque_ap->GetRange().GetRangeEnd();
63 }
64 
65 bool SBMemoryRegionInfo::IsReadable() {
66   return m_opaque_ap->GetReadable() == MemoryRegionInfo::eYes;
67 }
68 
69 bool SBMemoryRegionInfo::IsWritable() {
70   return m_opaque_ap->GetWritable() == MemoryRegionInfo::eYes;
71 }
72 
73 bool SBMemoryRegionInfo::IsExecutable() {
74   return m_opaque_ap->GetExecutable() == MemoryRegionInfo::eYes;
75 }
76 
77 bool SBMemoryRegionInfo::IsMapped() {
78   return m_opaque_ap->GetMapped() == MemoryRegionInfo::eYes;
79 }
80 
81 const char *SBMemoryRegionInfo::GetName() {
82   return m_opaque_ap->GetName().AsCString();
83 }
84 
85 bool SBMemoryRegionInfo::GetDescription(SBStream &description) {
86   Stream &strm = description.ref();
87   const addr_t load_addr = m_opaque_ap->GetRange().base;
88 
89   strm.Printf("[0x%16.16" PRIx64 "-0x%16.16" PRIx64 " ", load_addr,
90               load_addr + m_opaque_ap->GetRange().size);
91   strm.Printf(m_opaque_ap->GetReadable() ? "R" : "-");
92   strm.Printf(m_opaque_ap->GetWritable() ? "W" : "-");
93   strm.Printf(m_opaque_ap->GetExecutable() ? "X" : "-");
94   strm.Printf("]");
95 
96   return true;
97 }
98