Skip to content

Commit f2f3b1a

Browse files
committed
[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
1 parent cf14ef9 commit f2f3b1a

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

lldb/include/lldb/Target/Memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class AllocatedMemoryCache {
116116

117117
~AllocatedMemoryCache();
118118

119-
void Clear();
119+
void Clear(bool deallocate_memory);
120120

121121
lldb::addr_t AllocateMemory(size_t byte_size, uint32_t permissions,
122122
Status &error);

lldb/source/Target/Memory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@ AllocatedMemoryCache::AllocatedMemoryCache(Process &process)
332332

333333
AllocatedMemoryCache::~AllocatedMemoryCache() = default;
334334

335-
void AllocatedMemoryCache::Clear() {
335+
void AllocatedMemoryCache::Clear(bool deallocate_memory) {
336336
std::lock_guard<std::recursive_mutex> guard(m_mutex);
337-
if (m_process.IsAlive()) {
337+
if (m_process.IsAlive() && deallocate_memory) {
338338
PermissionsToBlockMap::iterator pos, end = m_memory_map.end();
339339
for (pos = m_memory_map.begin(); pos != end; ++pos)
340340
m_process.DoDeallocateMemory(pos->second->GetBaseAddress());

lldb/source/Target/Process.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ void Process::Finalize() {
543543
m_notifications.swap(empty_notifications);
544544
m_image_tokens.clear();
545545
m_memory_cache.Clear();
546-
m_allocated_memory_cache.Clear();
546+
m_allocated_memory_cache.Clear(/*deallocate_memory=*/true);
547547
{
548548
std::lock_guard<std::recursive_mutex> guard(m_language_runtimes_mutex);
549549
m_language_runtimes.clear();
@@ -5657,7 +5657,9 @@ void Process::DidExec() {
56575657
m_dyld_up.reset();
56585658
m_jit_loaders_up.reset();
56595659
m_image_tokens.clear();
5660-
m_allocated_memory_cache.Clear();
5660+
// After an exec, the inferior is a new process and these memory regions are
5661+
// no longer allocated.
5662+
m_allocated_memory_cache.Clear(/*deallocte_memory=*/false);
56615663
{
56625664
std::lock_guard<std::recursive_mutex> guard(m_language_runtimes_mutex);
56635665
m_language_runtimes.clear();

0 commit comments

Comments
 (0)