[Lldb-commits] [lldb] r132585 - in /lldb/trunk/source/Plugins/Process/Linux: ProcessLinux.cpp ProcessLinux.h
Peter Collingbourne
peter at pcc.me.uk
Fri Jun 3 13:40:44 PDT 2011
Author: pcc
Date: Fri Jun 3 15:40:44 2011
New Revision: 132585
URL: http://llvm.org/viewvc/llvm-project?rev=132585&view=rev
Log:
Implement ProcessLinux::Do{Allocate,Deallocate}Memory using inferior mmap/munmap calls
Modified:
lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp
lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h
Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp?rev=132585&r1=132584&r2=132585&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp Fri Jun 3 15:40:44 2011
@@ -13,12 +13,14 @@
// C++ Includes
// Other libraries and framework includes
#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/State.h"
#include "lldb/Host/Host.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/Target.h"
#include "ProcessLinux.h"
+#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
#include "ProcessMonitor.h"
#include "LinuxThread.h"
@@ -345,19 +347,40 @@
ProcessLinux::DoAllocateMemory(size_t size, uint32_t permissions,
Error &error)
{
- return 0;
-}
+ addr_t allocated_addr = LLDB_INVALID_ADDRESS;
-addr_t
-ProcessLinux::AllocateMemory(size_t size, uint32_t permissions, Error &error)
-{
- return 0;
+ unsigned prot = 0;
+ if (permissions & lldb::ePermissionsReadable)
+ prot |= eMmapProtRead;
+ if (permissions & lldb::ePermissionsWritable)
+ prot |= eMmapProtWrite;
+ if (permissions & lldb::ePermissionsExecutable)
+ prot |= eMmapProtExec;
+
+ if (InferiorCallMmap(this, allocated_addr, 0, size, prot,
+ eMmapFlagsAnon | eMmapFlagsPrivate, -1, 0)) {
+ m_addr_to_mmap_size[allocated_addr] = size;
+ error.Clear();
+ } else {
+ allocated_addr = LLDB_INVALID_ADDRESS;
+ error.SetErrorStringWithFormat("unable to allocate %zu bytes of memory with permissions %s", size, GetPermissionsAsCString (permissions));
+ }
+
+ return allocated_addr;
}
Error
-ProcessLinux::DoDeallocateMemory(lldb::addr_t ptr)
+ProcessLinux::DoDeallocateMemory(lldb::addr_t addr)
{
- return Error(1, eErrorTypeGeneric);
+ Error error;
+ MMapMap::iterator pos = m_addr_to_mmap_size.find(addr);
+ if (pos != m_addr_to_mmap_size.end() &&
+ InferiorCallMunmap(this, addr, pos->second))
+ m_addr_to_mmap_size.erase (pos);
+ else
+ error.SetErrorStringWithFormat("unable to deallocate memory at 0x%llx", addr);
+
+ return error;
}
size_t
Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h?rev=132585&r1=132584&r2=132585&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h Fri Jun 3 15:40:44 2011
@@ -114,10 +114,6 @@
DoAllocateMemory(size_t size, uint32_t permissions,
lldb_private::Error &error);
- lldb::addr_t
- AllocateMemory(size_t size, uint32_t permissions,
- lldb_private::Error &error);
-
virtual lldb_private::Error
DoDeallocateMemory(lldb::addr_t ptr);
@@ -220,6 +216,9 @@
/// Returns true if the process is stopped.
bool IsStopped();
+
+ typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
+ MMapMap m_addr_to_mmap_size;
};
#endif // liblldb_MacOSXProcess_H_
More information about the lldb-commits
mailing list