[Lldb-commits] [lldb] f2f3b1a - [lldb] Do not deallocate memory after exec
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Wed Jan 11 12:34:25 PST 2023
Author: Alex Langford
Date: 2023-01-11T12:33:41-08:00
New Revision: f2f3b1a87ad294433986683864f75575c3a81779
URL: https://github.com/llvm/llvm-project/commit/f2f3b1a87ad294433986683864f75575c3a81779
DIFF: https://github.com/llvm/llvm-project/commit/f2f3b1a87ad294433986683864f75575c3a81779.diff
LOG: [lldb] Do not deallocate memory after exec
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
Differential Revision: https://reviews.llvm.org/D140249
Added:
Modified:
lldb/include/lldb/Target/Memory.h
lldb/source/Target/Memory.cpp
lldb/source/Target/Process.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Target/Memory.h b/lldb/include/lldb/Target/Memory.h
index b3ad22aff16bd..8c564e8f5a8c5 100644
--- a/lldb/include/lldb/Target/Memory.h
+++ b/lldb/include/lldb/Target/Memory.h
@@ -116,7 +116,7 @@ class AllocatedMemoryCache {
~AllocatedMemoryCache();
- void Clear();
+ void Clear(bool deallocate_memory);
lldb::addr_t AllocateMemory(size_t byte_size, uint32_t permissions,
Status &error);
diff --git a/lldb/source/Target/Memory.cpp b/lldb/source/Target/Memory.cpp
index a07a72f31922e..d4dedeea7c2c5 100644
--- a/lldb/source/Target/Memory.cpp
+++ b/lldb/source/Target/Memory.cpp
@@ -332,9 +332,9 @@ AllocatedMemoryCache::AllocatedMemoryCache(Process &process)
AllocatedMemoryCache::~AllocatedMemoryCache() = default;
-void AllocatedMemoryCache::Clear() {
+void AllocatedMemoryCache::Clear(bool deallocate_memory) {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
- if (m_process.IsAlive()) {
+ if (m_process.IsAlive() && deallocate_memory) {
PermissionsToBlockMap::iterator pos, end = m_memory_map.end();
for (pos = m_memory_map.begin(); pos != end; ++pos)
m_process.DoDeallocateMemory(pos->second->GetBaseAddress());
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 1abe12f2a5920..e0cca0595ee30 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -543,7 +543,7 @@ void Process::Finalize() {
m_notifications.swap(empty_notifications);
m_image_tokens.clear();
m_memory_cache.Clear();
- m_allocated_memory_cache.Clear();
+ m_allocated_memory_cache.Clear(/*deallocate_memory=*/true);
{
std::lock_guard<std::recursive_mutex> guard(m_language_runtimes_mutex);
m_language_runtimes.clear();
@@ -5657,7 +5657,9 @@ void Process::DidExec() {
m_dyld_up.reset();
m_jit_loaders_up.reset();
m_image_tokens.clear();
- m_allocated_memory_cache.Clear();
+ // After an exec, the inferior is a new process and these memory regions are
+ // no longer allocated.
+ m_allocated_memory_cache.Clear(/*deallocte_memory=*/false);
{
std::lock_guard<std::recursive_mutex> guard(m_language_runtimes_mutex);
m_language_runtimes.clear();
More information about the lldb-commits
mailing list