Index: lldb/source/Core/ModuleList.cpp =================================================================== --- lldb/source/Core/ModuleList.cpp +++ lldb/source/Core/ModuleList.cpp @@ -291,15 +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. + while (true) { + bool made_progress = false; + collection::iterator pos = m_modules.begin(); + while (pos != m_modules.end()) { + if (pos->unique()) { + pos = RemoveImpl(pos); + ++remove_count; + made_progress = true; + } else { + ++pos; + } } + if (!made_progress) + break; } return remove_count; }