This revision was automatically updated to reflect the committed changes. Closed by commit rG139e2a3f7b27: [lldb] Remove orphaned modules in a loop (authored by teemperor). Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
Changed prior to commit: https://reviews.llvm.org/D84015?vs=278714&id=278993#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D84015/new/ https://reviews.llvm.org/D84015 Files: lldb/source/Core/ModuleList.cpp Index: lldb/source/Core/ModuleList.cpp =================================================================== --- lldb/source/Core/ModuleList.cpp +++ lldb/source/Core/ModuleList.cpp @@ -291,14 +291,24 @@ 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;
Index: lldb/source/Core/ModuleList.cpp =================================================================== --- lldb/source/Core/ModuleList.cpp +++ lldb/source/Core/ModuleList.cpp @@ -291,14 +291,24 @@ 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;
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits