]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbserver: remove get_thread_process
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 7 Nov 2024 16:22:20 +0000 (16:22 +0000)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 8 Nov 2024 14:16:23 +0000 (09:16 -0500)
Remove the `get_thread_process` function, use `thread_info::process`
instead.

In `server.cc`, use `current_process ()` instead of going through the
current thread.

Change-Id: Ifc61d65852e392d154b854a45d45df584ab3922e
Reviewed-By: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
gdbserver/inferiors.cc
gdbserver/inferiors.h
gdbserver/linux-low.cc
gdbserver/mem-break.cc
gdbserver/regcache.cc
gdbserver/server.cc
gdbserver/thread-db.cc

index 8ca6d6432649235af2a03282ebe74e212f879e6c..7657ddbda2a5bd7148f5a6efa83c0611e6cc126f 100644 (file)
@@ -213,12 +213,6 @@ have_attached_inferiors_p (void)
   }) != NULL;
 }
 
-struct process_info *
-get_thread_process (const struct thread_info *thread)
-{
-  return find_process_pid (thread->id.pid ());
-}
-
 struct process_info *
 current_process (void)
 {
@@ -422,7 +416,7 @@ void
 switch_to_thread (thread_info *thread)
 {
   if (thread != nullptr)
-    current_process_ = get_thread_process (thread);
+    current_process_ = thread->process ();
   else
     current_process_ = nullptr;
   current_thread = thread;
index 002dd2a4ed6d0f04dc003eb87888caff5a6a0b16..c282a7bf188acff3ea5c29592e68e003f169d27c 100644 (file)
@@ -134,7 +134,6 @@ pid_of (const process_info *proc)
    is null.  */
 
 struct process_info *current_process (void);
-struct process_info *get_thread_process (const struct thread_info *);
 
 extern owning_intrusive_list<process_info> all_processes;
 
index 924536c34fa89ff20a417ac4ed9afa495d517d51..e364114c7d21ff3bc8792f3eceb7f2721b7a8753 100644 (file)
@@ -604,7 +604,7 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp,
             the client side will access registers.  */
          gdb_assert (child_proc != NULL);
 
-         process_info *parent_proc = get_thread_process (event_thr);
+         process_info *parent_proc = event_thr->process ();
          child_proc->attached = parent_proc->attached;
 
          clone_all_breakpoints (child_thr, event_thr);
@@ -723,7 +723,6 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp,
     }
   else if (event == PTRACE_EVENT_EXEC && cs.report_exec_events)
     {
-      struct process_info *proc;
       std::vector<int> syscalls_to_catch;
       ptid_t event_ptid;
       pid_t event_pid;
@@ -736,7 +735,7 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp,
       event_pid = event_ptid.pid ();
 
       /* Save the syscall list from the execing process.  */
-      proc = get_thread_process (event_thr);
+      process_info *proc = event_thr->process ();
       syscalls_to_catch = std::move (proc->syscalls_to_catch);
 
       /* Delete the execing process and all its threads.  */
@@ -781,7 +780,7 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp,
 CORE_ADDR
 linux_process_target::get_pc (lwp_info *lwp)
 {
-  process_info *proc = get_thread_process (get_lwp_thread (lwp));
+  process_info *proc = get_lwp_thread (lwp)->process ();
   gdb_assert (!proc->starting_up);
 
   if (!low_supports_breakpoints ())
@@ -829,7 +828,7 @@ linux_process_target::save_stop_reason (lwp_info *lwp)
   if (!low_supports_breakpoints ())
     return false;
 
-  process_info *proc = get_thread_process (get_lwp_thread (lwp));
+  process_info *proc = get_lwp_thread (lwp)->process ();
   if (proc->starting_up)
     {
       /* Claim we have the stop PC so that the caller doesn't try to
@@ -2938,10 +2937,7 @@ linux_process_target::filter_exit_event (lwp_info *event_child,
 static int
 gdb_catching_syscalls_p (struct lwp_info *event_child)
 {
-  struct thread_info *thread = get_lwp_thread (event_child);
-  struct process_info *proc = get_thread_process (thread);
-
-  return !proc->syscalls_to_catch.empty ();
+  return !get_lwp_thread (event_child)->process ()->syscalls_to_catch.empty ();
 }
 
 bool
@@ -2949,7 +2945,7 @@ linux_process_target::gdb_catch_this_syscall (lwp_info *event_child)
 {
   int sysno;
   struct thread_info *thread = get_lwp_thread (event_child);
-  struct process_info *proc = get_thread_process (thread);
+  process_info *proc = thread->process ();
 
   if (proc->syscalls_to_catch.empty ())
     return false;
@@ -4016,7 +4012,6 @@ linux_process_target::resume_one_lwp_throw (lwp_info *lwp, int step,
 {
   struct thread_info *thread = get_lwp_thread (lwp);
   int ptrace_request;
-  struct process_info *proc = get_thread_process (thread);
 
   /* Note that target description may not be initialised
      (proc->tdesc == NULL) at this point because the program hasn't
@@ -4139,7 +4134,7 @@ linux_process_target::resume_one_lwp_throw (lwp_info *lwp, int step,
       step = single_step (lwp);
     }
 
-  if (proc->tdesc != NULL && low_supports_breakpoints ())
+  if (thread->process ()->tdesc != nullptr && low_supports_breakpoints ())
     {
       struct regcache *regcache = get_thread_regcache (current_thread, 1);
 
@@ -4393,11 +4388,10 @@ linux_process_target::thread_needs_step_over (thread_info *thread)
 {
   struct lwp_info *lwp = get_thread_lwp (thread);
   CORE_ADDR pc;
-  struct process_info *proc = get_thread_process (thread);
 
   /* GDBserver is skipping the extra traps from the wrapper program,
      don't have to do step over.  */
-  if (proc->tdesc == NULL)
+  if (thread->process ()->tdesc == nullptr)
     return false;
 
   /* LWPs which will not be resumed are not interesting, because we
index eebf999c223da34244b1eb160f303ea4e91b9aae..1f7af7138cf3792d68d98ff55fbdac48d948ea2c 100644 (file)
@@ -1412,7 +1412,7 @@ set_single_step_breakpoint (CORE_ADDR stop_at, ptid_t ptid)
 void
 delete_single_step_breakpoints (struct thread_info *thread)
 {
-  struct process_info *proc = get_thread_process (thread);
+  process_info *proc = thread->process ();
   struct breakpoint *bp, **bp_link;
 
   bp = proc->breakpoints;
@@ -1507,7 +1507,7 @@ uninsert_all_breakpoints (void)
 void
 uninsert_single_step_breakpoints (struct thread_info *thread)
 {
-  struct process_info *proc = get_thread_process (thread);
+  process_info *proc = thread->process ();
   struct breakpoint *bp;
 
   for (bp = proc->breakpoints; bp != NULL; bp = bp->next)
@@ -1576,7 +1576,7 @@ reinsert_breakpoints_at (CORE_ADDR pc)
 int
 has_single_step_breakpoints (struct thread_info *thread)
 {
-  struct process_info *proc = get_thread_process (thread);
+  process_info *proc = thread->process ();
   struct breakpoint *bp, **bp_link;
 
   bp = proc->breakpoints;
@@ -1613,7 +1613,7 @@ reinsert_all_breakpoints (void)
 void
 reinsert_single_step_breakpoints (struct thread_info *thread)
 {
-  struct process_info *proc = get_thread_process (thread);
+  process_info *proc = thread->process ();
   struct breakpoint *bp;
 
   for (bp = proc->breakpoints; bp != NULL; bp = bp->next)
@@ -2138,8 +2138,8 @@ clone_all_breakpoints (struct thread_info *child_thread,
   struct breakpoint *new_bkpt;
   struct breakpoint *bkpt_tail = NULL;
   struct raw_breakpoint *raw_bkpt_tail = NULL;
-  struct process_info *child_proc = get_thread_process (child_thread);
-  struct process_info *parent_proc = get_thread_process (parent_thread);
+  process_info *child_proc = child_thread->process ();
+  process_info *parent_proc = parent_thread->process ();
   struct breakpoint **new_list = &child_proc->breakpoints;
   struct raw_breakpoint **new_raw_list = &child_proc->raw_breakpoints;
 
index 64b6e3176188191e0ce22f75194e5f44ed221bf3..a37a985dd30b984c63c0b4bbbf4e73b756819d79 100644 (file)
@@ -40,7 +40,7 @@ get_thread_regcache (struct thread_info *thread, int fetch)
      have.  */
   if (regcache == NULL)
     {
-      struct process_info *proc = get_thread_process (thread);
+      process_info *proc = thread->process ();
 
       gdb_assert (proc->tdesc != NULL);
 
index 291d62a61f1995126f038443ad99d125f034c4a0..138a8acc953bd4aad8452183f77b79eb5abb02d9 100644 (file)
@@ -1296,11 +1296,7 @@ handle_detach (char *own_buf)
       process = find_process_pid (pid);
     }
   else
-    {
-      process = (current_thread != nullptr
-                ? get_thread_process (current_thread)
-                : nullptr);
-    }
+    process = current_process ();
 
   if (process == NULL)
     {
@@ -1363,9 +1359,7 @@ handle_detach (char *own_buf)
       if (child == nullptr || kind == TARGET_WAITKIND_THREAD_CLONED)
        continue;
 
-      process_info *fork_child_process = get_thread_process (child);
-      gdb_assert (fork_child_process != nullptr);
-
+      process_info *fork_child_process = child->process ();
       int fork_child_pid = fork_child_process->pid;
 
       if (detach_inferior (fork_child_process) != 0)
index 8cef84206b8be2055d7785feb71ca6ee6113bcf6..96a9ced19ecbb5cb0debdbe7fd756543882bc373 100644 (file)
@@ -388,10 +388,9 @@ thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
   psaddr_t addr;
   td_err_e err;
   struct lwp_info *lwp;
-  struct process_info *proc;
   struct thread_db *thread_db;
+  process_info *proc = thread->process ();
 
-  proc = get_thread_process (thread);
   thread_db = proc->priv->thread_db;
 
   /* If the thread layer is not (yet) initialized, fail.  */
@@ -448,14 +447,13 @@ thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
 bool
 thread_db_thread_handle (ptid_t ptid, gdb_byte **handle, int *handle_len)
 {
-  struct thread_db *thread_db;
   struct lwp_info *lwp;
   thread_info *thread = find_thread_ptid (ptid);
 
   if (thread == NULL)
     return false;
 
-  thread_db = get_thread_process (thread)->priv->thread_db;
+  thread_db *thread_db = thread->process ()->priv->thread_db;
 
   if (thread_db == NULL)
     return false;
@@ -873,8 +871,7 @@ thread_db_handle_monitor_command (char *mon)
 void
 thread_db_notice_clone (struct thread_info *parent_thr, ptid_t child_ptid)
 {
-  process_info *parent_proc = get_thread_process (parent_thr);
-  struct thread_db *thread_db = parent_proc->priv->thread_db;
+  thread_db *thread_db = parent_thr->process ()->priv->thread_db;
 
   /* If the thread layer isn't initialized, return.  It may just
      be that the program uses clone, but does not use libthread_db.  */