public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/7] New test case gdb.trace/signal.exp
Date: Wed, 23 Mar 2016 16:10:00 -0000	[thread overview]
Message-ID: <1458749384-19793-2-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1458749384-19793-1-git-send-email-yao.qi@linaro.org>

This is to test whether GDBserver deliver signal to the inferior while
doing the step over.  Nowadays, GDBserver doesn't deliver signal, so
there won't be spurious collection, however, if GDBserver does deliver
signal, there might be spurious collections.

gdb/testsuite:

2016-03-23  Yao Qi  <yao.qi@linaro.org>

	* gdb.trace/signal.c: New file.
	* gdb.trace/signal.exp: New file.
---
 gdb/testsuite/gdb.trace/signal.c   |  68 +++++++++++++++
 gdb/testsuite/gdb.trace/signal.exp | 172 +++++++++++++++++++++++++++++++++++++
 2 files changed, 240 insertions(+)
 create mode 100644 gdb/testsuite/gdb.trace/signal.c
 create mode 100644 gdb/testsuite/gdb.trace/signal.exp

diff --git a/gdb/testsuite/gdb.trace/signal.c b/gdb/testsuite/gdb.trace/signal.c
new file mode 100644
index 0000000..b2b976d
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/signal.c
@@ -0,0 +1,68 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2016 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <signal.h>
+#include <string.h>
+#include <stdio.h>
+
+static int counter = 0;
+
+static void
+handler (int sig)
+{
+  counter++;
+}
+
+static int iterations = 3;
+
+static void
+start (int pid)
+{
+  int i;
+
+  for (i = 0; i < iterations; i++)
+    {
+      kill (pid, SIGABRT);
+    }
+}
+
+static void
+end (void)
+{}
+
+int
+main (void)
+{
+  struct sigaction act;
+  int i;
+
+  memset (&act, 0, sizeof act);
+  act.sa_handler = handler;
+  act.sa_flags = SA_NODEFER;
+  sigaction (SIGABRT, &act, NULL);
+
+  for (i = 0; i < 3; i++)
+    {
+      kill (getpid (), SIGABRT);
+    }
+
+  counter = 0;
+  start (getpid ());
+
+  end ();
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.trace/signal.exp b/gdb/testsuite/gdb.trace/signal.exp
new file mode 100644
index 0000000..85898c3
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/signal.exp
@@ -0,0 +1,172 @@
+#   Copyright 2016 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+set syscall_insn ""
+
+# Define the syscall instruction for each target.
+
+if { [istarget "i\[34567\]86-*-linux*"] || [istarget "x86_64-*-linux*"] } {
+    set syscall_insn "\[ \t\](int|syscall|sysenter)\[ \t\]"
+} elseif { [istarget "aarch64*-*-linux*"] || [istarget "arm*-*-linux*"] } {
+    set syscall_insn "\[ \t\](swi|svc)\[ \t\]"
+} else {
+    return -1
+}
+
+load_lib "trace-support.exp"
+
+standard_testfile
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
+    untested $testfile.exp
+    return -1
+}
+
+if ![runto_main] {
+    fail "Can't run to main to check for trace support"
+    return -1
+}
+
+if ![gdb_target_supports_trace] {
+    unsupported "target does not support trace"
+    return -1
+}
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+if ![runto_main] {
+    fail "Can't run to main"
+    return -1
+}
+
+gdb_test "break kill" "Breakpoint \[0-9\]* at .*"
+gdb_test "handle SIGABRT nostop noprint pass" ".*" "pass SIGABRT"
+
+gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, (.* in |__libc_|)kill \\(\\).*" \
+    "continue to kill (1st time)"
+# Hit the breakpoint on $syscall for the first time.  In this time,
+# we will let PLT resolution done, and the number single steps we will
+# do later will be reduced.
+
+gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, (.* in |__libc_|)kill \\(\\).*" \
+    "continue to kill (2nd time)"
+# Hit the breakpoint on $syscall for the second time.  In this time,
+# the address of syscall insn and next insn of syscall are recorded.
+
+gdb_test "display/i \$pc" ".*"
+
+# Single step until we see a syscall insn or we reach the
+# upper bound of loop iterations.
+set msg "find syscall insn in kill"
+set steps 0
+set max_steps 1000
+gdb_test_multiple "stepi" $msg {
+    -re ".*$syscall_insn.*$gdb_prompt $" {
+	pass $msg
+    }
+    -re "x/i .*=>.*\r\n$gdb_prompt $" {
+	incr steps
+	if {$steps == $max_steps} {
+	    fail $msg
+	} else {
+	    send_gdb "stepi\n"
+	    exp_continue
+	}
+    }
+}
+
+if {$steps == $max_steps} {
+    return
+}
+
+# Remove the display
+gdb_test_no_output "delete display 1"
+
+set syscall_insn_addr [get_hexadecimal_valueof "\$pc" "0"]
+set syscall_insn_next 0
+set test "x/2i \$pc"
+gdb_test_multiple $test $test {
+    -re "$hex .*:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
+	set syscall_insn_next $expect_out(1,string)
+    }
+}
+
+delete_breakpoints
+gdb_test "break start" "Breakpoint \[0-9\] at .*"
+gdb_continue_to_breakpoint "continue to start"
+
+gdb_assert { 0 == [get_integer_valueof "counter" "1"] }
+
+delete_breakpoints
+
+# Set tracepoints on syscall instruction and the next one.  It is
+# more likely to get signal on these two places when GDBserver is
+# doing step-over.
+gdb_test "trace *$syscall_insn_addr" "Tracepoint \[0-9\] at .*"
+gdb_test "trace *$syscall_insn_next" "Tracepoint \[0-9\] at .*"
+
+gdb_test "break end" "Breakpoint \[0-9\] at .*"
+
+gdb_test_no_output "tstart"
+gdb_test "continue" ".*Breakpoint.* end .*at.*$srcfile.*" \
+    "continue to end"
+gdb_test_no_output "tstop"
+
+set iterations [get_integer_valueof "iterations" "0"]
+
+gdb_assert { $iterations == [get_integer_valueof "counter" "0"] }
+
+# Record the hit times of each tracepoint in this array.
+array set tracepoint_hits { }
+
+set test "tfind 0"
+gdb_test_multiple $test $test {
+    -re "Found trace frame 0, tracepoint ($decimal).*\r\n$gdb_prompt $" {
+
+	set idx [expr $expect_out(1,string)]
+
+	if {[info exists tracepoint_hits($idx)]} {
+	    incr tracepoint_hits($idx)
+	} else {
+	    set tracepoint_hits($idx) 1
+	}
+    }
+}
+
+set loop 1
+while { $loop } {
+    set test "tfind"
+    gdb_test_multiple $test $test {
+	-re "Found trace frame $decimal, tracepoint ($decimal).*\r\n$gdb_prompt $" {
+	    set idx [expr $expect_out(1,string)]
+
+	    if {[info exists tracepoint_hits($idx)]} {
+		incr tracepoint_hits($idx)
+	    } else {
+		set tracepoint_hits($idx) 1
+	    }
+	}
+	-re "Target failed to find requested trace frame\..*\r\n$gdb_prompt $" {
+	    set loop 0
+	}
+    }
+}
+
+for { set i 0 } { $i < [expr 20] } { incr i } {
+    if {[info exists tracepoint_hits($i)]} {
+	gdb_assert { $tracepoint_hits($i) == $iterations } \
+	    "tracepoint $i hit $iterations times"
+    }
+}
-- 
1.9.1

  parent reply	other threads:[~2016-03-23 16:10 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-23 16:10 [PATCH 0/7 V2] Step over instruction branches to itself Yao Qi
2016-03-23 16:10 ` [PATCH 5/7] [GDBserver] Don't error in reinsert_raw_breakpoint if bp->inserted Yao Qi
2016-04-11 14:54   ` Pedro Alves
2016-03-23 16:10 ` Yao Qi [this message]
2016-04-08 16:52   ` [PATCH 1/7] New test case gdb.trace/signal.exp Pedro Alves
2016-04-11  8:41     ` Yao Qi
2016-04-11 14:04       ` Pedro Alves
2016-04-22 10:53         ` Yao Qi
2016-04-26 12:57           ` Pedro Alves
2016-04-11 14:08       ` Pedro Alves
2016-03-23 16:10 ` [PATCH 3/7] Force to insert software single step breakpoint Yao Qi
2016-04-11 14:31   ` Pedro Alves
2016-04-13 16:21     ` Yao Qi
2016-04-19 14:54     ` Yao Qi
2016-04-19 15:17       ` Pedro Alves
2016-04-20  7:50     ` Yao Qi
2016-04-22 16:36       ` Pedro Alves
2016-04-25  8:40         ` Yao Qi
2016-03-23 16:10 ` [PATCH 4/7] Insert breakpoint even when the raw breakpoint is found Yao Qi
2016-04-11 14:41   ` Pedro Alves
2016-04-12  9:04     ` Yao Qi
2016-04-12  9:41       ` Pedro Alves
2016-04-25  8:45         ` Yao Qi
2016-03-23 16:10 ` [PATCH 6/7] Resume the inferior with signal rather than stepping over Yao Qi
2016-04-11 15:29   ` Pedro Alves
2016-03-23 16:10 ` [PATCH 2/7] Deliver signal in hardware single step Yao Qi
2016-04-11 14:10   ` Pedro Alves
2016-04-22 10:54     ` Yao Qi
2016-03-23 16:26 ` [PATCH 7/7] New test case gdb.base/branch-to-self.exp Yao Qi
2016-04-11 15:34   ` Pedro Alves
2016-04-25  8:58     ` Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1458749384-19793-2-git-send-email-yao.qi@linaro.org \
    --to=qiyaoltc@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).