public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/4] Probe catch syscall support
  2016-06-17 10:16 [PATCH 0/4] Tweak catch syscall for remote Yao Qi
  2016-06-17 10:16 ` [PATCH 4/4] Implement get_syscall_trapinfo for arm-linux Yao Qi
  2016-06-17 10:16 ` [PATCH 2/4] Remove parameter sysret from linux_target_ops.get_syscall_trapinfo Yao Qi
@ 2016-06-17 10:16 ` Yao Qi
  2016-06-17 10:16 ` [PATCH 3/4] Implement get_syscall_trapinfo for aarch64-linux Yao Qi
  2016-06-23 15:11 ` [PATCH 0/4] Tweak catch syscall for remote Pedro Alves
  4 siblings, 0 replies; 7+ messages in thread
From: Yao Qi @ 2016-06-17 10:16 UTC (permalink / raw)
  To: gdb-patches

In 82075af2c14b1f8a54fa5796fb63f7ef23f98d9d (Implement 'catch syscall'
for gdbserver), only x86 is supported, but the test can still be run
on other linux targets, like aarch64 and ppc, with native-gdbserver.
This causes many new fails.

This patch removes the check on isnative and on target triplets.
Instead, we can insert catch point, and resume the program to see whether
catch syscall is supported or not.

gdb/testsuite:

2016-06-16  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/catch-syscall.exp: Remove check on isnative and target
	triplets.  Start gdb, execute catch syscall, and continue.  Check
	gdb's output to determine catch syscall is supported.
---
 gdb/testsuite/gdb.base/catch-syscall.exp | 43 +++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp
index 5679000..f3ab6cb 100644
--- a/gdb/testsuite/gdb.base/catch-syscall.exp
+++ b/gdb/testsuite/gdb.base/catch-syscall.exp
@@ -19,20 +19,6 @@
 # It was written by Sergio Durigan Junior <sergiodj@linux.vnet.ibm.com>
 # on September/2008.
 
-if { ![isnative] } then {
-    continue
-}
-
-# This shall be updated whenever 'catch syscall' is implemented
-# on some architecture.
-if { ![istarget "x86_64-*-linux*"] && ![istarget "i\[34567\]86-*-linux*"]
-     && ![istarget "powerpc-*-linux*"] && ![istarget "powerpc64-*-linux*"]
-     && ![istarget "sparc-*-linux*"] && ![istarget "sparc64-*-linux*"]
-     && ![istarget "mips*-linux*"] && ![istarget "arm*-linux*"]
-     && ![istarget "s390*-linux*"] && ![istarget "aarch64*-*-linux*"] } {
-     continue
-}
-
 standard_testfile
 
 if  { [prepare_for_testing ${testfile}.exp $testfile ${testfile}.c] } {
@@ -40,6 +26,35 @@ if  { [prepare_for_testing ${testfile}.exp $testfile ${testfile}.c] } {
      return -1
 }
 
+# Check target supports catch syscall or not.
+clean_restart $binfile
+if ![runto_main] then {
+    fail "Can't run to main"
+    return
+}
+
+set test "catch syscall"
+gdb_test_multiple $test $test {
+    -re "The feature \'catch syscall\' is not supported.*\r\n$gdb_prompt $" {
+	unsupported "catch syscall isn't supported"
+	return -1
+    }
+    -re ".*$gdb_prompt $" {
+	pass $test
+    }
+}
+
+set test "check catch syscall"
+gdb_test_multiple "continue" $test {
+    -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
+	unsupported "catch syscall isn't supported"
+	return -1
+    }
+    -re ".*Catchpoint.*$gdb_prompt $" {
+      pass $test
+    }
+}
+
 # All (but the last) syscalls from the example code.  It is filled in
 # proc setup_all_syscalls.
 set all_syscalls { }
-- 
1.9.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/4] Remove parameter sysret from linux_target_ops.get_syscall_trapinfo
  2016-06-17 10:16 [PATCH 0/4] Tweak catch syscall for remote Yao Qi
  2016-06-17 10:16 ` [PATCH 4/4] Implement get_syscall_trapinfo for arm-linux Yao Qi
