[29/31] gdbserver/linux-low: turn 'get_syscall_trapinfo' into a method

Message ID ad7ec73520e9506f4f3c1da7c15c6834109a6223.1583529167.git.tankut.baris.aktemur@intel.com
State New, archived
Headers

Commit Message

Tankut Baris Aktemur March 6, 2020, 9:31 p.m. UTC
  gdbserver/ChangeLog:
2020-03-06  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Turn the 'get_syscall_trapinfo' linux target op into a method
	of process_stratum_target.

	* linux-low.h (struct linux_target_ops): Remove the op.
	(class linux_process_target) <get_syscall_trapinfo>
	<gdb_catch_this_syscall>
	<low_supports_catch_syscall>
	<low_get_syscall_trapinfo>: Declare.
	* linux-low.cc (get_syscall_trapinfo): Turn into...
	(linux_process_target::get_syscall_trapinfo): ...this.
	(linux_process_target::low_get_syscall_trapinfo): Define.
	(gdb_catch_this_syscall_p): Turn into...
	(linux_process_target::gdb_catch_this_syscall): ...this.
	(linux_process_target::low_supports_catch_syscall): Define.

	Update the callers below.

	(linux_process_target::wait_1)
	(linux_process_target::supports_catch_syscall)

	* linux-x86-low.cc (class x86_target) <low_supports_catch_syscall>
	<low_get_syscall_trapinfo>: Declare.
	(x86_target::low_supports_catch_syscall): Define.
	(x86_get_syscall_trapinfo): Turn into...
	(x86_target::low_get_syscall_trapinfo): ...this.
	(the_low_target): Remove the op field.
	* linux-aarch64-low.cc (class aarch64_target)
	<low_supports_catch_syscall>
	<low_get_syscall_trapinfo>: Declare.
	(aarch64_target::low_supports_catch_syscall): Define.
	(aarch64_get_syscall_trapinfo): Turn into...
	(aarch64_target::low_get_syscall_trapinfo): ...this.
	(the_low_target): Remove the op field.
	* linux-arm-low.cc (class arm_target) <low_supports_catch_syscall>
	<low_get_syscall_trapinfo>: Declare.
	(arm_target::low_supports_catch_syscall): Define.
	(arm_get_syscall_trapinfo): Turn into...
	(arm_target::low_get_syscall_trapinfo): ...this.
	(the_low_target): Remove the op field.
	* linux-ppc-low.cc (the_low_target): Remove the op field.
	* linux-s390-low.cc (the_low_target): Remove the op field.
---
 gdbserver/linux-aarch64-low.cc | 17 +++++++++---
 gdbserver/linux-arm-low.cc     | 19 +++++++++----
 gdbserver/linux-low.cc         | 49 +++++++++++++++++-----------------
 gdbserver/linux-low.h          | 20 +++++++++++---
 gdbserver/linux-ppc-low.cc     |  1 -
 gdbserver/linux-s390-low.cc    |  1 -
 gdbserver/linux-x86-low.cc     | 15 ++++++++---
 7 files changed, 79 insertions(+), 43 deletions(-)
  

Patch

diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc
index c6d2131f2f4..68ea95d6d36 100644
--- a/gdbserver/linux-aarch64-low.cc
+++ b/gdbserver/linux-aarch64-low.cc
@@ -126,6 +126,10 @@  protected:
   int low_get_thread_area (int lwpid, CORE_ADDR *addrp) override;
 
   bool low_supports_range_stepping () override;
+
+  bool low_supports_catch_syscall () override;
+
+  void low_get_syscall_trapinfo (regcache *regcache, int *sysno) override;
 };
 
 /* The singleton target ops object.  */
@@ -769,10 +773,16 @@  aarch64_target::low_get_thread_area (int lwpid, CORE_ADDR *addrp)
   return 0;
 }
 
-/* Implementation of linux_target_ops method "get_syscall_trapinfo".  */
+bool
+aarch64_target::low_supports_catch_syscall ()
+{
+  return true;
+}
 
-static void
-aarch64_get_syscall_trapinfo (struct regcache *regcache, int *sysno)
+/* Implementation of linux target ops method "low_get_syscall_trapinfo".  */
+
+void
+aarch64_target::low_get_syscall_trapinfo (regcache *regcache, int *sysno)
 {
   int use_64bit = register_size (regcache->tdesc, 0) == 8;
 
@@ -3160,7 +3170,6 @@  aarch64_target::breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
 
 struct linux_target_ops the_low_target =
 {
-  aarch64_get_syscall_trapinfo,
 };
 
 /* The linux target ops object.  */
diff --git a/gdbserver/linux-arm-low.cc b/gdbserver/linux-arm-low.cc
index 7febaa675dd..d8d57b44954 100644
--- a/gdbserver/linux-arm-low.cc
+++ b/gdbserver/linux-arm-low.cc
@@ -115,6 +115,10 @@  protected:
   void low_new_fork (process_info *parent, process_info *child) override;
 
   void low_prepare_to_resume (lwp_info *lwp) override;
+
+  bool low_supports_catch_syscall () override;
+
+  void low_get_syscall_trapinfo (regcache *regcache, int *sysno) override;
 };
 
 /* The singleton target ops object.  */
