From: Simon Marchi Date: Thu, 7 Nov 2024 16:17:56 +0000 (+0000) Subject: gdbserver: make add_thread a method of process_info X-Git-Tag: gdb-16-branchpoint~500 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9618dbfe52fa98e224e53e18626fbe08e9c892a7;p=thirdparty%2Fbinutils-gdb.git gdbserver: make add_thread a method of process_info Since thread_info objects are now basically children of process_info objects, I think that makes sense. Change-Id: I7f0a67b921b468e512851cb2f36015d1003412d7 Reviewed-By: Tankut Baris Aktemur --- diff --git a/gdbserver/gdbthread.h b/gdbserver/gdbthread.h index 94333c491a2..d00dc04d5a9 100644 --- a/gdbserver/gdbthread.h +++ b/gdbserver/gdbthread.h @@ -91,7 +91,6 @@ private: }; void remove_thread (struct thread_info *thread); -struct thread_info *add_thread (ptid_t ptid, void *target_data); /* Return a pointer to the first thread, or NULL if there isn't one. */ diff --git a/gdbserver/inferiors.cc b/gdbserver/inferiors.cc index d447808be69..7d9152dae4c 100644 --- a/gdbserver/inferiors.cc +++ b/gdbserver/inferiors.cc @@ -38,16 +38,11 @@ struct thread_info *current_thread; Empty if not specified. */ static std::string current_inferior_cwd; -struct thread_info * -add_thread (ptid_t thread_id, void *target_data) +thread_info * +process_info::add_thread (ptid_t id, void *target_data) { - process_info *process = find_process_pid (thread_id.pid ()); - gdb_assert (process != nullptr); - - auto &new_thread - = process->thread_list ().emplace_back (thread_id, process, target_data); - bool inserted - = process->thread_map ().insert ({thread_id, &new_thread}).second; + auto &new_thread = m_thread_list.emplace_back (id, this, target_data); + bool inserted = m_ptid_thread_map.insert ({ id, &new_thread }).second; /* A thread with this ptid should not exist in the map yet. */ gdb_assert (inserted); diff --git a/gdbserver/inferiors.h b/gdbserver/inferiors.h index 145737b9658..fd3ee28fa52 100644 --- a/gdbserver/inferiors.h +++ b/gdbserver/inferiors.h @@ -104,6 +104,9 @@ struct process_info : public intrusive_list_node /* Invoke FUNC for each thread. */ void for_each_thread (gdb::function_view func); + /* Add a thread with id ID to this process. */ + thread_info *add_thread (ptid_t id, void *target_data); + private: /* This processes' thread list, sorted by creation order. */ owning_intrusive_list m_thread_list; diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 39a7180e388..a21d5625b48 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -925,7 +925,7 @@ linux_process_target::add_lwp (ptid_t ptid) { lwp_info *lwp = new lwp_info; - lwp->thread = add_thread (ptid, lwp); + lwp->thread = find_process_pid (ptid.pid ())->add_thread (ptid, lwp); low_new_thread (lwp); diff --git a/gdbserver/netbsd-low.cc b/gdbserver/netbsd-low.cc index 1a3ef16b00a..53cb6fa858c 100644 --- a/gdbserver/netbsd-low.cc +++ b/gdbserver/netbsd-low.cc @@ -321,7 +321,7 @@ netbsd_wait (ptid_t ptid, struct target_waitstatus *ourstatus, ourstatus->set_spurious (); else { - add_thread (wptid, NULL); + find_process_pid (wptid.pid ())->add_thread (wptid, nullptr); ourstatus->set_thread_created (); } return wptid; @@ -391,7 +391,7 @@ netbsd_process_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, that was not fully initialized during the attach stage. */ if (wptid.lwp () != 0 && !find_thread_ptid (wptid) && ourstatus->kind () != TARGET_WAITKIND_THREAD_EXITED) - add_thread (wptid, nullptr); + find_process_pid (wptid.pid ())->add_thread (wptid, nullptr); switch (ourstatus->kind ()) { diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 41eed201c10..3236bb9677f 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -174,7 +174,7 @@ child_add_thread (DWORD pid, DWORD tid, HANDLE h, void *tlb) #endif th = new windows_thread_info (tid, h, base); - add_thread (ptid, th); + find_process_pid (pid)->add_thread (ptid, th); if (the_low_target.thread_added != NULL) (*the_low_target.thread_added) (th);