From patchwork Wed Mar 23 16:09:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 11490 Received: (qmail 89703 invoked by alias); 23 Mar 2016 16:10:03 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 89532 invoked by uid 89); 23 Mar 2016 16:10:03 -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=traps, proceeds, collected, (unknown) X-HELO: mail-pf0-f193.google.com Received: from mail-pf0-f193.google.com (HELO mail-pf0-f193.google.com) (209.85.192.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 23 Mar 2016 16:09:53 +0000 Received: by mail-pf0-f193.google.com with SMTP id q129so4626311pfb.3 for ; Wed, 23 Mar 2016 09:09:53 -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:subject:date:message-id:in-reply-to :references; bh=w03D5skH+Sb36QyMhBhqZMnreooAP+1WqYHmZQHov8s=; b=DoADjpl2O0cUBeQdI7nazq0NbzQF+sWAennfnlBAQQ14cS7qSLIOFktJ2MsgEGd4gn tkmI4gKK7FvT55SOj75r8UBhrrDi0CmCb5xkmSaLSm50NLndIxjir9FtIaqRT3o2I0vE F4RfAZlhwTLAIQoWanp85DcrxG9JHpl84HfvjchacaFakVjaf8Oyu+12odTZdc4GD0cr Z2CPIDU3a0Xyy+n6WyawwgcdD/AA08boUf5AvxRZ6ImO1BR4layi9tnALPUd8KpeSkTE 1ILoObbGAah+UGZrOAIT/2B166vZ1j3dcAmjlz2jAYD3el51VhT3u6jcZSN2srPCsQrM oagA== X-Gm-Message-State: AD7BkJIdWPN+eCocruFdjsO2g3eWGjkjstClmpEjijNUyLCTszqr21Kw83mPNQPuqWuXDg== X-Received: by 10.66.159.232 with SMTP id xf8mr5431031pab.71.1458749391485; Wed, 23 Mar 2016 09:09:51 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id 79sm5206701pfq.65.2016.03.23.09.09.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Mar 2016 09:09:50 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 2/7] Deliver signal in hardware single step Date: Wed, 23 Mar 2016 16:09:39 +0000 Message-Id: <1458749384-19793-3-git-send-email-yao.qi@linaro.org> In-Reply-To: <1458749384-19793-1-git-send-email-yao.qi@linaro.org> References: <1458749384-19793-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes GDBserver doesn't deliver signal when stepping over a breakpoint even hardware single step is used. When GDBserver started to step over (thread creation) breakpoint for mutlit-threaded debugging in 2002 [1], GDBserver behaves this way. This behavior gets trouble on conditional breakpoints on branch to self instruction like this, 0x00000000004005b6 <+29>: jmp 0x4005b6 and I set breakpoint $(gdb) break branch-to-self.c:43 if counter > 3 and the variable counter will be set to 5 in SIGALRM signal handler. Since GDBserver keeps stepping over breakpoint, the SIGALRM can never be dequeued and delivered to the inferior, so the program can't stop. The test can be found in gdb.base/branch-to-self.exp. GDBserver didn't deliver signal when stepping over a breakpoint because a tracepoint is collected twice if GDBserver does so in the following scenario, which can be reproduced by gdb.trace/signal.exp. - program stops at tracepoint, and tracepoint is collected, - gdbserver starts a step-over, - a signal arrives, step-over is canceled, and signal should be passed, - gdbserver starts a new step-over again, pass the signal as well, - program stops at the entry of signal handler, step-over finished, - gdbserver proceeds, - program returns from the signal handler, again to the tracepoint, and thus is collected again. The spurious collection isn't that harmful, IMO, so it should be OK to let GDBserver deliver signal when stepping over a breakpoint. gdb/gdbserver: 2016-03-23 Yao Qi * linux-low.c (lwp_signal_can_be_delivered): Don't deliver signal when stepping over breakpoint with software single step. gdb/testsuite: 2016-03-23 Yao Qi * gdb.trace/signal.exp: Also pass if $tracepoint_hits($i) > $iterations. --- gdb/gdbserver/linux-low.c | 10 +++++++--- gdb/testsuite/gdb.trace/signal.exp | 12 ++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 2cf192e..7e55349 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -4118,13 +4118,17 @@ single_step (struct lwp_info* lwp) } /* The signal can be delivered to the inferior if we are not trying to - reinsert a breakpoint and not trying to finish a fast tracepoint - collect. */ + reinsert a breakpoint for software single step and not trying to + finish a fast tracepoint collect. Since signal can be delivered in + the step-over, the program may go to signal handler and trap again + after return from the signal handler. We can live with the spurious + double traps. */ static int lwp_signal_can_be_delivered (struct lwp_info *lwp) { - return (lwp->bp_reinsert == 0 && !lwp->collecting_fast_tracepoint); + return (!(lwp->bp_reinsert != 0 && can_software_single_step ()) + && !lwp->collecting_fast_tracepoint); } /* Resume execution of LWP. If STEP is nonzero, single-step it. If diff --git a/gdb/testsuite/gdb.trace/signal.exp b/gdb/testsuite/gdb.trace/signal.exp index 85898c3..7eeb0f9 100644 --- a/gdb/testsuite/gdb.trace/signal.exp +++ b/gdb/testsuite/gdb.trace/signal.exp @@ -166,7 +166,15 @@ while { $loop } { 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" + + if { $tracepoint_hits($i) == $iterations } { + pass "tracepoint $i hit $iterations times" + } elseif { $tracepoint_hits($i) > $iterations } { + # GDBserver delivers the signal while stepping over tracepoint, + # so it is possible that a tracepoint is collected twice. + pass "tracepoint $i hit $iterations times: spurious collection" + } else { + fail "tracepoint $i hit $iterations times" + } } }