SBMemoryRegionInfoList.cpp revision 314564
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/SBMemoryRegionInfo.h"
11#include "lldb/API/SBMemoryRegionInfoList.h"
12#include "lldb/API/SBStream.h"
13#include "lldb/Core/Log.h"
14#include "lldb/Target/MemoryRegionInfo.h"
15
16#include <vector>
17
18using namespace lldb;
19using namespace lldb_private;
20
21class MemoryRegionInfoListImpl {
22public:
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
56private:
57  std::vector<lldb::SBMemoryRegionInfo> m_regions;
58};
59
60SBMemoryRegionInfoList::SBMemoryRegionInfoList()
61    : m_opaque_ap(new MemoryRegionInfoListImpl()) {}
62
63SBMemoryRegionInfoList::SBMemoryRegionInfoList(
64    const SBMemoryRegionInfoList &rhs)
65    : m_opaque_ap(new MemoryRegionInfoListImpl(*rhs.m_opaque_ap)) {}
66
67SBMemoryRegionInfoList::~SBMemoryRegionInfoList() {}
68
69const SBMemoryRegionInfoList &SBMemoryRegionInfoList::
70operator=(const SBMemoryRegionInfoList &rhs) {
71  if (this != &rhs) {
72    *m_opaque_ap = *rhs.m_opaque_ap;
73  }
74  return *this;
75}
76
77uint32_t SBMemoryRegionInfoList::GetSize() const {
78  return m_opaque_ap->GetSize();
79}
80
81bool 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
100void SBMemoryRegionInfoList::Clear() { m_opaque_ap->Clear(); }
101
102void SBMemoryRegionInfoList::Append(SBMemoryRegionInfo &sb_region) {
103  m_opaque_ap->Append(sb_region);
104}
105
106void SBMemoryRegionInfoList::Append(SBMemoryRegionInfoList &sb_region_list) {
107  m_opaque_ap->Append(*sb_region_list);
108}
109
110const MemoryRegionInfoListImpl *SBMemoryRegionInfoList::operator->() const {
111  return m_opaque_ap.get();
112}
113
114const MemoryRegionInfoListImpl &SBMemoryRegionInfoList::operator*() const {
115  assert(m_opaque_ap.get());
116  return *m_opaque_ap.get();
117}
118