]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/API/SBMemoryRegionInfoList.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / API / SBMemoryRegionInfoList.cpp
1 //===-- SBMemoryRegionInfoList.cpp ------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
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"
15
16 #include <vector>
17
18 using namespace lldb;
19 using namespace lldb_private;
20
21 class MemoryRegionInfoListImpl {
22 public:
23   MemoryRegionInfoListImpl() : m_regions() {}
24
25   MemoryRegionInfoListImpl(const MemoryRegionInfoListImpl &rhs)
26       : m_regions(rhs.m_regions) {}
27
28   MemoryRegionInfoListImpl &operator=(const MemoryRegionInfoListImpl &rhs) {
29     if (this == &rhs)
30       return *this;
31     m_regions = rhs.m_regions;
32     return *this;
33   }
34
35   size_t GetSize() const { return m_regions.size(); }
36
37   void Reserve(size_t capacity) { return m_regions.reserve(capacity); }
38
39   void Append(const MemoryRegionInfo &sb_region) {
40     m_regions.push_back(sb_region);
41   }
42
43   void Append(const MemoryRegionInfoListImpl &list) {
44     Reserve(GetSize() + list.GetSize());
45
46     for (const auto &val : list.m_regions)
47       Append(val);
48   }
49
50   void Clear() { m_regions.clear(); }
51
52   bool GetMemoryRegionInfoAtIndex(size_t index,
53                                   MemoryRegionInfo &region_info) {
54     if (index >= GetSize())
55       return false;
56     region_info = m_regions[index];
57     return true;
58   }
59
60   MemoryRegionInfos &Ref() { return m_regions; }
61
62   const MemoryRegionInfos &Ref() const { return m_regions; }
63
64 private:
65   MemoryRegionInfos m_regions;
66 };
67
68 MemoryRegionInfos &SBMemoryRegionInfoList::ref() {
69   return m_opaque_ap->Ref();
70 }
71
72 const MemoryRegionInfos &SBMemoryRegionInfoList::ref() const {
73   return m_opaque_ap->Ref();
74 }
75
76 SBMemoryRegionInfoList::SBMemoryRegionInfoList()
77     : m_opaque_ap(new MemoryRegionInfoListImpl()) {}
78
79 SBMemoryRegionInfoList::SBMemoryRegionInfoList(
80     const SBMemoryRegionInfoList &rhs)
81     : m_opaque_ap(new MemoryRegionInfoListImpl(*rhs.m_opaque_ap)) {}
82
83 SBMemoryRegionInfoList::~SBMemoryRegionInfoList() {}
84
85 const SBMemoryRegionInfoList &SBMemoryRegionInfoList::
86 operator=(const SBMemoryRegionInfoList &rhs) {
87   if (this != &rhs) {
88     *m_opaque_ap = *rhs.m_opaque_ap;
89   }
90   return *this;
91 }
92
93 uint32_t SBMemoryRegionInfoList::GetSize() const {
94   return m_opaque_ap->GetSize();
95 }
96
97 bool SBMemoryRegionInfoList::GetMemoryRegionAtIndex(
98     uint32_t idx, SBMemoryRegionInfo &region_info) {
99   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
100
101   bool result = m_opaque_ap->GetMemoryRegionInfoAtIndex(idx, region_info.ref());
102
103   if (log) {
104     SBStream sstr;
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()),
110                 sstr.GetData());
111   }
112
113   return result;
114 }
115
116 void SBMemoryRegionInfoList::Clear() { m_opaque_ap->Clear(); }
117
118 void SBMemoryRegionInfoList::Append(SBMemoryRegionInfo &sb_region) {
119   m_opaque_ap->Append(sb_region.ref());
120 }
121
122 void SBMemoryRegionInfoList::Append(SBMemoryRegionInfoList &sb_region_list) {
123   m_opaque_ap->Append(*sb_region_list);
124 }
125
126 const MemoryRegionInfoListImpl *SBMemoryRegionInfoList::operator->() const {
127   return m_opaque_ap.get();
128 }
129
130 const MemoryRegionInfoListImpl &SBMemoryRegionInfoList::operator*() const {
131   assert(m_opaque_ap.get());
132   return *m_opaque_ap;
133 }