@@ -1040,10 +1044,16 @@  arm_target::supports_hardware_single_step ()
   return false;
 }
 
-/* Implementation of linux_target_ops method "get_syscall_trapinfo".  */
+bool
+arm_target::low_supports_catch_syscall ()
+{
+  return true;
+}
 
-static void
-arm_get_syscall_trapinfo (struct regcache *regcache, int *sysno)
+/* Implementation of linux target ops method "low_get_syscall_trapinfo".  */
+
+void
+arm_target::low_get_syscall_trapinfo (regcache *regcache, int *sysno)
 {
   if (arm_is_thumb_mode ())
     collect_register_by_name (regcache, "r7", sysno);
@@ -1054,7 +1064,7 @@  arm_get_syscall_trapinfo (struct regcache *regcache, int *sysno)
 
       collect_register_by_name (regcache, "pc", &pc);
 
-      if (the_target->read_memory (pc - 4, (unsigned char *) &insn, 4))
+      if (read_memory (pc - 4, (unsigned char *) &insn, 4))
 	*sysno = UNKNOWN_SYSCALL;
       else
 	{
@@ -1121,7 +1131,6 @@  arm_target::get_regs_info ()
 }
 
 struct linux_target_ops the_low_target = {
-  arm_get_syscall_trapinfo,
 };
 
 /* The linux target ops object.  */
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index 9850d25d979..25f895f7acf 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -754,28 +754,17 @@  linux_process_target::get_pc (lwp_info *lwp)
   return pc;
 }
 
-/* This function should only be called if LWP got a SYSCALL_SIGTRAP.
-   Fill *SYSNO with the syscall nr trapped.  */
-
-static void
-get_syscall_trapinfo (struct lwp_info *lwp, int *sysno)
+void
+linux_process_target::get_syscall_trapinfo (lwp_info *lwp, int *sysno)
 {
   struct thread_info *saved_thread;
   struct regcache *regcache;
 
-  if (the_low_target.get_syscall_trapinfo == NULL)
-    {
-      /* If we cannot get the syscall trapinfo, report an unknown
-	 system call number.  */
-      *sysno = UNKNOWN_SYSCALL;
-      return;
-    }
-
   saved_thread = current_thread;
   current_thread = get_lwp_thread (lwp);
 
   regcache = get_thread_regcache (current_thread, 1);
-  (*the_low_target.get_syscall_trapinfo) (regcache, sysno);
+  low_get_syscall_trapinfo (regcache, sysno);
 
   if (debug_threads)
     debug_printf ("get_syscall_trapinfo sysno %d\n", *sysno);
@@ -783,6 +772,13 @@  get_syscall_trapinfo (struct lwp_info *lwp, int *sysno)
   current_thread = saved_thread;
 }
 
+void
+linux_process_target::low_get_syscall_trapinfo (regcache *regcache, int *sysno)
+{
+  /* By default, report an unknown system call number.  */
+  *sysno = UNKNOWN_SYSCALL;
+}
+
 bool
 linux_process_target::save_stop_reason (lwp_info *lwp)
 {
@@ -2961,29 +2957,26 @@  gdb_catching_syscalls_p (struct lwp_info *event_child)
   return !proc->syscalls_to_catch.empty ();
 }
 
-/* Returns 1 if GDB is interested in the event_child syscall.
-   Only to be called when stopped reason is SYSCALL_SIGTRAP.  */
-
-static int
-gdb_catch_this_syscall_p (struct lwp_info *event_child)
+bool
+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);
 
   if (proc->syscalls_to_catch.empty ())
-    return 0;
+    return false;
 
   if (proc->syscalls_to_catch[0] == ANY_SYSCALL)
-    return 1;
+    return true;
 
   get_syscall_trapinfo (event_child, &sysno);
 
   for (int iter : proc->syscalls_to_catch)
     if (iter == sysno)
-      return 1;
+      return true;
 
-  return 0;
+  return false;
 }
 
 ptid_t
