From: Simon Marchi Date: Tue, 3 Dec 2024 16:05:38 +0000 (-0500) Subject: gdbserver: add and use `process_info::find_thread(ptid)` X-Git-Tag: gdb-16-branchpoint~178 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7a0a2f75f003ec1c3cb5d1013070913cef4d1f35;p=thirdparty%2Fbinutils-gdb.git gdbserver: add and use `process_info::find_thread(ptid)` Add an overload of `process_info::find_thread` that finds a thread by ptid. Use it in two spots. Change-Id: I2b7fb819bf4f83f7bd37f8641c38e878119b3814 --- diff --git a/gdbserver/inferiors.cc b/gdbserver/inferiors.cc index b0610d6d07d..7a0209b1673 100644 --- a/gdbserver/inferiors.cc +++ b/gdbserver/inferiors.cc @@ -71,13 +71,7 @@ find_thread_ptid (ptid_t ptid) if (process == nullptr) return nullptr; - auto &thread_map = process->thread_map (); - - if (auto it = thread_map.find (ptid); - it != thread_map.end ()) - return it->second; - - return nullptr; + return process->find_thread (ptid); } /* Find a thread associated with the given PROCESS, or NULL if no @@ -232,6 +226,18 @@ find_process (gdb::function_view func) /* See inferiors.h. */ +thread_info * +process_info::find_thread (ptid_t ptid) +{ + if (auto it = m_ptid_thread_map.find (ptid); + it != m_ptid_thread_map.end ()) + return it->second; + + return nullptr; +} + +/* See inferiors.h. */ + thread_info * process_info::find_thread (gdb::function_view func) { @@ -282,11 +288,9 @@ find_thread (ptid_t filter, gdb::function_view func) if (filter.is_pid ()) return process->find_thread (func); - auto &thread_map = process->thread_map (); - - if (auto it = thread_map.find (filter); - it != thread_map.end () && func (it->second)) - return it->second; + if (thread_info *thread = process->find_thread (filter); + thread != nullptr && func (thread)) + return thread; return nullptr; } diff --git a/gdbserver/inferiors.h b/gdbserver/inferiors.h index f6eb3dfa488..5757a1f96e3 100644 --- a/gdbserver/inferiors.h +++ b/gdbserver/inferiors.h @@ -97,6 +97,10 @@ struct process_info : public intrusive_list_node std::unordered_map &thread_map () { return m_ptid_thread_map; } + /* Return the thread with ptid PTID, or nullptr if no such thread is + found. */ + thread_info *find_thread (ptid_t ptid); + /* Find the first thread for which FUNC returns true. Return nullptr if no such thread is found. */ thread_info *find_thread (gdb::function_view func);