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 <tankut.baris.aktemur@intel.com>
This commit is contained in:
Simon Marchi 2024-11-07 16:17:56 +00:00 committed by Simon Marchi
parent dceb3cd436
commit 9618dbfe52
6 changed files with 11 additions and 14 deletions

View File

@ -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. */

View File

@ -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);

View File

@ -104,6 +104,9 @@ struct process_info : public intrusive_list_node<process_info>
/* Invoke FUNC for each thread. */
void for_each_thread (gdb::function_view<void (thread_info *)> 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<thread_info> m_thread_list;

View File

@ -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);

View File

@ -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 ())
{

View File

@ -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);