================ @@ -743,9 +743,19 @@ DebuggerSP Debugger::CreateInstance(lldb::LogOutputCallback log_callback, } void Debugger::HandleDestroyCallback() { - if (m_destroy_callback) { - m_destroy_callback(GetID(), m_destroy_callback_baton); - m_destroy_callback = nullptr; + std::lock_guard<std::recursive_mutex> guard(m_destroy_callback_mutex); + const lldb::user_id_t user_id = GetID(); + // In case one destroy callback adds or removes other destroy callbacks + // which aren't taken care of in the same inner loop. + while (m_destroy_callback_and_baton.size()) { + auto iter = m_destroy_callback_and_baton.begin(); + while (iter != m_destroy_callback_and_baton.end()) { + // Invoke the callback and remove the entry from the map + const auto &callback = iter->second.first; + const auto &baton = iter->second.second; + callback(user_id, baton); + iter = m_destroy_callback_and_baton.erase(iter); + } ---------------- royitaqi wrote:
Ah I like it! It's a lot simpler this way. Will update. https://github.com/llvm/llvm-project/pull/89868 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits