]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbserver/win32-low.cc: remove use of `all_threads`
authorSimon Marchi <simon.marchi@polymtl.ca>
Tue, 3 Dec 2024 20:01:14 +0000 (15:01 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Thu, 5 Dec 2024 16:43:14 +0000 (11:43 -0500)
Fix this:

    gdbserver/win32-low.cc: In function ‘void child_delete_thread(DWORD, DWORD)’:
    gdbserver/win32-low.cc:192:7: error: ‘all_threads’ was not declared in this scope; did you mean ‘using_threads’?
      192 |   if (all_threads.size () == 1)
          |       ^~~~~~~~~~~
          |       using_threads

Commit 9f77b3aa0bfc ("gdbserver: change 'all_processes' and
'all_threads' list type") changed the type of `all_thread` to an
intrusive_list, without changing this particular use, which broke the
build because an intrusive_list doesn't know its size, so it doesn't
have a `size()` method.  The subsequent commit removed `all_threads`,
leading to the error above.

Fix it by using the number of threads of the concerned process instead.
My rationale: as far as I know, GDBserver on Windows only supports one
process at a time, so there's no need to iterate over all processes.  If
we made GDBserver for Windows support multiple processes, my intuition
is that we'd want this check to use the number of threads of the
concerned process, not the number of threads overall.

Add the method `process_info::thread_count`, to get the number of
threads of the process.

I'm not really sure what this check is for in the first place, Hannes
Domani said that this check didn't seem to trigger on Windows 7 and 11.
Perhaps it was necessary before.

Change-Id: I84d6226532b887d99248cf3be90f5065fb7a074a
Tested-By: Hannes Domani <ssbssa@yahoo.de>
gdbserver/inferiors.h
gdbserver/win32-low.cc

index 5757a1f96e32bf0825c2812bff9c548796f0865d..5867608ba466fdcee334f5ffa8e5fcc40045a1af 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 number of threads in this process.  */
+  unsigned int thread_count () const
+  { return m_ptid_thread_map.size (); }
+
   /* Return the thread with ptid PTID, or nullptr if no such thread is
      found.  */
   thread_info *find_thread (ptid_t ptid);
index d19e89152ec03de996c16644bdefb5350183fce1..c3115ea826c83468cc26b6ed5786b263dcd3024e 100644 (file)
@@ -188,12 +188,17 @@ delete_thread_info (thread_info *thread)
 static void
 child_delete_thread (DWORD pid, DWORD tid)
 {
+  process_info *process = find_process_pid (pid);
+
+  if (process == nullptr)
+    return;
+
   /* If the last thread is exiting, just return.  */
-  if (all_threads.size () == 1)
+  if (process->thread_count () == 1)
     return;
 
-  thread_info *thread = find_thread_ptid (ptid_t (pid, tid));
-  if (thread == NULL)
+  thread_info *thread = process->find_thread (ptid_t (pid, tid));
+  if (thread == nullptr)
     return;
 
   delete_thread_info (thread);