[Lldb-commits] [lldb] [lldb] Don't add the same module to a target twice (PR #208472)

Charles Zablit via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 9 07:20:53 PDT 2026


https://github.com/charles-zablit created https://github.com/llvm/llvm-project/pull/208472

`Target::GetOrCreateModule` uses `Append`, so a module already in the target could be added again. Then `RemoveModule` dropped only one, keeping the module (and its memory-mapped file) alive.
On Windows that mapped file can't be deleted, causing `TestReplaceDLL.py` to fail with `LLDB_USE_LLDB_SERVER=1`.

This patch uses `AppendIfNeeded` instead.

rdar://181797592

>From 308fd85ca8304570b226dd420b826a8f70b329a9 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Thu, 9 Jul 2026 15:18:51 +0100
Subject: [PATCH] [lldb] Don't add the same module to a target twice

---
 lldb/source/Target/Target.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 4084d72ee1317..b0c3b71c39650 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -2660,7 +2660,7 @@ ModuleSP Target::GetOrCreateModule(const ModuleSpec &orig_module_spec,
         }
 
         if (replaced_modules.empty())
-          m_images.Append(module_sp, notify);
+          m_images.AppendIfNeeded(module_sp, notify);
 
         for (ModuleSP &old_module_sp : replaced_modules) {
           auto old_module_wp = old_module_sp->weak_from_this();



More information about the lldb-commits mailing list