[2/5] gdbserver: Use the PID of the current process instead of the current thread

Message ID 20230331034432.3037148-3-thiago.bauermann@linaro.org
State New
Headers
Series gdbserver: Follow-up on linux_get_auxv using PID parameter |

Commit Message

Thiago Jung Bauermann March 31, 2023, 3:44 a.m. UTC
  Commit 43e5fbd8b788 ("gdbserver: Add PID parameter to linux_get_auxv and
linux_get_hwcap") used current_thread->id.pid () to get the current
process' PID.  Pedro then mentioned that using current_process ()->pid is
more to the point.  He added that "sometimes there's a current process, but
not a current thread, so when we don't actually need a thread,
current_process() is better".

So this patch goes through the places that use current_thread to get the
current process' PID and changes them to use current_process () instead.

Suggested-by: Pedro Alves <pedro@palves.net>
---
 gdbserver/linux-aarch64-low.cc | 10 +++++-----
 gdbserver/linux-arm-low.cc     |  6 +++---
 gdbserver/linux-ppc-low.cc     |  6 +++---
 gdbserver/mem-break.cc         |  2 +-
 gdbserver/regcache.cc          |  2 +-
 gdbserver/server.cc            |  2 +-
 gdbserver/tracepoint.cc        |  2 +-
 gdbserver/win32-i386-low.cc    |  4 ++--
 8 files changed, 17 insertions(+), 17 deletions(-)
  

Patch

diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc
index 2ed6e95562c5..0c524c036d89 100644
--- a/gdbserver/linux-aarch64-low.cc
+++ b/gdbserver/linux-aarch64-low.cc
@@ -436,7 +436,7 @@  aarch64_target::low_insert_point (raw_bkpt_type type, CORE_ADDR addr,
   int ret;
   enum target_hw_bp_type targ_type;
   struct aarch64_debug_reg_state *state
-    = aarch64_get_debug_reg_state (pid_of (current_thread));
+    = aarch64_get_debug_reg_state (current_process ()->pid);
 
   if (show_debug_regs)
     fprintf (stderr, "insert_point on entry (addr=0x%08lx, len=%d)\n",
@@ -487,7 +487,7 @@  aarch64_target::low_remove_point (raw_bkpt_type type, CORE_ADDR addr,
   int ret;
   enum target_hw_bp_type targ_type;
   struct aarch64_debug_reg_state *state
-    = aarch64_get_debug_reg_state (pid_of (current_thread));
+    = aarch64_get_debug_reg_state (current_process ()->pid);
 
   if (show_debug_regs)
     fprintf (stderr, "remove_point on entry (addr=0x%08lx, len=%d)\n",
@@ -575,7 +575,7 @@  aarch64_target::low_stopped_data_address ()
     = aarch64_remove_non_address_bits ((CORE_ADDR) siginfo.si_addr);
 
   /* Check if the address matches any watched address.  */
-  state = aarch64_get_debug_reg_state (pid_of (current_thread));
+  state = aarch64_get_debug_reg_state (current_process ()->pid);
   for (i = aarch64_num_wp_regs - 1; i >= 0; --i)
     {
       const unsigned int offset
@@ -846,7 +846,7 @@  aarch64_target::low_arch_setup ()
   if (is_elf64)
     {
       struct aarch64_features features;
-      int pid = current_thread->id.pid ();
+      int pid = current_process ()->pid;
 
       features.vq = aarch64_sve_get_vq (tid);
       /* A-profile PAC is 64-bit only.  */
@@ -3323,7 +3323,7 @@  aarch64_target::supports_memory_tagging ()
 #endif
     }
 
-  return (linux_get_hwcap2 (current_thread->id.pid (), 8) & HWCAP2_MTE) != 0;
+  return (linux_get_hwcap2 (current_process ()->pid, 8) & HWCAP2_MTE) != 0;
 }
 
 bool
diff --git a/gdbserver/linux-arm-low.cc b/gdbserver/linux-arm-low.cc
index 5975b44af0ae..76d15baa8512 100644
--- a/gdbserver/linux-arm-low.cc
+++ b/gdbserver/linux-arm-low.cc
@@ -636,7 +636,7 @@  arm_target::low_insert_point (raw_bkpt_type type, CORE_ADDR addr,
 	pts[i] = p;
 
 	/* Only update the threads of the current process.  */
-	for_each_thread (current_thread->id.pid (), [&] (thread_info *thread)
+	for_each_thread (current_process ()->pid, [&] (thread_info *thread)
 	  {
 	    update_registers_callback (thread, watch, i);
 	  });
@@ -681,7 +681,7 @@  arm_target::low_remove_point (raw_bkpt_type type, CORE_ADDR addr,
 	pts[i].control = arm_hwbp_control_disable (pts[i].control);
 
 	/* Only update the threads of the current process.  */
-	for_each_thread (current_thread->id.pid (), [&] (thread_info *thread)
+	for_each_thread (current_process ()->pid, [&] (thread_info *thread)
 	  {
 	    update_registers_callback (thread, watch, i);
 	  });
@@ -958,7 +958,7 @@  get_next_pcs_syscall_next_pc (struct arm_get_next_pcs *self)
 static const struct target_desc *
 arm_read_description (void)
 {
-  unsigned long arm_hwcap = linux_get_hwcap (current_thread->id.pid (), 4);
+  unsigned long arm_hwcap = linux_get_hwcap (current_process ()->pid, 4);
 
   if (arm_hwcap & HWCAP_IWMMXT)
     return arm_linux_read_description (ARM_FP_TYPE_IWMMXT);
diff --git a/gdbserver/linux-ppc-low.cc b/gdbserver/linux-ppc-low.cc
index f8dd770b8eb3..fe44ba47992b 100644
--- a/gdbserver/linux-ppc-low.cc
+++ b/gdbserver/linux-ppc-low.cc
@@ -894,8 +894,8 @@  ppc_target::low_arch_setup ()
 
   /* The value of current_process ()->tdesc needs to be set for this
      call.  */
-  ppc_hwcap = linux_get_hwcap (current_thread->id.pid (), features.wordsize);
-  ppc_hwcap2 = linux_get_hwcap2 (current_thread->id.pid (), features.wordsize);
+  ppc_hwcap = linux_get_hwcap (current_process ()->pid, features.wordsize);
+  ppc_hwcap2 = linux_get_hwcap2 (current_process ()->pid, features.wordsize);
 
   features.isa205 = ppc_linux_has_isa205 (ppc_hwcap);
 
@@ -1097,7 +1097,7 @@  is_elfv2_inferior (void)
   const struct target_desc *tdesc = current_process ()->tdesc;
   int wordsize = register_size (tdesc, 0);
 
-  if (!linux_get_auxv (current_thread->id.pid (), wordsize, AT_PHDR, &phdr))
+  if (!linux_get_auxv (current_process ()->pid, wordsize, AT_PHDR, &phdr))
     return def_res;
 
   /* Assume ELF header is at the beginning of the page where program headers
diff --git a/gdbserver/mem-break.cc b/gdbserver/mem-break.cc
index c669842228d0..4cd7a3de093f 100644
--- a/gdbserver/mem-break.cc
+++ b/gdbserver/mem-break.cc
@@ -1392,7 +1392,7 @@  set_single_step_breakpoint (CORE_ADDR stop_at, ptid_t ptid)
 {
   struct single_step_breakpoint *bp;
 
-  gdb_assert (current_ptid.pid () == ptid.pid ());
+  gdb_assert (current_process ()->pid == ptid.pid ());
 
   bp = (struct single_step_breakpoint *) set_breakpoint_type_at (single_step_breakpoint,
 								stop_at, NULL);
diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 0b1141662ac6..15dda96965f1 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -106,7 +106,7 @@  void
 regcache_invalidate (void)
 {
   /* Only update the threads of the current process.  */
-  int pid = current_thread->id.pid ();
+  int pid = current_process ()->pid;
 
   regcache_invalidate_pid (pid);
 }
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index b6786baafadd..b6c23f280f86 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -1469,7 +1469,7 @@  handle_qxfer_exec_file (const char *annex,
       if (current_thread == NULL)
 	return -1;
 
-      pid = pid_of (current_thread);
+      pid = current_process ()->pid;
     }
   else
     {
diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc
index 3f60989e4c7f..590210260bf5 100644
--- a/gdbserver/tracepoint.cc
+++ b/gdbserver/tracepoint.cc
@@ -6813,7 +6813,7 @@  static int
 run_inferior_command (char *cmd, int len)
 {
   int err = -1;
-  int pid = current_ptid.pid ();
+  int pid = current_process ()->pid;
 
   trace_debug ("run_inferior_command: running: %s", cmd);
 
diff --git a/gdbserver/win32-i386-low.cc b/gdbserver/win32-i386-low.cc
index f78e01206785..af96b464681b 100644
--- a/gdbserver/win32-i386-low.cc
+++ b/gdbserver/win32-i386-low.cc
@@ -57,7 +57,7 @@  x86_dr_low_set_addr (int regnum, CORE_ADDR addr)
   gdb_assert (DR_FIRSTADDR <= regnum && regnum <= DR_LASTADDR);
 
   /* Only update the threads of this process.  */
-  for_each_thread (current_thread->id.pid (), update_debug_registers);
+  for_each_thread (current_process ()->pid, update_debug_registers);
 }
 
 /* Update the inferior's DR7 debug control register from STATE.  */
@@ -66,7 +66,7 @@  static void
 x86_dr_low_set_control (unsigned long control)
 {
   /* Only update the threads of this process.  */
-  for_each_thread (current_thread->id.pid (), update_debug_registers);
+  for_each_thread (current_process ()->pid, update_debug_registers);
 }
 
 /* Return the current value of a DR register of the current thread's