blob: fff4044f73e0f7438efe4a4f5ba2a7e563794587 [file] [log] [blame]
Howard Hellyer260368432016-06-23 08:35:37 +00001//===-- 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
Howard Hellyer260368432016-06-23 08:35:37 +000010#include "lldb/API/SBMemoryRegionInfoList.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000011#include "lldb/API/SBMemoryRegionInfo.h"
Howard Hellyer260368432016-06-23 08:35:37 +000012#include "lldb/API/SBStream.h"
Howard Hellyer260368432016-06-23 08:35:37 +000013#include "lldb/Target/MemoryRegionInfo.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000014#include "lldb/Utility/Log.h"
Howard Hellyer260368432016-06-23 08:35:37 +000015
16#include <vector>
17
18using namespace lldb;
19using namespace lldb_private;
20
Kate Stoneb9c1b512016-09-06 20:57:50 +000021class MemoryRegionInfoListImpl {
Howard Hellyer260368432016-06-23 08:35:37 +000022public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000023 MemoryRegionInfoListImpl() : m_regions() {}
Howard Hellyer260368432016-06-23 08:35:37 +000024
Kate Stoneb9c1b512016-09-06 20:57:50 +000025 MemoryRegionInfoListImpl(const MemoryRegionInfoListImpl &rhs)
26 : m_regions(rhs.m_regions) {}
Howard Hellyer260368432016-06-23 08:35:37 +000027
Kate Stoneb9c1b512016-09-06 20:57:50 +000028 MemoryRegionInfoListImpl &operator=(const MemoryRegionInfoListImpl &rhs) {
29 if (this == &rhs)
30 return *this;
31 m_regions = rhs.m_regions;
32 return *this;
33 }
Howard Hellyer260368432016-06-23 08:35:37 +000034
Kate Stoneb9c1b512016-09-06 20:57:50 +000035 uint32_t GetSize() { return m_regions.size(); }
Howard Hellyer260368432016-06-23 08:35:37 +000036
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 void Append(const lldb::SBMemoryRegionInfo &sb_region) {
38 m_regions.push_back(sb_region);
39 }
Howard Hellyer260368432016-06-23 08:35:37 +000040
Kate Stoneb9c1b512016-09-06 20:57:50 +000041 void Append(const MemoryRegionInfoListImpl &list) {
42 for (auto val : list.m_regions)
43 Append(val);
44 }
Howard Hellyer260368432016-06-23 08:35:37 +000045
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 void Clear() { m_regions.clear(); }
Howard Hellyer260368432016-06-23 08:35:37 +000047
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 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 }
Howard Hellyer260368432016-06-23 08:35:37 +000055
56private:
Kate Stoneb9c1b512016-09-06 20:57:50 +000057 std::vector<lldb::SBMemoryRegionInfo> m_regions;
Howard Hellyer260368432016-06-23 08:35:37 +000058};
59
Kate Stoneb9c1b512016-09-06 20:57:50 +000060SBMemoryRegionInfoList::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;
Howard Hellyer260368432016-06-23 08:35:37 +000075}
76
Kate Stoneb9c1b512016-09-06 20:57:50 +000077uint32_t SBMemoryRegionInfoList::GetSize() const {
78 return m_opaque_ap->GetSize();
Howard Hellyer260368432016-06-23 08:35:37 +000079}
80
Kate Stoneb9c1b512016-09-06 20:57:50 +000081bool 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;
Howard Hellyer260368432016-06-23 08:35:37 +000098}
99
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100void SBMemoryRegionInfoList::Clear() { m_opaque_ap->Clear(); }
101
102void SBMemoryRegionInfoList::Append(SBMemoryRegionInfo &sb_region) {
103 m_opaque_ap->Append(sb_region);
Howard Hellyer260368432016-06-23 08:35:37 +0000104}
105
Kate Stoneb9c1b512016-09-06 20:57:50 +0000106void SBMemoryRegionInfoList::Append(SBMemoryRegionInfoList &sb_region_list) {
107 m_opaque_ap->Append(*sb_region_list);
Howard Hellyer260368432016-06-23 08:35:37 +0000108}
109
Kate Stoneb9c1b512016-09-06 20:57:50 +0000110const MemoryRegionInfoListImpl *SBMemoryRegionInfoList::operator->() const {
111 return m_opaque_ap.get();
Howard Hellyer260368432016-06-23 08:35:37 +0000112}
113
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114const MemoryRegionInfoListImpl &SBMemoryRegionInfoList::operator*() const {
115 assert(m_opaque_ap.get());
116 return *m_opaque_ap.get();
Howard Hellyer260368432016-06-23 08:35:37 +0000117}