[Lldb-commits] [lldb] Fix race condition during iteration through modules (#139283) (PR #139862)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed May 14 10:44:21 PDT 2025


================
@@ -1510,6 +1510,7 @@ bool Target::IgnoreWatchpointByID(lldb::watch_id_t watch_id,
 }
 
 ModuleSP Target::GetExecutableModule() {
+  std::lock_guard<std::recursive_mutex> guard(m_images.GetMutex());
----------------
JDevlieghere wrote:

Let's use the `Modules()` iterable which allows us to use a for-based loop and does the locking for us:

```
  // Search for the first executable in the module list.
  for (ModuleSP module_sp : m_images.Modules()) {
    lldb_private::ObjectFile *obj = module_sp->GetObjectFile();
```

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


More information about the lldb-commits mailing list