[Lldb-commits] [lldb] r349766 - Replace MemoryRegionInfoSP with values and cleanup related code
Tatyana Krasnukha via lldb-commits
lldb-commits at lists.llvm.org
Thu Dec 20 07:02:59 PST 2018
Author: tkrasnukha
Date: Thu Dec 20 07:02:58 2018
New Revision: 349766
URL: http://llvm.org/viewvc/llvm-project?rev=349766&view=rev
Log:
Replace MemoryRegionInfoSP with values and cleanup related code
Differential Revision: https://reviews.llvm.org/D55472
Modified:
lldb/trunk/include/lldb/API/SBMemoryRegionInfo.h
lldb/trunk/include/lldb/API/SBMemoryRegionInfoList.h
lldb/trunk/include/lldb/Target/MemoryRegionInfo.h
lldb/trunk/include/lldb/Target/Process.h
lldb/trunk/include/lldb/lldb-forward.h
lldb/trunk/source/API/SBMemoryRegionInfoList.cpp
lldb/trunk/source/API/SBProcess.cpp
lldb/trunk/source/Target/Process.cpp
Modified: lldb/trunk/include/lldb/API/SBMemoryRegionInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBMemoryRegionInfo.h?rev=349766&r1=349765&r2=349766&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBMemoryRegionInfo.h (original)
+++ lldb/trunk/include/lldb/API/SBMemoryRegionInfo.h Thu Dec 20 07:02:58 2018
@@ -102,6 +102,7 @@ private:
const lldb_private::MemoryRegionInfo &ref() const;
+ // Unused.
SBMemoryRegionInfo(const lldb_private::MemoryRegionInfo *lldb_object_ptr);
lldb::MemoryRegionInfoUP m_opaque_ap;
Modified: lldb/trunk/include/lldb/API/SBMemoryRegionInfoList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBMemoryRegionInfoList.h?rev=349766&r1=349765&r2=349766&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBMemoryRegionInfoList.h (original)
+++ lldb/trunk/include/lldb/API/SBMemoryRegionInfoList.h Thu Dec 20 07:02:58 2018
@@ -42,6 +42,12 @@ protected:
const MemoryRegionInfoListImpl &operator*() const;
private:
+ friend class SBProcess;
+
+ lldb_private::MemoryRegionInfos &ref();
+
+ const lldb_private::MemoryRegionInfos &ref() const;
+
std::unique_ptr<MemoryRegionInfoListImpl> m_opaque_ap;
};
Modified: lldb/trunk/include/lldb/Target/MemoryRegionInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/MemoryRegionInfo.h?rev=349766&r1=349765&r2=349766&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/MemoryRegionInfo.h (original)
+++ lldb/trunk/include/lldb/Target/MemoryRegionInfo.h Thu Dec 20 07:02:58 2018
@@ -123,6 +123,12 @@ inline bool operator<(lldb::addr_t lhs,
return lhs < rhs.GetRange().GetRangeBase();
}
+// Forward-declarable wrapper.
+class MemoryRegionInfos : public std::vector<lldb_private::MemoryRegionInfo> {
+public:
+ using std::vector<lldb_private::MemoryRegionInfo>::vector;
+};
+
}
namespace llvm {
Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=349766&r1=349765&r2=349766&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Thu Dec 20 07:02:58 2018
@@ -2081,7 +2081,7 @@ public:
/// An error value.
//------------------------------------------------------------------
virtual Status
- GetMemoryRegions(std::vector<lldb::MemoryRegionInfoSP> ®ion_list);
+ GetMemoryRegions(lldb_private::MemoryRegionInfos ®ion_list);
virtual Status GetWatchpointSupportInfo(uint32_t &num) {
Status error;
Modified: lldb/trunk/include/lldb/lldb-forward.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=349766&r1=349765&r2=349766&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward.h (original)
+++ lldb/trunk/include/lldb/lldb-forward.h Thu Dec 20 07:02:58 2018
@@ -125,13 +125,14 @@ class JITLoaderList;
class Language;
class LanguageCategory;
class LanguageRuntime;
-class MemoryRegionInfo;
class LineTable;
class Listener;
class Log;
class Mangled;
class Materializer;
class MemoryHistory;
+class MemoryRegionInfo;
+class MemoryRegionInfos;
class Module;
class ModuleList;
class ModuleSpec;
@@ -369,7 +370,6 @@ typedef std::shared_ptr<lldb_private::Li
typedef std::shared_ptr<lldb_private::Listener> ListenerSP;
typedef std::weak_ptr<lldb_private::Listener> ListenerWP;
typedef std::shared_ptr<lldb_private::MemoryHistory> MemoryHistorySP;
-typedef std::shared_ptr<lldb_private::MemoryRegionInfo> MemoryRegionInfoSP;
typedef std::unique_ptr<lldb_private::MemoryRegionInfo> MemoryRegionInfoUP;
typedef std::shared_ptr<lldb_private::Module> ModuleSP;
typedef std::weak_ptr<lldb_private::Module> ModuleWP;
Modified: lldb/trunk/source/API/SBMemoryRegionInfoList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBMemoryRegionInfoList.cpp?rev=349766&r1=349765&r2=349766&view=diff
==============================================================================
--- lldb/trunk/source/API/SBMemoryRegionInfoList.cpp (original)
+++ lldb/trunk/source/API/SBMemoryRegionInfoList.cpp Thu Dec 20 07:02:58 2018
@@ -32,31 +32,47 @@ public:
return *this;
}
- uint32_t GetSize() { return m_regions.size(); }
+ size_t GetSize() const { return m_regions.size(); }
- void Append(const lldb::SBMemoryRegionInfo &sb_region) {
+ void Reserve(size_t capacity) { return m_regions.reserve(capacity); }
+
+ void Append(const MemoryRegionInfo &sb_region) {
m_regions.push_back(sb_region);
}
void Append(const MemoryRegionInfoListImpl &list) {
- for (auto val : list.m_regions)
+ Reserve(GetSize() + list.GetSize());
+
+ for (const auto &val : list.m_regions)
Append(val);
}
void Clear() { m_regions.clear(); }
- bool GetMemoryRegionInfoAtIndex(uint32_t index,
- SBMemoryRegionInfo ®ion_info) {
+ bool GetMemoryRegionInfoAtIndex(size_t index,
+ MemoryRegionInfo ®ion_info) {
if (index >= GetSize())
return false;
region_info = m_regions[index];
return true;
}
+ MemoryRegionInfos &Ref() { return m_regions; }
+
+ const MemoryRegionInfos &Ref() const { return m_regions; }
+
private:
- std::vector<lldb::SBMemoryRegionInfo> m_regions;
+ MemoryRegionInfos m_regions;
};
+MemoryRegionInfos &SBMemoryRegionInfoList::ref() {
+ return m_opaque_ap->Ref();
+}
+
+const MemoryRegionInfos &SBMemoryRegionInfoList::ref() const {
+ return m_opaque_ap->Ref();
+}
+
SBMemoryRegionInfoList::SBMemoryRegionInfoList()
: m_opaque_ap(new MemoryRegionInfoListImpl()) {}
@@ -82,7 +98,7 @@ bool SBMemoryRegionInfoList::GetMemoryRe
uint32_t idx, SBMemoryRegionInfo ®ion_info) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
- bool result = m_opaque_ap->GetMemoryRegionInfoAtIndex(idx, region_info);
+ bool result = m_opaque_ap->GetMemoryRegionInfoAtIndex(idx, region_info.ref());
if (log) {
SBStream sstr;
@@ -100,7 +116,7 @@ bool SBMemoryRegionInfoList::GetMemoryRe
void SBMemoryRegionInfoList::Clear() { m_opaque_ap->Clear(); }
void SBMemoryRegionInfoList::Append(SBMemoryRegionInfo &sb_region) {
- m_opaque_ap->Append(sb_region);
+ m_opaque_ap->Append(sb_region.ref());
}
void SBMemoryRegionInfoList::Append(SBMemoryRegionInfoList &sb_region_list) {
Modified: lldb/trunk/source/API/SBProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=349766&r1=349765&r2=349766&view=diff
==============================================================================
--- lldb/trunk/source/API/SBProcess.cpp (original)
+++ lldb/trunk/source/API/SBProcess.cpp Thu Dec 20 07:02:58 2018
@@ -1358,18 +1358,14 @@ SBProcess::GetMemoryRegionInfo(lldb::add
SBMemoryRegionInfo &sb_region_info) {
lldb::SBError sb_error;
ProcessSP process_sp(GetSP());
- MemoryRegionInfoSP region_info_sp =
- std::make_shared<lldb_private::MemoryRegionInfo>();
if (process_sp) {
Process::StopLocker stop_locker;
if (stop_locker.TryLock(&process_sp->GetRunLock())) {
std::lock_guard<std::recursive_mutex> guard(
process_sp->GetTarget().GetAPIMutex());
+
sb_error.ref() =
- process_sp->GetMemoryRegionInfo(load_addr, *region_info_sp);
- if (sb_error.Success()) {
- sb_region_info.ref() = *region_info_sp;
- }
+ process_sp->GetMemoryRegionInfo(load_addr, sb_region_info.ref());
} else {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
if (log)
@@ -1385,35 +1381,23 @@ SBProcess::GetMemoryRegionInfo(lldb::add
}
lldb::SBMemoryRegionInfoList SBProcess::GetMemoryRegions() {
- lldb::SBError sb_error;
lldb::SBMemoryRegionInfoList sb_region_list;
+
ProcessSP process_sp(GetSP());
- if (process_sp) {
- Process::StopLocker stop_locker;
- if (stop_locker.TryLock(&process_sp->GetRunLock())) {
- std::lock_guard<std::recursive_mutex> guard(
- process_sp->GetTarget().GetAPIMutex());
- std::vector<MemoryRegionInfoSP> region_list;
- sb_error.ref() = process_sp->GetMemoryRegions(region_list);
- if (sb_error.Success()) {
- std::vector<MemoryRegionInfoSP>::iterator end = region_list.end();
- for (std::vector<MemoryRegionInfoSP>::iterator it = region_list.begin();
- it != end; it++) {
- SBMemoryRegionInfo sb_region_info(it->get());
- sb_region_list.Append(sb_region_info);
- }
- }
- } else {
- Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
- if (log)
- log->Printf(
- "SBProcess(%p)::GetMemoryRegionInfo() => error: process is running",
- static_cast<void *>(process_sp.get()));
- sb_error.SetErrorString("process is running");
- }
+ Process::StopLocker stop_locker;
+ if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
+ std::lock_guard<std::recursive_mutex> guard(
+ process_sp->GetTarget().GetAPIMutex());
+
+ process_sp->GetMemoryRegions(sb_region_list.ref());
} else {
- sb_error.SetErrorString("SBProcess is invalid");
+ Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
+ if (log)
+ log->Printf(
+ "SBProcess(%p)::GetMemoryRegionInfo() => error: process is running",
+ static_cast<void *>(process_sp.get()));
}
+
return sb_region_list;
}
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=349766&r1=349765&r2=349766&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Thu Dec 20 07:02:58 2018
@@ -6035,7 +6035,7 @@ Process::AdvanceAddressToNextBranchInstr
}
Status
-Process::GetMemoryRegions(std::vector<lldb::MemoryRegionInfoSP> ®ion_list) {
+Process::GetMemoryRegions(lldb_private::MemoryRegionInfos ®ion_list) {
Status error;
@@ -6043,17 +6043,17 @@ Process::GetMemoryRegions(std::vector<ll
region_list.clear();
do {
- lldb::MemoryRegionInfoSP region_info(new lldb_private::MemoryRegionInfo());
- error = GetMemoryRegionInfo(range_end, *region_info);
+ lldb_private::MemoryRegionInfo region_info;
+ error = GetMemoryRegionInfo(range_end, region_info);
// GetMemoryRegionInfo should only return an error if it is unimplemented.
if (error.Fail()) {
region_list.clear();
break;
}
- range_end = region_info->GetRange().GetRangeEnd();
- if (region_info->GetMapped() == MemoryRegionInfo::eYes) {
- region_list.push_back(region_info);
+ range_end = region_info.GetRange().GetRangeEnd();
+ if (region_info.GetMapped() == MemoryRegionInfo::eYes) {
+ region_list.push_back(std::move(region_info));
}
} while (range_end != LLDB_INVALID_ADDRESS);
More information about the lldb-commits
mailing list