[DAG] Fix typo in VSELECT SimplifyDemandedVectorElts handling. NFC.
[llvm-project.git] / lldb / source / API / SBMemoryRegionInfoList.cpp
blobf8381d1098a0ff7a13527d3e11025ca1ce2e6b1b
1 //===-- SBMemoryRegionInfoList.cpp ----------------------------------------===//
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 //===----------------------------------------------------------------------===//
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"
15 #include <vector>
17 using namespace lldb;
18 using namespace lldb_private;
20 class MemoryRegionInfoListImpl {
21 public:
22 MemoryRegionInfoListImpl() : m_regions() {}
24 MemoryRegionInfoListImpl(const MemoryRegionInfoListImpl &rhs) = default;
26 MemoryRegionInfoListImpl &operator=(const MemoryRegionInfoListImpl &rhs) {
27 if (this == &rhs)
28 return *this;
29 m_regions = rhs.m_regions;
30 return *this;
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)
45 Append(val);
48 void Clear() { m_regions.clear(); }
50 bool GetMemoryRegionContainingAddress(lldb::addr_t addr,
51 MemoryRegionInfo &region_info) {
52 for (auto &region : m_regions) {
53 if (region.GetRange().Contains(addr)) {
54 region_info = region;
55 return true;
58 return false;
61 bool GetMemoryRegionInfoAtIndex(size_t index,
62 MemoryRegionInfo &region_info) {
63 if (index >= GetSize())
64 return false;
65 region_info = m_regions[index];
66 return true;
69 MemoryRegionInfos &Ref() { return m_regions; }
71 const MemoryRegionInfos &Ref() const { return m_regions; }
73 private:
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);
100 if (this != &rhs) {
101 *m_opaque_up = *rhs.m_opaque_up;
103 return *this;
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 &region_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 &region_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());
150 return *m_opaque_up;