diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2024-12-03 11:05:38 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2024-12-05 11:43:14 -0500 |
commit | 7a0a2f75f003ec1c3cb5d1013070913cef4d1f35 (patch) | |
tree | 53e1aab4ea6c299c3161746d100d6378439ba2da | |
parent | a042adc98554870ba21e3cda5211a28fad98c217 (diff) | |
download | binutils-7a0a2f75f003ec1c3cb5d1013070913cef4d1f35.zip binutils-7a0a2f75f003ec1c3cb5d1013070913cef4d1f35.tar.gz binutils-7a0a2f75f003ec1c3cb5d1013070913cef4d1f35.tar.bz2 |
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
-rw-r--r-- | gdbserver/inferiors.cc | 28 | ||||
-rw-r--r-- | gdbserver/inferiors.h | 4 |
2 files changed, 20 insertions, 12 deletions
diff --git a/gdbserver/inferiors.cc b/gdbserver/inferiors.cc index b0610d6..7a0209b 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 @@ -233,6 +227,18 @@ find_process (gdb::function_view<bool (process_info *)> 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<bool (thread_info *)> func) { for (thread_info &thread : m_thread_list) @@ -282,11 +288,9 @@ find_thread (ptid_t filter, gdb::function_view<bool (thread_info *)> 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 f6eb3df..5757a1f 100644 --- a/gdbserver/inferiors.h +++ b/gdbserver/inferiors.h @@ -97,6 +97,10 @@ struct process_info : public intrusive_list_node<process_info> std::unordered_map<ptid_t, thread_info *> &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<bool (thread_info *)> func); |