1 //===-- SBMemoryRegionInfoList.cpp ------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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"
18 using namespace lldb_private;
20 class MemoryRegionInfoListImpl {
22 MemoryRegionInfoListImpl() : m_regions() {}
24 MemoryRegionInfoListImpl(const MemoryRegionInfoListImpl &rhs)
25 : m_regions(rhs.m_regions) {}
27 MemoryRegionInfoListImpl &operator=(const MemoryRegionInfoListImpl &rhs) {
30 m_regions = rhs.m_regions;
34 size_t GetSize() const { return m_regions.size(); }
36 void Reserve(size_t capacity) { return m_regions.reserve(capacity); }
38 void Append(const MemoryRegionInfo &sb_region) {
39 m_regions.push_back(sb_region);
42 void Append(const MemoryRegionInfoListImpl &list) {
43 Reserve(GetSize() + list.GetSize());
45 for (const auto &val : list.m_regions)
49 void Clear() { m_regions.clear(); }
51 bool GetMemoryRegionInfoAtIndex(size_t index,
52 MemoryRegionInfo ®ion_info) {
53 if (index >= GetSize())
55 region_info = m_regions[index];
59 MemoryRegionInfos &Ref() { return m_regions; }
61 const MemoryRegionInfos &Ref() const { return m_regions; }
64 MemoryRegionInfos m_regions;
67 MemoryRegionInfos &SBMemoryRegionInfoList::ref() { return m_opaque_up->Ref(); }
69 const MemoryRegionInfos &SBMemoryRegionInfoList::ref() const {
70 return m_opaque_up->Ref();
73 SBMemoryRegionInfoList::SBMemoryRegionInfoList()
74 : m_opaque_up(new MemoryRegionInfoListImpl()) {
75 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBMemoryRegionInfoList);
78 SBMemoryRegionInfoList::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);
85 SBMemoryRegionInfoList::~SBMemoryRegionInfoList() {}
87 const SBMemoryRegionInfoList &SBMemoryRegionInfoList::
88 operator=(const SBMemoryRegionInfoList &rhs) {
90 const lldb::SBMemoryRegionInfoList &,
91 SBMemoryRegionInfoList, operator=,(const lldb::SBMemoryRegionInfoList &),
95 *m_opaque_up = *rhs.m_opaque_up;
97 return LLDB_RECORD_RESULT(*this);
100 uint32_t SBMemoryRegionInfoList::GetSize() const {
101 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBMemoryRegionInfoList, GetSize);
103 return m_opaque_up->GetSize();
106 bool SBMemoryRegionInfoList::GetMemoryRegionAtIndex(
107 uint32_t idx, SBMemoryRegionInfo ®ion_info) {
108 LLDB_RECORD_METHOD(bool, SBMemoryRegionInfoList, GetMemoryRegionAtIndex,
109 (uint32_t, lldb::SBMemoryRegionInfo &), idx, region_info);
111 return m_opaque_up->GetMemoryRegionInfoAtIndex(idx, region_info.ref());
114 void SBMemoryRegionInfoList::Clear() {
115 LLDB_RECORD_METHOD_NO_ARGS(void, SBMemoryRegionInfoList, Clear);
117 m_opaque_up->Clear();
120 void SBMemoryRegionInfoList::Append(SBMemoryRegionInfo &sb_region) {
121 LLDB_RECORD_METHOD(void, SBMemoryRegionInfoList, Append,
122 (lldb::SBMemoryRegionInfo &), sb_region);
124 m_opaque_up->Append(sb_region.ref());
127 void SBMemoryRegionInfoList::Append(SBMemoryRegionInfoList &sb_region_list) {
128 LLDB_RECORD_METHOD(void, SBMemoryRegionInfoList, Append,
129 (lldb::SBMemoryRegionInfoList &), sb_region_list);
131 m_opaque_up->Append(*sb_region_list);
134 const MemoryRegionInfoListImpl *SBMemoryRegionInfoList::operator->() const {
135 return m_opaque_up.get();
138 const MemoryRegionInfoListImpl &SBMemoryRegionInfoList::operator*() const {
139 assert(m_opaque_up.get());
143 namespace lldb_private {
147 void 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 &));