[Lldb-commits] [lldb] 139e2a3 - [lldb] Remove orphaned modules in a loop

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 20 01:48:21 PDT 2020


Author: Raphael Isemann
Date: 2020-07-20T10:47:56+02:00
New Revision: 139e2a3f7b279ca886c71b676f983ea314c36568

URL: https://github.com/llvm/llvm-project/commit/139e2a3f7b279ca886c71b676f983ea314c36568
DIFF: https://github.com/llvm/llvm-project/commit/139e2a3f7b279ca886c71b676f983ea314c36568.diff

LOG: [lldb] Remove orphaned modules in a loop

Summary:

When modules reference each other (which happens for example with the different
modules LLDB loads when debugging -gmodules-compiled binaries), just iterating
over the module list once isn't good enough to find all orphans. Any removed
modules in the module list will also clear up the shared pointers they hold to
other modules, so after any module was removed from the list, LLDB should
iterate again and check if any additional modules can no be safely deleted.

This is currently causing that many gmodules tests are not cleaning up all
allocated modules which causes cleanup asserts to fail (right now these asserts
just mark the test as unsupported, but after D83865 the tests will start
failing).

Reviewers: aprantl, clayborg, JDevlieghere

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D84015

Added: 
    

Modified: 
    lldb/source/Core/ModuleList.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index 0345678ddaff..1f1f5efcf4cc 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -291,14 +291,24 @@ size_t ModuleList::RemoveOrphans(bool mandatory) {
     if (!lock.try_lock())
       return 0;
   }
-  collection::iterator pos = m_modules.begin();
   size_t remove_count = 0;
-  while (pos != m_modules.end()) {
-    if (pos->unique()) {
-      pos = RemoveImpl(pos);
-      ++remove_count;
-    } else {
-      ++pos;
+  // Modules might hold shared pointers to other modules, so removing one
+  // module might make other other modules orphans. Keep removing modules until
+  // there are no further modules that can be removed.
+  bool made_progress = true;
+  while (made_progress) {
+    // Keep track if we make progress this iteration.
+    made_progress = false;
+    collection::iterator pos = m_modules.begin();
+    while (pos != m_modules.end()) {
+      if (pos->unique()) {
+        pos = RemoveImpl(pos);
+        ++remove_count;
+        // We did make progress.
+        made_progress = true;
+      } else {
+        ++pos;
+      }
     }
   }
   return remove_count;


        


More information about the lldb-commits mailing list