hhellyer updated this revision to Diff 58771.
hhellyer added a comment.
Removed std::enable_shared_from_this from MemoryRegionInfo.h (which removes the
only change from that file)
Renamed region_info to region_info_sp in SBProcess::GetMemoryRegionInfo in
SBProcess.cpp
I also corrected the position of the opening { on the functions in that file to
match the standard.
http://reviews.llvm.org/D20565
Files:
include/lldb/API/LLDB.h
include/lldb/API/SBDefines.h
include/lldb/API/SBMemoryRegionInfo.h
include/lldb/API/SBMemoryRegionInfoList.h
include/lldb/API/SBProcess.h
include/lldb/API/SBStream.h
include/lldb/Target/Process.h
include/lldb/lldb-forward.h
source/API/CMakeLists.txt
source/API/SBMemoryRegionInfo.cpp
source/API/SBMemoryRegionInfoList.cpp
source/API/SBProcess.cpp
Index: source/API/SBProcess.cpp
===================================================================
--- source/API/SBProcess.cpp
+++ source/API/SBProcess.cpp
@@ -23,6 +23,7 @@
#include "lldb/Core/State.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/StreamFile.h"
+#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/SystemRuntime.h"
@@ -36,6 +37,8 @@
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBFileSpec.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "lldb/API/SBMemoryRegionInfoList.h"
#include "lldb/API/SBThread.h"
#include "lldb/API/SBThreadCollection.h"
#include "lldb/API/SBStream.h"
@@ -1476,3 +1479,74 @@
error.ref() = PluginManager::SaveCore(process_sp, core_file);
return error;
}
+
+lldb::SBError
+SBProcess::GetMemoryRegionInfo (lldb::addr_t load_addr, 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.SetSP(region_info_sp);
+ }
+ }
+ 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");
+ }
+ }
+ else
+ {
+ sb_error.SetErrorString ("SBProcess is invalid");
+ }
+ return sb_error;
+}
+
+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);
+ 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");
+ }
+ }
+ else
+ {
+ sb_error.SetErrorString ("SBProcess is invalid");
+ }
+ return sb_region_list;
+}
Index: source/API/SBMemoryRegionInfoList.cpp
===================================================================
--- /dev/null
+++ source/API/SBMemoryRegionInfoList.cpp
@@ -0,0 +1,172 @@
+//===-- SBMemoryRegionInfoList.cpp ------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "lldb/API/SBMemoryRegionInfoList.h"
+#include "lldb/API/SBStream.h"
+#include "lldb/Core/Log.h"
+#include "lldb/Target/MemoryRegionInfo.h"
+
+#include <vector>
+
+using namespace lldb;
+using namespace lldb_private;
+
+class MemoryRegionInfoListImpl
+{
+public:
+ 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;
+ }
+
+ uint32_t
+ GetSize ()
+ {
+ return m_regions.size();
+ }
+
+ void
+ Append (const lldb::SBMemoryRegionInfo& sb_region)
+ {
+ m_regions.push_back(sb_region);
+ }
+
+ void
+ Append (const MemoryRegionInfoListImpl& list)
+ {
+ for (auto val : list.m_regions)
+ Append (val);
+ }
+
+ void
+ Clear ()
+ {
+ m_regions.clear();
+ }
+
+ bool
+ GetMemoryRegionInfoAtIndex (uint32_t index, SBMemoryRegionInfo ®ion_info)
+ {
+ if (index >= GetSize())
+ return false;
+ region_info = m_regions[index];
+ return true;
+ }
+
+private:
+ std::vector<lldb::SBMemoryRegionInfo> m_regions;
+};
+
+SBMemoryRegionInfoList::SBMemoryRegionInfoList () :
+ m_opaque_ap (new MemoryRegionInfoListImpl())
+{
+}
+
+SBMemoryRegionInfoList::SBMemoryRegionInfoList (const SBMemoryRegionInfoList& rhs) :
+ m_opaque_ap (new MemoryRegionInfoListImpl(*rhs.m_opaque_ap))
+{
+}
+
+SBMemoryRegionInfoList::~SBMemoryRegionInfoList ()
+{
+}
+
+const SBMemoryRegionInfoList &
+SBMemoryRegionInfoList::operator = (const SBMemoryRegionInfoList &rhs)
+{
+ if (this != &rhs)
+ {
+ *m_opaque_ap = *rhs.m_opaque_ap;
+ }
+ return *this;
+}
+
+uint32_t
+SBMemoryRegionInfoList::GetSize() const
+{
+ if (m_opaque_ap.get())
+ return m_opaque_ap->GetSize();
+ return 0;
+}
+
+
+bool
+SBMemoryRegionInfoList::GetMemoryRegionAtIndex (uint32_t idx, SBMemoryRegionInfo ®ion_info)
+{
+ Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+
+ bool result = m_opaque_ap->GetMemoryRegionInfoAtIndex(idx, region_info);
+
+ if (log)
+ {
+ SBStream sstr;
+ region_info.GetDescription (sstr);
+ log->Printf ("SBMemoryRegionInfoList::GetMemoryRegionAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')",
+ static_cast<void*>(m_opaque_ap.get()), idx,
+ static_cast<void*>(region_info.GetSP().get()), sstr.GetData());
+ }
+
+ return result;
+}
+
+void
+SBMemoryRegionInfoList::Clear()
+{
+ if (m_opaque_ap.get())
+ m_opaque_ap->Clear();
+}
+
+void
+SBMemoryRegionInfoList::Append(SBMemoryRegionInfo &sb_region)
+{
+ if (sb_region.IsValid() && m_opaque_ap.get())
+ m_opaque_ap->Append(sb_region);
+}
+
+void
+SBMemoryRegionInfoList::Append(SBMemoryRegionInfoList &sb_region_list)
+{
+ if (sb_region_list.IsValid() && m_opaque_ap.get())
+ m_opaque_ap->Append(*sb_region_list);
+}
+
+bool
+SBMemoryRegionInfoList::IsValid () const
+{
+ return m_opaque_ap.get() != NULL;
+}
+
+const MemoryRegionInfoListImpl *
+SBMemoryRegionInfoList::operator->() const
+{
+ return m_opaque_ap.get();
+}
+
+const MemoryRegionInfoListImpl&
+SBMemoryRegionInfoList::operator*() const
+{
+ assert (m_opaque_ap.get());
+ return *m_opaque_ap.get();
+}
+
Index: source/API/SBMemoryRegionInfo.cpp
===================================================================
--- /dev/null
+++ source/API/SBMemoryRegionInfo.cpp
@@ -0,0 +1,159 @@
+//===-- SBMemoryRegionInfo.cpp ----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/API/SBDefines.h"
+#include "lldb/API/SBError.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "lldb/API/SBStream.h"
+#include "lldb/Core/StreamString.h"
+#include "lldb/Target/MemoryRegionInfo.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+
+SBMemoryRegionInfo::SBMemoryRegionInfo () :
+ m_opaque_sp ()
+{
+}
+
+SBMemoryRegionInfo::SBMemoryRegionInfo (const lldb::MemoryRegionInfoSP& region_sp) :
+ m_opaque_sp (region_sp)
+{
+}
+
+SBMemoryRegionInfo::SBMemoryRegionInfo(const SBMemoryRegionInfo &rhs) :
+ m_opaque_sp (rhs.m_opaque_sp)
+{
+}
+
+const SBMemoryRegionInfo &
+SBMemoryRegionInfo::operator = (const SBMemoryRegionInfo &rhs)
+{
+ if (this != &rhs)
+ m_opaque_sp = rhs.m_opaque_sp;
+ return *this;
+}
+
+SBMemoryRegionInfo::~SBMemoryRegionInfo ()
+{
+}
+
+bool
+SBMemoryRegionInfo::IsValid () const
+{
+ return m_opaque_sp.get() != NULL;
+}
+
+void
+SBMemoryRegionInfo::Clear()
+{
+ m_opaque_sp.reset();
+}
+
+bool
+SBMemoryRegionInfo::operator == (const SBMemoryRegionInfo &rhs) const
+{
+ if (m_opaque_sp)
+ return m_opaque_sp.get() == rhs.m_opaque_sp.get();
+ return false;
+}
+
+bool
+SBMemoryRegionInfo::operator != (const SBMemoryRegionInfo &rhs) const
+{
+ if (m_opaque_sp)
+ return m_opaque_sp.get() != rhs.m_opaque_sp.get();
+ return false;
+}
+
+lldb::MemoryRegionInfoSP
+SBMemoryRegionInfo::GetSP () const
+{
+ return m_opaque_sp;
+}
+
+void
+SBMemoryRegionInfo::SetSP (const MemoryRegionInfoSP ®ion_sp)
+{
+ m_opaque_sp = region_sp;
+}
+
+lldb::addr_t
+SBMemoryRegionInfo::GetRegionBase () {
+ MemoryRegionInfoSP region_sp (GetSP ());
+ if (region_sp)
+ {
+ return region_sp->GetRange().GetRangeBase();
+ }
+ return 0;
+}
+
+lldb::addr_t
+SBMemoryRegionInfo::GetRegionEnd () {
+ MemoryRegionInfoSP region_sp (GetSP ());
+ if (region_sp)
+ {
+ return region_sp->GetRange().GetRangeEnd();
+ }
+ return 0;
+}
+
+bool
+SBMemoryRegionInfo::IsReadable () {
+ MemoryRegionInfoSP region_sp (GetSP ());
+ if (region_sp)
+ {
+ return region_sp->GetReadable() == MemoryRegionInfo::eYes;
+ }
+ return false;
+}
+
+bool
+SBMemoryRegionInfo::IsWritable () {
+ MemoryRegionInfoSP region_sp (GetSP ());
+ if (region_sp)
+ {
+ return region_sp->GetWritable() == MemoryRegionInfo::eYes;
+ }
+ return false;
+}
+
+bool
+SBMemoryRegionInfo::IsExecutable () {
+ MemoryRegionInfoSP region_sp (GetSP ());
+ if (region_sp)
+ {
+ return region_sp->GetExecutable() == MemoryRegionInfo::eYes;
+ }
+ return false;
+}
+
+bool
+SBMemoryRegionInfo::GetDescription (SBStream &description)
+{
+ Stream &strm = description.ref();
+
+ MemoryRegionInfoSP region_sp (GetSP());
+ if (region_sp)
+ {
+ const addr_t load_addr = region_sp->GetRange().base;
+ strm.Printf ("[0x%16.16" PRIx64 "-0x%16.16" PRIx64 " ", load_addr, load_addr + region_sp->GetRange().size);
+ strm.Printf (region_sp->GetReadable() ? "R" : "-");
+ strm.Printf (region_sp->GetWritable() ? "W" : "-");
+ strm.Printf (region_sp->GetExecutable() ? "X" : "-");
+ strm.Printf ("]");
+ }
+ else
+ {
+ strm.PutCString ("No value");
+ }
+
+ return true;
+}
Index: source/API/CMakeLists.txt
===================================================================
--- source/API/CMakeLists.txt
+++ source/API/CMakeLists.txt
@@ -35,6 +35,8 @@
SBLaunchInfo.cpp
SBLineEntry.cpp
SBListener.cpp
+ SBMemoryRegionInfo.cpp
+ SBMemoryRegionInfoList.cpp
SBModule.cpp
SBModuleSpec.cpp
SBPlatform.cpp
Index: include/lldb/lldb-forward.h
===================================================================
--- include/lldb/lldb-forward.h
+++ include/lldb/lldb-forward.h
@@ -356,6 +356,8 @@
typedef std::weak_ptr<lldb_private::Listener> ListenerWP;
typedef std::shared_ptr<lldb_private::LogChannel> LogChannelSP;
typedef std::shared_ptr<lldb_private::MemoryHistory> MemoryHistorySP;
+ typedef std::shared_ptr<lldb_private::MemoryRegionInfo> MemoryRegionInfoSP;
+ typedef std::weak_ptr<lldb_private::Section> MemoryRegionInfoWP;
typedef std::shared_ptr<lldb_private::Module> ModuleSP;
typedef std::weak_ptr<lldb_private::Module> ModuleWP;
typedef std::shared_ptr<lldb_private::ObjectFile> ObjectFileSP;
Index: include/lldb/Target/Process.h
===================================================================
--- include/lldb/Target/Process.h
+++ include/lldb/Target/Process.h
@@ -2447,6 +2447,14 @@
}
virtual Error
+ GetMemoryRegions (std::vector<lldb::MemoryRegionInfoSP>&)
+ {
+ Error error;
+ error.SetErrorString ("Process::GetMemoryRegions() not supported");
+ return error;
+ }
+
+ virtual Error
GetWatchpointSupportInfo (uint32_t &num)
{
Error error;
Index: include/lldb/API/SBStream.h
===================================================================
--- include/lldb/API/SBStream.h
+++ include/lldb/API/SBStream.h
@@ -76,6 +76,7 @@
friend class SBInstruction;
friend class SBInstructionList;
friend class SBLineEntry;
+ friend class SBMemoryRegionInfo;
friend class SBModule;
friend class SBModuleSpec;
friend class SBModuleSpecList;
Index: include/lldb/API/SBProcess.h
===================================================================
--- include/lldb/API/SBProcess.h
+++ include/lldb/API/SBProcess.h
@@ -393,6 +393,34 @@
lldb::SBError
SaveCore(const char *file_name);
+ //------------------------------------------------------------------
+ /// Query the address load_addr and store the details of the memory
+ /// region that contains it in the supplied SBMemoryRegionInfo object.
+ /// To iterate over all memory regions use GetMemoryRegionList.
+ ///
+ /// @param[in] load_addr
+ /// The address to be queried.
+ ///
+ /// @param[out] region_info
+ /// A reference to an SBMemoryRegionInfo object that will contain
+ /// the details of the memory region containing load_addr.
+ ///
+ /// @return
+ /// An error object describes any errors that occurred while
+ /// querying load_addr.
+ //------------------------------------------------------------------
+ lldb::SBError
+ GetMemoryRegionInfo (lldb::addr_t load_addr, lldb::SBMemoryRegionInfo ®ion_info);
+
+ //------------------------------------------------------------------
+ /// Return the list of memory regions within the process.
+ ///
+ /// @return
+ /// A list of all witin the process memory regions.
+ //------------------------------------------------------------------
+ lldb::SBMemoryRegionInfoList
+ GetMemoryRegions();
+
protected:
friend class SBAddress;
friend class SBBreakpoint;
Index: include/lldb/API/SBMemoryRegionInfoList.h
===================================================================
--- /dev/null
+++ include/lldb/API/SBMemoryRegionInfoList.h
@@ -0,0 +1,66 @@
+//===-- SBMemoryRegionInfoList.h --------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SBMemoryRegionInfoList_h_
+#define LLDB_SBMemoryRegionInfoList_h_
+
+#include "lldb/API/SBDefines.h"
+
+class MemoryRegionInfoListImpl;
+
+namespace lldb {
+
+class LLDB_API SBMemoryRegionInfoList
+{
+public:
+
+ SBMemoryRegionInfoList ();
+
+ SBMemoryRegionInfoList (const lldb::SBMemoryRegionInfoList &rhs);
+
+ const SBMemoryRegionInfoList &
+ operator = (const SBMemoryRegionInfoList &rhs);
+
+ ~SBMemoryRegionInfoList ();
+
+ bool
+ IsValid() const;
+
+ uint32_t
+ GetSize () const;
+
+ bool
+ GetMemoryRegionAtIndex (uint32_t idx, SBMemoryRegionInfo ®ion_info);
+
+ void
+ Append (lldb::SBMemoryRegionInfo ®ion);
+
+ void
+ Append (lldb::SBMemoryRegionInfoList ®ion_list);
+
+ void
+ Clear ();
+
+protected:
+
+ const MemoryRegionInfoListImpl *
+ operator->() const;
+
+ const MemoryRegionInfoListImpl &
+ operator*() const;
+
+private:
+
+ std::unique_ptr<MemoryRegionInfoListImpl> m_opaque_ap;
+
+};
+
+} // namespace lldb
+
+#endif // LLDB_SBMemoryRegionInfoList_h_
Index: include/lldb/API/SBMemoryRegionInfo.h
===================================================================
--- /dev/null
+++ include/lldb/API/SBMemoryRegionInfo.h
@@ -0,0 +1,110 @@
+//===-- SBMemoryRegionInfo.h ------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SBMemoryRegionInfo_h_
+#define LLDB_SBMemoryRegionInfo_h_
+
+#include "lldb/API/SBDefines.h"
+#include "lldb/API/SBData.h"
+
+namespace lldb {
+
+class LLDB_API SBMemoryRegionInfo
+{
+public:
+
+ SBMemoryRegionInfo ();
+
+ SBMemoryRegionInfo (const lldb::SBMemoryRegionInfo &rhs);
+
+ ~SBMemoryRegionInfo ();
+
+ const lldb::SBMemoryRegionInfo &
+ operator = (const lldb::SBMemoryRegionInfo &rhs);
+
+ bool
+ IsValid () const;
+
+ void
+ Clear();
+
+ //------------------------------------------------------------------
+ /// Get the base address of this memory range.
+ ///
+ /// @return
+ /// The base address of this memory range.
+ //------------------------------------------------------------------
+ lldb::addr_t
+ GetRegionBase ();
+
+ //------------------------------------------------------------------
+ /// Get the end address of this memory range.
+ ///
+ /// @return
+ /// The base address of this memory range.
+ //------------------------------------------------------------------
+ lldb::addr_t
+ GetRegionEnd ();
+
+ //------------------------------------------------------------------
+ /// Check if this memory address is marked readable to the process.
+ ///
+ /// @return
+ /// true if this memory address is marked readable
+ //------------------------------------------------------------------
+ bool
+ IsReadable ();
+
+ //------------------------------------------------------------------
+ /// Check if this memory address is marked writable to the process.
+ ///
+ /// @return
+ /// true if this memory address is marked writable
+ //------------------------------------------------------------------
+ bool
+ IsWritable ();
+
+ //------------------------------------------------------------------
+ /// Check if this memory address is marked executable to the process.
+ ///
+ /// @return
+ /// true if this memory address is marked executable
+ //------------------------------------------------------------------
+ bool
+ IsExecutable ();
+
+ bool
+ operator == (const lldb::SBMemoryRegionInfo &rhs) const;
+
+ bool
+ operator != (const lldb::SBMemoryRegionInfo &rhs) const;
+
+ bool
+ GetDescription (lldb::SBStream &description);
+
+private:
+
+ friend class SBProcess;
+ friend class SBMemoryRegionInfoList;
+
+ SBMemoryRegionInfo (const lldb::MemoryRegionInfoSP ®ion_sp);
+
+ lldb::MemoryRegionInfoSP
+ GetSP() const;
+
+ void
+ SetSP (const MemoryRegionInfoSP ®ion_sp);
+
+ lldb::MemoryRegionInfoSP m_opaque_sp;
+};
+
+
+} // namespace lldb
+
+#endif // LLDB_SBMemoryRegionInfo_h_
Index: include/lldb/API/SBDefines.h
===================================================================
--- include/lldb/API/SBDefines.h
+++ include/lldb/API/SBDefines.h
@@ -59,6 +59,8 @@
class LLDB_API SBLaunchInfo;
class LLDB_API SBLineEntry;
class LLDB_API SBListener;
+class LLDB_API SBMemoryRegionInfo;
+class LLDB_API SBMemoryRegionInfoList;
class LLDB_API SBModule;
class LLDB_API SBModuleSpec;
class LLDB_API SBModuleSpecList;
Index: include/lldb/API/LLDB.h
===================================================================
--- include/lldb/API/LLDB.h
+++ include/lldb/API/LLDB.h
@@ -43,6 +43,8 @@
#include "lldb/API/SBLaunchInfo.h"
#include "lldb/API/SBLineEntry.h"
#include "lldb/API/SBListener.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "lldb/API/SBMemoryRegionInfoList.h"
#include "lldb/API/SBModule.h"
#include "lldb/API/SBModuleSpec.h"
#include "lldb/API/SBPlatform.h"
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits