1 //===-- SBMemoryRegionInfoList.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/SBMemoryRegionInfoList.h" 12 #include "lldb/API/SBStream.h" 13 #include "lldb/Core/Log.h" 14 #include "lldb/Target/MemoryRegionInfo.h" 15 16 #include <vector> 17 18 using namespace lldb; 19 using namespace lldb_private; 20 21 class MemoryRegionInfoListImpl 22 { 23 public: 24 MemoryRegionInfoListImpl () : 25 m_regions() 26 { 27 } 28 29 MemoryRegionInfoListImpl (const MemoryRegionInfoListImpl& rhs) : 30 m_regions(rhs.m_regions) 31 { 32 } 33 34 MemoryRegionInfoListImpl& 35 operator = (const MemoryRegionInfoListImpl& rhs) 36 { 37 if (this == &rhs) 38 return *this; 39 m_regions = rhs.m_regions; 40 return *this; 41 } 42 43 uint32_t 44 GetSize () 45 { 46 return m_regions.size(); 47 } 48 49 void 50 Append (const lldb::SBMemoryRegionInfo& sb_region) 51 { 52 m_regions.push_back(sb_region); 53 } 54 55 void 56 Append (const MemoryRegionInfoListImpl& list) 57 { 58 for (auto val : list.m_regions) 59 Append (val); 60 } 61 62 void 63 Clear () 64 { 65 m_regions.clear(); 66 } 67 68 bool 69 GetMemoryRegionInfoAtIndex (uint32_t index, SBMemoryRegionInfo ®ion_info) 70 { 71 if (index >= GetSize()) 72 return false; 73 region_info = m_regions[index]; 74 return true; 75 } 76 77 private: 78 std::vector<lldb::SBMemoryRegionInfo> m_regions; 79 }; 80 81 SBMemoryRegionInfoList::SBMemoryRegionInfoList () : 82 m_opaque_ap (new MemoryRegionInfoListImpl()) 83 { 84 } 85 86 SBMemoryRegionInfoList::SBMemoryRegionInfoList (const SBMemoryRegionInfoList& rhs) : 87 m_opaque_ap (new MemoryRegionInfoListImpl(*rhs.m_opaque_ap)) 88 { 89 } 90 91 SBMemoryRegionInfoList::~SBMemoryRegionInfoList () 92 { 93 } 94 95 const SBMemoryRegionInfoList & 96 SBMemoryRegionInfoList::operator = (const SBMemoryRegionInfoList &rhs) 97 { 98 if (this != &rhs) 99 { 100 *m_opaque_ap = *rhs.m_opaque_ap; 101 } 102 return *this; 103 } 104 105 uint32_t 106 SBMemoryRegionInfoList::GetSize() const 107 { 108 return m_opaque_ap->GetSize(); 109 } 110 111 112 bool 113 SBMemoryRegionInfoList::GetMemoryRegionAtIndex (uint32_t idx, SBMemoryRegionInfo ®ion_info) 114 { 115 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 116 117 bool result = m_opaque_ap->GetMemoryRegionInfoAtIndex(idx, region_info); 118 119 if (log) 120 { 121 SBStream sstr; 122 region_info.GetDescription (sstr); 123 log->Printf ("SBMemoryRegionInfoList::GetMemoryRegionAtIndex (this.ap=%p, idx=%d) => SBMemoryRegionInfo (this.ap=%p, '%s')", 124 static_cast<void*>(m_opaque_ap.get()), idx, 125 static_cast<void*>(region_info.m_opaque_ap.get()), sstr.GetData()); 126 } 127 128 return result; 129 } 130 131 void 132 SBMemoryRegionInfoList::Clear() 133 { 134 135 m_opaque_ap->Clear(); 136 } 137 138 void 139 SBMemoryRegionInfoList::Append(SBMemoryRegionInfo &sb_region) 140 { 141 m_opaque_ap->Append(sb_region); 142 } 143 144 void 145 SBMemoryRegionInfoList::Append(SBMemoryRegionInfoList &sb_region_list) 146 { 147 m_opaque_ap->Append(*sb_region_list); 148 } 149 150 const MemoryRegionInfoListImpl * 151 SBMemoryRegionInfoList::operator->() const 152 { 153 return m_opaque_ap.get(); 154 } 155 156 const MemoryRegionInfoListImpl& 157 SBMemoryRegionInfoList::operator*() const 158 { 159 assert (m_opaque_ap.get()); 160 return *m_opaque_ap.get(); 161 } 162 163