@ 2016-06-17 10:16 ` Yao Qi
  2016-06-17 10:16 ` [PATCH 1/4] Probe catch syscall support Yao Qi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Yao Qi @ 2016-06-17 10:16 UTC (permalink / raw)
  To: gdb-patches

When I implement linux_target_ops.get_syscall_trapinfo for aarch64 and arm,
I find the second parameter sysret isn't used at all.  In RSP, we don't
need syscall return value either, because GDB can figure out the return
value from registers content got by 'g' packet.

This patch is to remove them.

gdb/gdbserver:

2016-06-16  Yao Qi  <yao.qi@linaro.org>

	* linux-low.c (get_syscall_trapinfo): Remove parameter sysret.
	Callers updated.
	* linux-low.h (struct linux_target_ops) <get_syscall_trapinfo>:
	Remove parameter sysno.
	* linux-x86-low.c (x86_get_syscall_trapinfo): Remove parameter
	sysret.
---
 gdb/gdbserver/linux-low.c     | 23 ++++++++---------------
 gdb/gdbserver/linux-low.h     |  8 +++-----
 gdb/gdbserver/linux-x86-low.c | 10 ++--------
 3 files changed, 13 insertions(+), 28 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index dd92e78..0f4bb87 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -758,11 +758,10 @@ get_pc (struct lwp_info *lwp)
 }
 
 /* This function should only be called if LWP got a SYSCALL_SIGTRAP.
-   Fill *SYSNO with the syscall nr trapped.  Fill *SYSRET with the
-   return code.  */
+   Fill *SYSNO with the syscall nr trapped.  */
 
 static void
-get_syscall_trapinfo (struct lwp_info *lwp, int *sysno, int *sysret)
+get_syscall_trapinfo (struct lwp_info *lwp, int *sysno)
 {
   struct thread_info *saved_thread;
   struct regcache *regcache;
@@ -770,9 +769,8 @@ get_syscall_trapinfo (struct lwp_info *lwp, int *sysno, int *sysret)
   if (the_low_target.get_syscall_trapinfo == NULL)
     {
       /* If we cannot get the syscall trapinfo, report an unknown
-	 system call number and -ENOSYS return value.  */
+	 system call number.  */
       *sysno = UNKNOWN_SYSCALL;
-      *sysret = -ENOSYS;
       return;
     }
 
@@ -780,13 +778,10 @@ get_syscall_trapinfo (struct lwp_info *lwp, int *sysno, int *sysret)
   current_thread = get_lwp_thread (lwp);
 
   regcache = get_thread_regcache (current_thread, 1);
-  (*the_low_target.get_syscall_trapinfo) (regcache, sysno, sysret);
+  (*the_low_target.get_syscall_trapinfo) (regcache, sysno);
 
   if (debug_threads)
-    {
-      debug_printf ("get_syscall_trapinfo sysno %d sysret %d\n",
-		    *sysno, *sysret);
-    }
+    debug_printf ("get_syscall_trapinfo sysno %d\n", *sysno);
 
   current_thread = saved_thread;
 }
