]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbserver: make add_thread a method of process_info
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 7 Nov 2024 16:17:56 +0000 (16:17 +0000)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 8 Nov 2024 14:16:23 +0000 (09:16 -0500)
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>
gdbserver/gdbthread.h
gdbserver/inferiors.cc
gdbserver/inferiors.h
gdbserver/linux-low.cc
gdbserver/netbsd-low.cc
gdbserver/win32-low.cc

index 94333c491a276978297a0e7dcb9d21b1edab2b3a..d00dc04d5a9f6f13125b9680e83a7de7ebf106a0 100644 (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.  */
 
index d447808be693cb546a5cd07462d1209f7f70a7d2..7d9152dae4c6b324548dd43b877b0b21e92acd81 100644 (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);
index 145737b9658f1bf6019b3ad21a521f5d103167e8..fd3ee28fa52980df62ddcab060c8ad27b5972594 100644 (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;
index 39a7180e38849f34b59aa0552d29334255b344ee..a21d5625b4861143d73a2f686b391101e336c64b 100644 (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);
 
index 1a3ef16b00a246ce133855809912a48f06e6a715..53cb6fa858c57d74aa29702ea280d064a6b30be6 100644 (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 ())
        {
index 41eed201c101e11347042c11b5cb7580b6ba29c1..3236bb9677fd594bc4c2b202f693308251df0486 100644 (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);