]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/API/SBMemoryRegionInfo.cpp
MFV 316891
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / API / SBMemoryRegionInfo.cpp
1 //===-- SBMemoryRegionInfo.cpp ----------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/API/SBMemoryRegionInfo.h"
11 #include "lldb/API/SBDefines.h"
12 #include "lldb/API/SBError.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/Core/StreamString.h"
15 #include "lldb/Target/MemoryRegionInfo.h"
16
17 using namespace lldb;
18 using namespace lldb_private;
19
20 SBMemoryRegionInfo::SBMemoryRegionInfo()
21     : m_opaque_ap(new MemoryRegionInfo()) {}
22
23 SBMemoryRegionInfo::SBMemoryRegionInfo(const MemoryRegionInfo *lldb_object_ptr)
24     : m_opaque_ap(new MemoryRegionInfo()) {
25   if (lldb_object_ptr)
26     ref() = *lldb_object_ptr;
27 }
28
29 SBMemoryRegionInfo::SBMemoryRegionInfo(const SBMemoryRegionInfo &rhs)
30     : m_opaque_ap(new MemoryRegionInfo()) {
31   ref() = rhs.ref();
32 }
33
34 const SBMemoryRegionInfo &SBMemoryRegionInfo::
35 operator=(const SBMemoryRegionInfo &rhs) {
36   if (this != &rhs) {
37     ref() = rhs.ref();
38   }
39   return *this;
40 }
41
42 SBMemoryRegionInfo::~SBMemoryRegionInfo() {}
43
44 void SBMemoryRegionInfo::Clear() { m_opaque_ap->Clear(); }
45
46 bool SBMemoryRegionInfo::operator==(const SBMemoryRegionInfo &rhs) const {
47   return ref() == rhs.ref();
48 }
49
50 bool SBMemoryRegionInfo::operator!=(const SBMemoryRegionInfo &rhs) const {
51   return ref() != rhs.ref();
52 }
53
54 MemoryRegionInfo &SBMemoryRegionInfo::ref() { return *m_opaque_ap; }
55
56 const MemoryRegionInfo &SBMemoryRegionInfo::ref() const { return *m_opaque_ap; }
57
58 lldb::addr_t SBMemoryRegionInfo::GetRegionBase() {
59   return m_opaque_ap->GetRange().GetRangeBase();
60 }
61
62 lldb::addr_t SBMemoryRegionInfo::GetRegionEnd() {
63   return m_opaque_ap->GetRange().GetRangeEnd();
64 }
65
66 bool SBMemoryRegionInfo::IsReadable() {
67   return m_opaque_ap->GetReadable() == MemoryRegionInfo::eYes;
68 }
69
70 bool SBMemoryRegionInfo::IsWritable() {
71   return m_opaque_ap->GetWritable() == MemoryRegionInfo::eYes;
72 }
73
74 bool SBMemoryRegionInfo::IsExecutable() {
75   return m_opaque_ap->GetExecutable() == MemoryRegionInfo::eYes;
76 }
77
78 bool SBMemoryRegionInfo::IsMapped() {
79   return m_opaque_ap->GetMapped() == MemoryRegionInfo::eYes;
80 }
81
82 const char *SBMemoryRegionInfo::GetName() {
83   return m_opaque_ap->GetName().AsCString();
84 }
85
86 bool SBMemoryRegionInfo::GetDescription(SBStream &description) {
87   Stream &strm = description.ref();
88   const addr_t load_addr = m_opaque_ap->GetRange().base;
89
90   strm.Printf("[0x%16.16" PRIx64 "-0x%16.16" PRIx64 " ", load_addr,
91               load_addr + m_opaque_ap->GetRange().size);
92   strm.Printf(m_opaque_ap->GetReadable() ? "R" : "-");
93   strm.Printf(m_opaque_ap->GetWritable() ? "W" : "-");
94   strm.Printf(m_opaque_ap->GetExecutable() ? "X" : "-");
95   strm.Printf("]");
96
97   return true;
98 }