@@ -3116,7 +3111,7 @@ static int
 gdb_catch_this_syscall_p (struct lwp_info *event_child)
 {
   int i, iter;
-  int sysno, sysret;
+  int sysno;
   struct thread_info *thread = get_lwp_thread (event_child);
   struct process_info *proc = get_thread_process (thread);
 
@@ -3126,7 +3121,7 @@ gdb_catch_this_syscall_p (struct lwp_info *event_child)
   if (VEC_index (int, proc->syscalls_to_catch, 0) == ANY_SYSCALL)
     return 1;
 
-  get_syscall_trapinfo (event_child, &sysno, &sysret);
+  get_syscall_trapinfo (event_child, &sysno);
   for (i = 0;
        VEC_iterate (int, proc->syscalls_to_catch, i, iter);
        i++)
@@ -3734,10 +3729,8 @@ linux_wait_1 (ptid_t ptid,
 
   if (WSTOPSIG (w) == SYSCALL_SIGTRAP)
     {
-      int sysret;
-
       get_syscall_trapinfo (event_child,
-			    &ourstatus->value.syscall_number, &sysret);
+			    &ourstatus->value.syscall_number);
       ourstatus->kind = event_child->syscall_state;
     }
   else if (current_thread->last_resume_kind == resume_stop
diff --git a/gdb/gdbserver/linux-low.h b/gdb/gdbserver/linux-low.h
index 6e7ddbd..5057e66 100644
--- a/gdb/gdbserver/linux-low.h
+++ b/gdb/gdbserver/linux-low.h
@@ -241,11 +241,9 @@ struct linux_target_ops
   /* See target.h.  */
   int (*supports_hardware_single_step) (void);
 
-  /* Fill *SYSNO with the syscall nr trapped.  Fill *SYSRET with the
-     return code.  Only to be called when inferior is stopped
-     due to SYSCALL_SIGTRAP.  */
-  void (*get_syscall_trapinfo) (struct regcache *regcache,
-				int *sysno, int *sysret);
+  /* 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);
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index 2535959..5080dec 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -991,25 +991,19 @@ x86_arch_setup (void)
    code.  This should only be called if LWP got a SYSCALL_SIGTRAP.  */
 
 static void
-x86_get_syscall_trapinfo (struct regcache *regcache, int *sysno, int *sysret)
+x86_get_syscall_trapinfo (struct regcache *regcache, int *sysno)
 {
   int use_64bit = register_size (regcache->tdesc, 0) == 8;
 
   if (use_64bit)
     {
       long l_sysno;
-      long l_sysret;
 
       collect_register_by_name (regcache, "orig_rax", &l_sysno);
-      collect_register_by_name (regcache, "rax", &l_sysret);
       *sysno = (int) l_sysno;
-      *sysret = (int) l_sysret;
     }
   else
-    {
-      collect_register_by_name (regcache, "orig_eax", sysno);
-      collect_register_by_name (regcache, "eax", sysret);
-    }
+    collect_register_by_name (regcache, "orig_eax", sysno);
 }
 
 static int
-- 
1.9.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/4] Implement get_syscall_trapinfo for aarch64-linux
  2016-06-17 10:16 [PATCH 0/4] Tweak catch syscall for remote Yao Qi
                   ` (2 preceding siblings ...)
  2016-06-17 10:16 ` [PATCH 1/4] Probe catch syscall support Yao Qi
@ 2016-06-17 10:16 ` Yao Qi
  2016-06-23 15:11 ` [PATCH 0/4] Tweak catch syscall for remote Pedro Alves
  4 siblings, 0 replies; 7+ messages in thread
From: Yao Qi @ 2016-06-17 10:16 UTC (permalink / raw)
  To: gdb-patches

gdb/gdbserver:

2016-06-16  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_get_syscall_trapinfo): New
	function.
	(the_low_target): Install aarch64_get_syscall_trapinfo.
---
 gdb/gdbserver/linux-aarch64-low.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
index d237bde..7ac68dd 100644
--- a/gdb/gdbserver/linux-aarch64-low.c
+++ b/gdb/gdbserver/linux-aarch64-low.c
@@ -570,6 +570,24 @@ aarch64_get_thread_area (int lwpid, CORE_ADDR *addrp)
   return 0;
 }
 
