From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27446 invoked by alias); 22 Apr 2016 10:53:37 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 27419 invoked by uid 89); 22 Apr 2016 10:53:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=x86_64*linux*, x86_64-*-linux*, nostop, UD:signal.h X-HELO: mail-pa0-f46.google.com Received: from mail-pa0-f46.google.com (HELO mail-pa0-f46.google.com) (209.85.220.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 22 Apr 2016 10:53:22 +0000 Received: by mail-pa0-f46.google.com with SMTP id zm5so38901065pac.0 for ; Fri, 22 Apr 2016 03:53:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=Vy88r/7DSLV5dJOK9LhZCuw5LMEzFBsRL4sHXAIXnwU=; b=VRkEYLbPI4trYqWl4xteGIFC+V10OWuFzy6817pb5Up0F2GWC0SIgHPx/QFf/X7hdb hH/WtILfrNsjjhUsRIbh/jAJ4EB+ZlxtzksLa63MAMT31pGmZtKbJR53tAXZzwuXZ/6i mtkCIWGia1+6ydRZcMKpm0gLppRnpcwT0K6wLBLXhbktD+j5PSS1Juokc1pqk3aWQmUe 6Xlzn21jv7028CqvvSV5H5eM1ikcqW2fHQNJCRv2MLNUUmRKKyJnZ7IfP0zvRzu9otwd 7HRwFoFoDepyAw5rVsk6qzI8NhsewQpUKj1vvOXwdK9yi+3dKsCeajOxYizNXdD9XR9V ETOw== X-Gm-Message-State: AOPr4FWr/yhqIa7E9JRwzBVu+3iIE9MgD9Yx89gKWgcpbqjVkrG96/8YOHhYRY+j5PnLGw== X-Received: by 10.67.7.37 with SMTP id cz5mr27504749pad.18.1461322400319; Fri, 22 Apr 2016 03:53:20 -0700 (PDT) Received: from E107787-LIN (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id s66sm7579648pfi.3.2016.04.22.03.53.15 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 22 Apr 2016 03:53:19 -0700 (PDT) From: Yao Qi To: Pedro Alves Cc: Yao Qi , gdb-patches@sourceware.org Subject: Re: [PATCH 1/7] New test case gdb.trace/signal.exp References: <1458749384-19793-1-git-send-email-yao.qi@linaro.org> <1458749384-19793-2-git-send-email-yao.qi@linaro.org> <5707E1CC.2010609@redhat.com> <86a8l0leqy.fsf@gmail.com> <570BAECD.30508@redhat.com> Date: Fri, 22 Apr 2016 10:53:00 -0000 In-Reply-To: <570BAECD.30508@redhat.com> (Pedro Alves's message of "Mon, 11 Apr 2016 15:03:57 +0100") Message-ID: <86inz9j4oo.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2016-04/txt/msg00513.txt.bz2 Pedro Alves writes: >> +# Record the hit times of each tracepoint in this array. >> +array set tracepoint_hits { } >> + >> +set test "tfind 0" >> +gdb_test_multiple $test $test { > > Why do we need this separate "tfind 0" step? I'd think the > "tfind" loop below would be sufficient? I don't know the first "tfind" can find the first snapshot , and I think "tfind 0" should be the first one in all other "tfind X" commands. The usage like this is not documented. In current doc: tfind =20=20=20 No argument means find the next trace snapshot. We probably need to change the doc to No argument means find the next trace snapshot or find the first one if no trace snapshot is selected. > Otherwise looks good to me. Patch below is what I'll push in. --=20 Yao (=E9=BD=90=E5=B0=A7) =46rom 8f78bf828e7df83f1fde7154bbfcd718a90bef36 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Wed, 23 Mar 2016 15:37:10 +0000 Subject: [PATCH] New test case gdb.trace/signal.exp 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 collection. gdb/testsuite: 2016-04-22 Yao Qi * gdb.trace/signal.c: New file. * gdb.trace/signal.exp: New file. diff --git a/gdb/testsuite/gdb.trace/signal.c b/gdb/testsuite/gdb.trace/sig= nal.c new file mode 100644 index 0000000..4577a7b --- /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 . = */ + +#include +#include +#include + +static int counter =3D 0; + +static void +handler (int sig) +{ + counter++; +} + +static int iterations =3D 3; + +static void +start (int pid) +{ + int i; + + for (i =3D 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 =3D handler; + act.sa_flags =3D SA_NODEFER; + sigaction (SIGABRT, &act, NULL); + + for (i =3D 0; i < 3; i++) + { + kill (getpid (), SIGABRT); + } + + counter =3D 0; + start (getpid ()); + + end (); + return 0; +} diff --git a/gdb/testsuite/gdb.trace/signal.exp b/gdb/testsuite/gdb.trace/s= ignal.exp new file mode 100644 index 0000000..7118a9f --- /dev/null +++ b/gdb/testsuite/gdb.trace/signal.exp @@ -0,0 +1,179 @@ +# 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 . + +# This is to test whether GDBserver or other remote stubs deliver signal +# to the inferior while step over thread. The program signal.c sends +# signal SIGABRT to itself via kill syscall. The test sets tracepoints +# syscall instruction and the next one, and it is quite likely that +# GDBserver gets the signal when it steps over thread and does the +# collection. If GDBserver doesn't deliver signal in thread step over, +# one collection is got for one tracepoint hit. Otherwise, there may +# be two collections for one tracepoint hit, because tracepoint is +# collected once before step over, the program goes into signal handler +# (because signal is delivered in step over), and program goes back +# to the tracepoint again (one more collection) after returns from +# signal handler. + +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 +} + +# Step 1, find the syscall instruction address. + +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 { + unsupported "unknown syscall instruction" + 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 $decimal at .*" +gdb_test "handle SIGABRT nostop noprint pass" ".*" "pass SIGABRT" + +# 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 $decimal, (.* in |__libc_|)= kill \\(\\).*" \ + "continue to kill, 1st 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 "continue" "Continuing\\..*Breakpoint $decimal, (.* in |__libc_|)= kill \\(\\).*" \ + "continue to kill, 2nd time" + +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 .*=3D>.*\r\n$gdb_prompt $" { + incr steps + if {$steps =3D=3D $max_steps} { + fail $msg + } else { + send_gdb "stepi\n" + exp_continue + } + } +} + +if {$steps =3D=3D $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 $decimal at .*" +gdb_continue_to_breakpoint "continue to start" + +gdb_assert { 0 =3D=3D [get_integer_valueof "counter" "1"] } "counter is ze= ro" + +delete_breakpoints + +# Step 2, 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 $decimal at .*" \ + "tracepoint on syscall instruction" +set tpnum [get_integer_valueof "\$bpnum" 0] +gdb_test "trace *$syscall_insn_next" "Tracepoint $decimal at .*" \ + "tracepoint on instruction following syscall instruction" + +gdb_test "break end" "Breakpoint $decimal 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 =3D=3D [get_integer_valueof "counter" "0"] } \ + "iterations equals to counter" + +# Record the hit times of each tracepoint in this array. +array set tracepoint_hits { } +for { set i $tpnum } { $i < [expr $tpnum + 2] } { incr i } { + set tracepoint_hits($i) 0 +} + +while { 1 } { + set test "tfind" + set idx 0 + gdb_test_multiple $test $test { + -re "Found trace frame $decimal, tracepoint ($decimal).*\r\n$gdb_prompt $= " { + set idx [expr $expect_out(1,string)] + incr tracepoint_hits($idx) + } + -re "Target failed to find requested trace frame\..*\r\n$gdb_prompt= $" { + set idx 0 + } + } + if {$idx =3D=3D 0} { + break + } +} + +# Step 3, check the number of collections on each tracepoint. + +for { set i $tpnum } { $i < [expr $tpnum + 2] } { incr i } { + gdb_assert { $tracepoint_hits($i) =3D=3D $iterations } \ + "tracepoint $i hit $iterations times" +}