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

via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 9 07:21:36 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Charles Zablit (charles-zablit)

<details>
<summary>Changes</summary>

`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

---
Full diff: https://github.com/llvm/llvm-project/pull/208472.diff


1 Files Affected:

- (modified) lldb/source/Target/Target.cpp (+1-1) 


``````````diff
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();

``````````

</details>


https://github.com/llvm/llvm-project/pull/208472


More information about the lldb-commits mailing list