+/* Implementation of linux_target_ops method "get_syscall_trapinfo".  */
+
+static void
+aarch64_get_syscall_trapinfo (struct regcache *regcache, int *sysno)
+{
+  int use_64bit = register_size (regcache->tdesc, 0) == 8;
+
+  if (use_64bit)
+    {
+      long l_sysno;
+
+      collect_register_by_name (regcache, "x8", &l_sysno);
+      *sysno = (int) l_sysno;
+    }
+  else
+    collect_register_by_name (regcache, "r7", sysno);
+}
+
 /* List of condition codes that we need.  */
 
 enum aarch64_condition_codes
@@ -2984,6 +3002,7 @@ struct linux_target_ops the_low_target =
   aarch64_supports_range_stepping,
   aarch64_breakpoint_kind_from_current_state,
   aarch64_supports_hardware_single_step,
+  aarch64_get_syscall_trapinfo,
 };
 
 void
-- 
1.9.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/4] Implement get_syscall_trapinfo for arm-linux
  2016-06-17 10:16 [PATCH 0/4] Tweak catch syscall for remote Yao Qi
@ 2016-06-17 10:16 ` Yao Qi
  2016-06-17 10:16 ` [PATCH 2/4] Remove parameter sysret from linux_target_ops.get_syscall_trapinfo Yao Qi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Yao Qi @ 2016-06-17 10:16 UTC (permalink / raw)
  To: gdb-patches

gdb/gdbserver:

2016-06-16  Yao Qi  <yao.qi@linaro.org>

	* linux-arm-low.c (arm_get_syscall_trapinfo): New function.
	(the_low_target): Install arm_get_syscall_trapinfo.
---
 gdb/gdbserver/linux-arm-low.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/gdb/gdbserver/linux-arm-low.c b/gdb/gdbserver/linux-arm-low.c
index 2ffda87..67d1bbf 100644
--- a/gdb/gdbserver/linux-arm-low.c
+++ b/gdb/gdbserver/linux-arm-low.c
@@ -951,6 +951,36 @@ arm_supports_hardware_single_step (void)
   return 0;
 }
 
