1 //===-- SBMemoryRegionInfoList.cpp ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBMemoryRegionInfoList.h"
11 #include "lldb/API/SBMemoryRegionInfo.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Target/MemoryRegionInfo.h"
14 #include "lldb/Utility/Log.h"
19 using namespace lldb_private;
21 class MemoryRegionInfoListImpl {
23 MemoryRegionInfoListImpl() : m_regions() {}
25 MemoryRegionInfoListImpl(const MemoryRegionInfoListImpl &rhs)
26 : m_regions(rhs.m_regions) {}
28 MemoryRegionInfoListImpl &operator=(const MemoryRegionInfoListImpl &rhs) {
31 m_regions = rhs.m_regions;
35 size_t GetSize() const { return m_regions.size(); }
37 void Reserve(size_t capacity) { return m_regions.reserve(capacity); }
39 void Append(const MemoryRegionInfo &sb_region) {
40 m_regions.push_back(sb_region);
43 void Append(const MemoryRegionInfoListImpl &list) {
44 Reserve(GetSize() + list.GetSize());
46 for (const auto &val : list.m_regions)
50 void Clear() { m_regions.clear(); }
52 bool GetMemoryRegionInfoAtIndex(size_t index,
53 MemoryRegionInfo ®ion_info) {
54 if (index >= GetSize())
56 region_info = m_regions[index];
60 MemoryRegionInfos &Ref() { return m_regions; }
62 const MemoryRegionInfos &Ref() const { return m_regions; }
65 MemoryRegionInfos m_regions;
68 MemoryRegionInfos &SBMemoryRegionInfoList::ref() {
69 return m_opaque_ap->Ref();
72 const MemoryRegionInfos &SBMemoryRegionInfoList::ref() const {
73 return m_opaque_ap->Ref();
76 SBMemoryRegionInfoList::SBMemoryRegionInfoList()
77 : m_opaque_ap(new MemoryRegionInfoListImpl()) {}
79 SBMemoryRegionInfoList::SBMemoryRegionInfoList(
80 const SBMemoryRegionInfoList &rhs)
81 : m_opaque_ap(new MemoryRegionInfoListImpl(*rhs.m_opaque_ap)) {}
83 SBMemoryRegionInfoList::~SBMemoryRegionInfoList() {}
85 const SBMemoryRegionInfoList &SBMemoryRegionInfoList::
86 operator=(const SBMemoryRegionInfoList &rhs) {
88 *m_opaque_ap = *rhs.m_opaque_ap;
93 uint32_t SBMemoryRegionInfoList::GetSize() const {
94 return m_opaque_ap->GetSize();
97 bool SBMemoryRegionInfoList::GetMemoryRegionAtIndex(
98 uint32_t idx, SBMemoryRegionInfo ®ion_info) {
99 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
101 bool result = m_opaque_ap->GetMemoryRegionInfoAtIndex(idx, region_info.ref());
105 region_info.GetDescription(sstr);
106 log->Printf("SBMemoryRegionInfoList::GetMemoryRegionAtIndex (this.ap=%p, "
107 "idx=%d) => SBMemoryRegionInfo (this.ap=%p, '%s')",
108 static_cast<void *>(m_opaque_ap.get()), idx,
109 static_cast<void *>(region_info.m_opaque_ap.get()),
116 void SBMemoryRegionInfoList::Clear() { m_opaque_ap->Clear(); }
118 void SBMemoryRegionInfoList::Append(SBMemoryRegionInfo &sb_region) {
119 m_opaque_ap->Append(sb_region.ref());
122 void SBMemoryRegionInfoList::Append(SBMemoryRegionInfoList &sb_region_list) {
123 m_opaque_ap->Append(*sb_region_list);
126 const MemoryRegionInfoListImpl *SBMemoryRegionInfoList::operator->() const {
127 return m_opaque_ap.get();
130 const MemoryRegionInfoListImpl &SBMemoryRegionInfoList::operator*() const {
131 assert(m_opaque_ap.get());