[Lldb-commits] [PATCH] D140249: [lldb] Do not deallocate memory after exec

Alex Langford via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Dec 16 15:01:05 PST 2022


bulbazord created this revision.
bulbazord added reviewers: jasonmolenda, jingham, JDevlieghere.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.

After an exec has occured, resources used to manage the state of a
Process are cleaned up. One such resource is the AllocatedMemoryCache
which keeps track of memory allocations made in the process for things
like expression evaluation. After an exec is performed, the allocated
memory regions in the process are gone, so it does not make sense to try
to deallocate those regions.

rdar://103188106


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140249

Files:
  lldb/include/lldb/Target/Memory.h
  lldb/source/Target/Memory.cpp
  lldb/source/Target/Process.cpp


Index: lldb/source/Target/Process.cpp
===================================================================
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -542,7 +542,7 @@
   m_notifications.swap(empty_notifications);
   m_image_tokens.clear();
   m_memory_cache.Clear();
-  m_allocated_memory_cache.Clear();
+  m_allocated_memory_cache.Clear(/*did_exec=*/false);
   {
     std::lock_guard<std::recursive_mutex> guard(m_language_runtimes_mutex);
     m_language_runtimes.clear();
@@ -5656,7 +5656,7 @@
   m_dyld_up.reset();
   m_jit_loaders_up.reset();
   m_image_tokens.clear();
-  m_allocated_memory_cache.Clear();
+  m_allocated_memory_cache.Clear(/*did_exec=*/true);
   {
     std::lock_guard<std::recursive_mutex> guard(m_language_runtimes_mutex);
     m_language_runtimes.clear();
Index: lldb/source/Target/Memory.cpp
===================================================================
--- lldb/source/Target/Memory.cpp
+++ lldb/source/Target/Memory.cpp
@@ -332,9 +332,9 @@
 
 AllocatedMemoryCache::~AllocatedMemoryCache() = default;
 
-void AllocatedMemoryCache::Clear() {
+void AllocatedMemoryCache::Clear(bool did_exec) {
   std::lock_guard<std::recursive_mutex> guard(m_mutex);
-  if (m_process.IsAlive()) {
+  if (m_process.IsAlive() && !did_exec) {
     PermissionsToBlockMap::iterator pos, end = m_memory_map.end();
     for (pos = m_memory_map.begin(); pos != end; ++pos)
       m_process.DoDeallocateMemory(pos->second->GetBaseAddress());
Index: lldb/include/lldb/Target/Memory.h
===================================================================
--- lldb/include/lldb/Target/Memory.h
+++ lldb/include/lldb/Target/Memory.h
@@ -116,7 +116,7 @@
 
   ~AllocatedMemoryCache();
 
-  void Clear();
+  void Clear(bool did_exec);
 
   lldb::addr_t AllocateMemory(size_t byte_size, uint32_t permissions,
                               Status &error);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140249.483674.patch
Type: text/x-patch
Size: 1882 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20221216/9435a080/attachment.bin>


More information about the lldb-commits mailing list