]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbserver: add and use `process_info::find_thread(ptid)`
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 3 Dec 2024 16:05:38 +0000 (11:05 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Thu, 5 Dec 2024 16:43:14 +0000 (11:43 -0500)
Add an overload of `process_info::find_thread` that finds a thread by
ptid.  Use it in two spots.

Change-Id: I2b7fb819bf4f83f7bd37f8641c38e878119b3814

gdbserver/inferiors.cc
gdbserver/inferiors.h

index b0610d6d07d1c00e13942ad21bb4366a3e7ddca4..7a0209b167365747dd0503828d1207efdd1cc6c5 100644 (file)
@@ -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<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)
 {
@@ -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;
 }
index f6eb3dfa488a548dad3825c9955e179b5361f63b..5757a1f96e32bf0825c2812bff9c548796f0865d 100644 (file)
@@ -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);