+/* Implementation of linux_target_ops method "get_syscall_trapinfo".  */
+
+static void
+arm_get_syscall_trapinfo (struct regcache *regcache, int *sysno)
+{
+  if (arm_is_thumb_mode ())
+    collect_register_by_name (regcache, "r7", sysno);
+  else
+    {
+      unsigned long pc;
+      unsigned long insn;
+      unsigned long svc_operand;
+
+      collect_register_by_name (regcache, "pc", &pc);
+      (*the_target->read_memory) (pc - 4, (unsigned char *) &insn, 4);
+      svc_operand = (0x00ffffff & insn);
+
+      if (svc_operand)
+	{
+	  /* OABI */
+	  *sysno = svc_operand - 0x900000;
+	}
+      else
+	{
+	  /* EABI */
+	  collect_register_by_name (regcache, "r7", sysno);
+	}
+    }
+}
+
 /* Register sets without using PTRACE_GETREGSET.  */
 
 static struct regset_info arm_regsets[] = {
@@ -1031,7 +1061,8 @@ struct linux_target_ops the_low_target = {
   NULL, /* get_min_fast_tracepoint_insn_len */
   NULL, /* supports_range_stepping */
   arm_breakpoint_kind_from_current_state,
-  arm_supports_hardware_single_step
+  arm_supports_hardware_single_step,
+  arm_get_syscall_trapinfo,
 };
 
 void
-- 
1.9.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 0/4] Tweak catch syscall for remote
@ 2016-06-17 10:16 Yao Qi
  2016-06-17 10:16 ` [PATCH 4/4] Implement get_syscall_trapinfo for arm-linux Yao Qi
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Yao Qi @ 2016-06-17 10:16 UTC (permalink / raw)
  To: gdb-patches

I see some test fails in catch-syscall.exp on aarch64 with
native-gdbserver.  This patch series add catch syscall in remote for
both aarch64-linux and arm-linux.

Currently, only catch syscall for remote is only supported on x86, but
the test is run on other targets.  Patch 1 fixes the issue in
catch-sysca.exp about probing the catch syscall support.

Patch 2 removes one redundant parameter in
linux_target_ops.get_syscall_trapinfo.  Patch 3 and 4 adds support for
aarch64-linux and arm-linux respectively.

*** BLURB HERE ***

Yao Qi (4):
  Probe catch syscall support
  Remove parameter sysret from linux_target_ops.get_syscall_trapinfo
  Implement get_syscall_trapinfo for aarch64-linux
  Implement get_syscall_trapinfo for arm-linux

 gdb/gdbserver/linux-aarch64-low.c        | 19 ++++++++++++++
 gdb/gdbserver/linux-arm-low.c            | 33 +++++++++++++++++++++++-
 gdb/gdbserver/linux-low.c                | 23 ++++++-----------
 gdb/gdbserver/linux-low.h                |  8 +++---
 gdb/gdbserver/linux-x86-low.c            | 10 ++------
 gdb/testsuite/gdb.base/catch-syscall.exp | 43 +++++++++++++++++++++-----------
 6 files changed, 93 insertions(+), 43 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] Tweak catch syscall for remote
  2016-06-17 10:16 [PATCH 0/4] Tweak catch syscall for remote Yao Qi
                   ` (3 preceding siblings ...)
  2016-06-17 10:16 ` [PATCH 3/4] Implement get_syscall_trapinfo for aarch64-linux Yao Qi
@ 2016-06-23 15:11 ` Pedro Alves
  2016-06-28 14:17   ` Yao Qi
  4 siblings, 1 reply; 7+ messages in thread
From: Pedro Alves @ 2016-06-23 15:11 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 06/17/2016 11:16 AM, Yao Qi wrote:
> I see some test fails in catch-syscall.exp on aarch64 with
> native-gdbserver.  This patch series add catch syscall in remote for
> both aarch64-linux and arm-linux.
> 
> Currently, only catch syscall for remote is only supported on x86, but
> the test is run on other targets.  Patch 1 fixes the issue in
> catch-sysca.exp about probing the catch syscall support.
> 
> Patch 2 removes one redundant parameter in
> linux_target_ops.get_syscall_trapinfo.  Patch 3 and 4 adds support for
> aarch64-linux and arm-linux respectively.
> 

LGTM.  Might want to handle read_memory failing in patch 4, as it
leaves "insn" undefined if that happens.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] Tweak catch syscall for remote
  2016-06-23 15:11 ` [PATCH 0/4] Tweak catch syscall for remote Pedro Alves
@ 2016-06-28 14:17   ` Yao Qi
  0 siblings, 0 replies; 7+ messages in thread
From: Yao Qi @ 2016-06-28 14:17 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Thu, Jun 23, 2016 at 4:10 PM, Pedro Alves <palves@redhat.com> wrote:
> LGTM.  Might want to handle read_memory failing in patch 4, as it
> leaves "insn" undefined if that happens.
>

OK, I updated patch 4 to set *sysno to UNKNOWN_SYSCALL if read_memory
fails.  Patches are pushed in.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-06-28 14:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-17 10:16 [PATCH 0/4] Tweak catch syscall for remote Yao Qi
2016-06-17 10:16 ` [PATCH 4/4] Implement get_syscall_trapinfo for arm-linux Yao Qi
2016-06-17 10:16 ` [PATCH 2/4] Remove parameter sysret from linux_target_ops.get_syscall_trapinfo Yao Qi
2016-06-17 10:16 ` [PATCH 1/4] Probe catch syscall support Yao Qi
2016-06-17 10:16 ` [PATCH 3/4] Implement get_syscall_trapinfo for aarch64-linux Yao Qi
2016-06-23 15:11 ` [PATCH 0/4] Tweak catch syscall for remote Pedro Alves
2016-06-28 14:17   ` Yao Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).