@@ -3326,7 +3319,7 @@  linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus,
   /* Check if GDB is interested in this syscall.  */
   if (WIFSTOPPED (w)
       && WSTOPSIG (w) == SYSCALL_SIGTRAP
-      && !gdb_catch_this_syscall_p (event_child))
+      && !gdb_catch_this_syscall (event_child))
     {
       if (debug_threads)
 	{
@@ -6404,10 +6397,16 @@  linux_process_target::read_loadmap (const char *annex, CORE_ADDR offset,
 bool
 linux_process_target::supports_catch_syscall ()
 {
-  return (the_low_target.get_syscall_trapinfo != NULL
+  return (low_supports_catch_syscall ()
 	  && linux_supports_tracesysgood ());
 }
 
+bool
+linux_process_target::low_supports_catch_syscall ()
+{
+  return false;
+}
+
 int
 linux_process_target::get_ipa_tdesc_idx ()
 {
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 9965f2ce04e..0ecdd06452e 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -131,10 +131,6 @@  struct lwp_info;
 
 struct linux_target_ops
 {
-  /* Fill *SYSNO with the syscall nr trapped.  Only to be called when
-     inferior is stopped due to SYSCALL_SIGTRAP.  */
-  void (*get_syscall_trapinfo) (struct regcache *regcache, int *sysno);
-
   /* See target.h.  */
   int (*get_ipa_tdesc_idx) (void);
 };
@@ -593,6 +589,14 @@  class linux_process_target : public process_stratum_target
   fast_tpoint_collect_result linux_fast_tracepoint_collecting
     (lwp_info *lwp, fast_tpoint_collect_status *status);
 
+  /* This function should only be called if LWP got a SYSCALL_SIGTRAP.
+     Fill *SYSNO with the syscall nr trapped.  */
+  void get_syscall_trapinfo (lwp_info *lwp, int *sysno);
+
+  /* Returns true if GDB is interested in the event_child syscall.
+     Only to be called when stopped reason is SYSCALL_SIGTRAP.  */
+  bool gdb_catch_this_syscall (lwp_info *event_child);
+
 protected:
   /* The architecture-specific "low" methods are listed below.  */
 
@@ -686,6 +690,14 @@  class linux_process_target : public process_stratum_target
   /* Returns true if the low target supports range stepping.  */
   virtual bool low_supports_range_stepping ();
 
+  /* Return true if the target supports catch syscall.  Such targets
+     override the low_get_syscall_trapinfo method below.  */
+  virtual bool low_supports_catch_syscall ();
+
+  /* Fill *SYSNO with the syscall nr trapped.  Only to be called when
+     inferior is stopped due to SYSCALL_SIGTRAP.  */
+  virtual void low_get_syscall_trapinfo (regcache *regcache, int *sysno);
+
   /* How many bytes the PC should be decremented after a break.  */
   int m_decr_pc_after_break;
 };
diff --git a/gdbserver/linux-ppc-low.cc b/gdbserver/linux-ppc-low.cc
index 1dc60ecdbef..1431b74031f 100644
--- a/gdbserver/linux-ppc-low.cc
+++ b/gdbserver/linux-ppc-low.cc
@@ -3448,7 +3448,6 @@  ppc_get_ipa_tdesc_idx (void)
 }
 
 struct linux_target_ops the_low_target = {
-  NULL, /* get_syscall_trapinfo */
   ppc_get_ipa_tdesc_idx,
 };
 
diff --git a/gdbserver/linux-s390-low.cc b/gdbserver/linux-s390-low.cc
index d7f18ccf212..b44a3b9942f 100644
--- a/gdbserver/linux-s390-low.cc
+++ b/gdbserver/linux-s390-low.cc
@@ -2849,7 +2849,6 @@  s390_target::emit_ops ()
 }
 
 struct linux_target_ops the_low_target = {
-  NULL, /* get_syscall_trapinfo */
   s390_get_ipa_tdesc_idx,
 };
 
diff --git a/gdbserver/linux-x86-low.cc b/gdbserver/linux-x86-low.cc
index 328517022dd..efffb9c7d30 100644
--- a/gdbserver/linux-x86-low.cc
+++ b/gdbserver/linux-x86-low.cc
@@ -176,6 +176,10 @@  protected:
 
   bool low_supports_range_stepping () override;
 
+  bool low_supports_catch_syscall () override;
+
+  void low_get_syscall_trapinfo (regcache *regcache, int *sysno) override;
+
 private:
 
   /* Update all the target description of all processes; a new GDB
@@ -1103,11 +1107,17 @@  x86_target::low_arch_setup ()
   current_process ()->tdesc = x86_linux_read_description ();
 }
 
+bool
+x86_target::low_supports_catch_syscall ()
+{
+  return true;
+}
+
 /* Fill *SYSNO and *SYSRET with the syscall nr trapped and the syscall return
    code.  This should only be called if LWP got a SYSCALL_SIGTRAP.  */
 
-static void
-x86_get_syscall_trapinfo (struct regcache *regcache, int *sysno)
+void
+x86_target::low_get_syscall_trapinfo (regcache *regcache, int *sysno)
 {
   int use_64bit = register_size (regcache->tdesc, 0) == 8;
 
@@ -2978,7 +2988,6 @@  x86_get_ipa_tdesc_idx (void)
 
 struct linux_target_ops the_low_target =
 {
-  x86_get_syscall_trapinfo,
   x86_get_ipa_tdesc_idx,
 };