]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/API/SBMemoryRegionInfoList.cpp
Merge OpenSSL 1.0.2n.
[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   uint32_t GetSize() { return m_regions.size(); }
36
37   void Append(const lldb::SBMemoryRegionInfo &sb_region) {
38     m_regions.push_back(sb_region);
39   }
40
41   void Append(const MemoryRegionInfoListImpl &list) {
42     for (auto val : list.m_regions)
43       Append(val);
44   }
45
46   void Clear() { m_regions.clear(); }
47
48   bool GetMemoryRegionInfoAtIndex(uint32_t index,
49                                   SBMemoryRegionInfo &region_info) {
50     if (index >= GetSize())
51       return false;
52     region_info = m_regions[index];
53     return true;
54   }
55
56 private:
57   std::vector<lldb::SBMemoryRegionInfo> m_regions;
58 };
59
60 SBMemoryRegionInfoList::SBMemoryRegionInfoList()
61     : m_opaque_ap(new MemoryRegionInfoListImpl()) {}
62
63 SBMemoryRegionInfoList::SBMemoryRegionInfoList(
64     const SBMemoryRegionInfoList &rhs)
65     : m_opaque_ap(new MemoryRegionInfoListImpl(*rhs.m_opaque_ap)) {}
66
67 SBMemoryRegionInfoList::~SBMemoryRegionInfoList() {}
68
69 const SBMemoryRegionInfoList &SBMemoryRegionInfoList::
70 operator=(const SBMemoryRegionInfoList &rhs) {
71   if (this != &rhs) {
72     *m_opaque_ap = *rhs.m_opaque_ap;
73   }
74   return *this;
75 }
76
77 uint32_t SBMemoryRegionInfoList::GetSize() const {
78   return m_opaque_ap->GetSize();
79 }
80
81 bool SBMemoryRegionInfoList::GetMemoryRegionAtIndex(
82     uint32_t idx, SBMemoryRegionInfo &region_info) {
83   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
84
85   bool result = m_opaque_ap->GetMemoryRegionInfoAtIndex(idx, region_info);
86
87   if (log) {
88     SBStream sstr;
89     region_info.GetDescription(sstr);
90     log->Printf("SBMemoryRegionInfoList::GetMemoryRegionAtIndex (this.ap=%p, "
91                 "idx=%d) => SBMemoryRegionInfo (this.ap=%p, '%s')",
92                 static_cast<void *>(m_opaque_ap.get()), idx,
93                 static_cast<void *>(region_info.m_opaque_ap.get()),
94                 sstr.GetData());
95   }
96
97   return result;
98 }
99
100 void SBMemoryRegionInfoList::Clear() { m_opaque_ap->Clear(); }
101
102 void SBMemoryRegionInfoList::Append(SBMemoryRegionInfo &sb_region) {
103   m_opaque_ap->Append(sb_region);
104 }
105
106 void SBMemoryRegionInfoList::Append(SBMemoryRegionInfoList &sb_region_list) {
107   m_opaque_ap->Append(*sb_region_list);
108 }
109
110 const MemoryRegionInfoListImpl *SBMemoryRegionInfoList::operator->() const {
111   return m_opaque_ap.get();
112 }
113
114 const MemoryRegionInfoListImpl &SBMemoryRegionInfoList::operator*() const {
115   assert(m_opaque_ap.get());
116   return *m_opaque_ap.get();
117 }