================ @@ -87,12 +87,33 @@ Status SaveCoreOptions::AddThread(lldb::ThreadSP thread_sp) { m_process_sp = thread_sp->GetProcess(); } - m_threads_to_save.insert(thread_sp->GetID()); + m_threads_to_save.insert({thread_sp->GetID(), thread_sp}); + m_thread_indexes.push_back(thread_sp->GetID()); return error; } bool SaveCoreOptions::RemoveThread(lldb::ThreadSP thread_sp) { - return thread_sp && m_threads_to_save.erase(thread_sp->GetID()) > 0; + if (!thread_sp) + return false; + if (m_threads_to_save.erase(thread_sp->GetID()) == 0) + return false; + + auto it = std::find(m_thread_indexes.begin(), m_thread_indexes.end(), + thread_sp->GetID()); + m_thread_indexes.erase(it); + return true; +} + +uint32_t SaveCoreOptions::GetNumThreads() const { + return m_threads_to_save.size(); +} + +std::optional<lldb::ThreadSP> +SaveCoreOptions::GetThreadAtIndex(uint32_t idx) const { + if (idx >= m_thread_indexes.size()) + return std::nullopt; + lldb::tid_t tid = m_thread_indexes[idx]; + return m_threads_to_save.find(tid)->second; ---------------- clayborg wrote:
If we only have a `std::vector<tid_t> m_threads_to_save` now, this can be: ``` if (!m_process_sp || idx >= m_threads_to_save.size()) return ThreadSP(); return process_sp->GetThreadList().FindThreadByID(m_threads_to_save[idx], /*can_update=*/false); ``` https://github.com/llvm/llvm-project/pull/122541 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits