2016-06-23 16:35:37 +08:00
|
|
|
//===-- SBMemoryRegionInfoList.cpp ------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-06-23 16:35:37 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBMemoryRegionInfoList.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/API/SBMemoryRegionInfo.h"
|
2016-06-23 16:35:37 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
|
|
|
#include "lldb/Target/MemoryRegionInfo.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2016-06-23 16:35:37 +08:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
class MemoryRegionInfoListImpl {
|
2016-06-23 16:35:37 +08:00
|
|
|
public:
|
2016-09-07 04:57:50 +08:00
|
|
|
MemoryRegionInfoListImpl() : m_regions() {}
|
|
|
|
|
|
|
|
MemoryRegionInfoListImpl(const MemoryRegionInfoListImpl &rhs)
|
|
|
|
: m_regions(rhs.m_regions) {}
|
|
|
|
|
|
|
|
MemoryRegionInfoListImpl &operator=(const MemoryRegionInfoListImpl &rhs) {
|
|
|
|
if (this == &rhs)
|
|
|
|
return *this;
|
|
|
|
m_regions = rhs.m_regions;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-12-20 23:02:58 +08:00
|
|
|
size_t GetSize() const { return m_regions.size(); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-12-20 23:02:58 +08:00
|
|
|
void Reserve(size_t capacity) { return m_regions.reserve(capacity); }
|
|
|
|
|
|
|
|
void Append(const MemoryRegionInfo &sb_region) {
|
2016-09-07 04:57:50 +08:00
|
|
|
m_regions.push_back(sb_region);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Append(const MemoryRegionInfoListImpl &list) {
|
2018-12-20 23:02:58 +08:00
|
|
|
Reserve(GetSize() + list.GetSize());
|
|
|
|
|
|
|
|
for (const auto &val : list.m_regions)
|
2016-09-07 04:57:50 +08:00
|
|
|
Append(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear() { m_regions.clear(); }
|
|
|
|
|
2018-12-20 23:02:58 +08:00
|
|
|
bool GetMemoryRegionInfoAtIndex(size_t index,
|
|
|
|
MemoryRegionInfo ®ion_info) {
|
2016-09-07 04:57:50 +08:00
|
|
|
if (index >= GetSize())
|
|
|
|
return false;
|
|
|
|
region_info = m_regions[index];
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-23 16:35:37 +08:00
|
|
|
|
2018-12-20 23:02:58 +08:00
|
|
|
MemoryRegionInfos &Ref() { return m_regions; }
|
|
|
|
|
|
|
|
const MemoryRegionInfos &Ref() const { return m_regions; }
|
|
|
|
|
2016-06-23 16:35:37 +08:00
|
|
|
private:
|
2018-12-20 23:02:58 +08:00
|
|
|
MemoryRegionInfos m_regions;
|
2016-06-23 16:35:37 +08:00
|
|
|
};
|
|
|
|
|
2018-12-20 23:02:58 +08:00
|
|
|
MemoryRegionInfos &SBMemoryRegionInfoList::ref() {
|
|
|
|
return m_opaque_ap->Ref();
|
|
|
|
}
|
|
|
|
|
|
|
|
const MemoryRegionInfos &SBMemoryRegionInfoList::ref() const {
|
|
|
|
return m_opaque_ap->Ref();
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBMemoryRegionInfoList::SBMemoryRegionInfoList()
|
|
|
|
: m_opaque_ap(new MemoryRegionInfoListImpl()) {}
|
2016-06-23 16:35:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBMemoryRegionInfoList::SBMemoryRegionInfoList(
|
|
|
|
const SBMemoryRegionInfoList &rhs)
|
|
|
|
: m_opaque_ap(new MemoryRegionInfoListImpl(*rhs.m_opaque_ap)) {}
|
2016-06-23 16:35:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBMemoryRegionInfoList::~SBMemoryRegionInfoList() {}
|
2016-06-23 16:35:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const SBMemoryRegionInfoList &SBMemoryRegionInfoList::
|
|
|
|
operator=(const SBMemoryRegionInfoList &rhs) {
|
|
|
|
if (this != &rhs) {
|
|
|
|
*m_opaque_ap = *rhs.m_opaque_ap;
|
|
|
|
}
|
|
|
|
return *this;
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t SBMemoryRegionInfoList::GetSize() const {
|
|
|
|
return m_opaque_ap->GetSize();
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBMemoryRegionInfoList::GetMemoryRegionAtIndex(
|
|
|
|
uint32_t idx, SBMemoryRegionInfo ®ion_info) {
|
|
|
|
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2016-06-23 16:35:37 +08:00
|
|
|
|
2018-12-20 23:02:58 +08:00
|
|
|
bool result = m_opaque_ap->GetMemoryRegionInfoAtIndex(idx, region_info.ref());
|
2016-06-23 16:35:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log) {
|
|
|
|
SBStream sstr;
|
|
|
|
region_info.GetDescription(sstr);
|
|
|
|
log->Printf("SBMemoryRegionInfoList::GetMemoryRegionAtIndex (this.ap=%p, "
|
|
|
|
"idx=%d) => SBMemoryRegionInfo (this.ap=%p, '%s')",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()), idx,
|
|
|
|
static_cast<void *>(region_info.m_opaque_ap.get()),
|
|
|
|
sstr.GetData());
|
|
|
|
}
|
2016-06-23 16:35:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return result;
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBMemoryRegionInfoList::Clear() { m_opaque_ap->Clear(); }
|
2016-06-23 16:35:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBMemoryRegionInfoList::Append(SBMemoryRegionInfo &sb_region) {
|
2018-12-20 23:02:58 +08:00
|
|
|
m_opaque_ap->Append(sb_region.ref());
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBMemoryRegionInfoList::Append(SBMemoryRegionInfoList &sb_region_list) {
|
|
|
|
m_opaque_ap->Append(*sb_region_list);
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const MemoryRegionInfoListImpl *SBMemoryRegionInfoList::operator->() const {
|
|
|
|
return m_opaque_ap.get();
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const MemoryRegionInfoListImpl &SBMemoryRegionInfoList::operator*() const {
|
|
|
|
assert(m_opaque_ap.get());
|
2018-12-21 05:02:55 +08:00
|
|
|
return *m_opaque_ap;
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|