1 //===-- SBMemoryRegionInfoList.cpp ----------------------------------------===//
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 "lldb/API/SBMemoryRegionInfo.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Target/MemoryRegionInfo.h"
13 #include "lldb/Utility/Instrumentation.h"
18 using namespace lldb_private
;
20 class MemoryRegionInfoListImpl
{
22 MemoryRegionInfoListImpl() : m_regions() {}
24 MemoryRegionInfoListImpl(const MemoryRegionInfoListImpl
&rhs
) = default;
26 MemoryRegionInfoListImpl
&operator=(const MemoryRegionInfoListImpl
&rhs
) {
29 m_regions
= rhs
.m_regions
;
33 size_t GetSize() const { return m_regions
.size(); }
35 void Reserve(size_t capacity
) { return m_regions
.reserve(capacity
); }
37 void Append(const MemoryRegionInfo
&sb_region
) {
38 m_regions
.push_back(sb_region
);
41 void Append(const MemoryRegionInfoListImpl
&list
) {
42 Reserve(GetSize() + list
.GetSize());
44 for (const auto &val
: list
.m_regions
)
48 void Clear() { m_regions
.clear(); }
50 bool GetMemoryRegionContainingAddress(lldb::addr_t addr
,
51 MemoryRegionInfo
®ion_info
) {
52 for (auto ®ion
: m_regions
) {
53 if (region
.GetRange().Contains(addr
)) {
61 bool GetMemoryRegionInfoAtIndex(size_t index
,
62 MemoryRegionInfo
®ion_info
) {
63 if (index
>= GetSize())
65 region_info
= m_regions
[index
];
69 MemoryRegionInfos
&Ref() { return m_regions
; }
71 const MemoryRegionInfos
&Ref() const { return m_regions
; }
74 MemoryRegionInfos m_regions
;
77 MemoryRegionInfos
&SBMemoryRegionInfoList::ref() { return m_opaque_up
->Ref(); }
79 const MemoryRegionInfos
&SBMemoryRegionInfoList::ref() const {
80 return m_opaque_up
->Ref();
83 SBMemoryRegionInfoList::SBMemoryRegionInfoList()
84 : m_opaque_up(new MemoryRegionInfoListImpl()) {
85 LLDB_INSTRUMENT_VA(this);
88 SBMemoryRegionInfoList::SBMemoryRegionInfoList(
89 const SBMemoryRegionInfoList
&rhs
)
90 : m_opaque_up(new MemoryRegionInfoListImpl(*rhs
.m_opaque_up
)) {
91 LLDB_INSTRUMENT_VA(this, rhs
);
94 SBMemoryRegionInfoList::~SBMemoryRegionInfoList() = default;
96 const SBMemoryRegionInfoList
&SBMemoryRegionInfoList::
97 operator=(const SBMemoryRegionInfoList
&rhs
) {
98 LLDB_INSTRUMENT_VA(this, rhs
);
101 *m_opaque_up
= *rhs
.m_opaque_up
;
106 uint32_t SBMemoryRegionInfoList::GetSize() const {
107 LLDB_INSTRUMENT_VA(this);
109 return m_opaque_up
->GetSize();
112 bool SBMemoryRegionInfoList::GetMemoryRegionContainingAddress(
113 lldb::addr_t addr
, SBMemoryRegionInfo
®ion_info
) {
114 LLDB_INSTRUMENT_VA(this, addr
, region_info
);
116 return m_opaque_up
->GetMemoryRegionContainingAddress(addr
, region_info
.ref());
119 bool SBMemoryRegionInfoList::GetMemoryRegionAtIndex(
120 uint32_t idx
, SBMemoryRegionInfo
®ion_info
) {
121 LLDB_INSTRUMENT_VA(this, idx
, region_info
);
123 return m_opaque_up
->GetMemoryRegionInfoAtIndex(idx
, region_info
.ref());
126 void SBMemoryRegionInfoList::Clear() {
127 LLDB_INSTRUMENT_VA(this);
129 m_opaque_up
->Clear();
132 void SBMemoryRegionInfoList::Append(SBMemoryRegionInfo
&sb_region
) {
133 LLDB_INSTRUMENT_VA(this, sb_region
);
135 m_opaque_up
->Append(sb_region
.ref());
138 void SBMemoryRegionInfoList::Append(SBMemoryRegionInfoList
&sb_region_list
) {
139 LLDB_INSTRUMENT_VA(this, sb_region_list
);
141 m_opaque_up
->Append(*sb_region_list
);
144 const MemoryRegionInfoListImpl
*SBMemoryRegionInfoList::operator->() const {
145 return m_opaque_up
.get();
148 const MemoryRegionInfoListImpl
&SBMemoryRegionInfoList::operator*() const {
149 assert(m_opaque_up
.get());