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