From patchwork Thu Jun 28 17:49:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 936345 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-480702-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="RIj0JcKL"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Gq1p556cz9s19 for ; Fri, 29 Jun 2018 05:03:41 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=t+ho9neluXDzaKnVMaPnBHMF67QkYUoY9+pk8zf3ZcmhL2mYyI Tzaa8A5iGTCKpPVMXsicOv69OCDfeSGIEAU7he7StaxjEsfDvAMU2winbe0ky9Gh DnGdCWtef+B/XufWXSIc9+7Vm9revs8TwvR13IxwjOwcFoRb+/FbipP9k= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=vALDKgaBIk0TOjBZH3qADsA040c=; b=RIj0JcKLat5oJY+bnadB J1KFwTuJFv1rRGQi+QzyeuZCmGrG7FRRs8b5pp5BDGzwppny0tu/wO4J0LUtR8rz CDDAimdGpBU34TS5Eqs63JmDe3+rMI0wZm8Oj6o7sxLUkn7/hgbaGVmpTDAWvXQJ yxlfRcCdIO43nCDmNsFgTI0= Received: (qmail 86081 invoked by alias); 28 Jun 2018 19:03:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 86045 invoked by uid 89); 28 Jun 2018 19:03:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=played, HCc:D*comcast.net, H*Ad:D*comcast.net, factors X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 28 Jun 2018 19:03:29 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 37FD8ACEB; Thu, 28 Jun 2018 19:03:24 +0000 (UTC) Date: Thu, 28 Jun 2018 19:49:30 +0200 From: Tom de Vries To: gcc-patches@gcc.gnu.org Cc: Rainer Orth , Mike Stump Subject: [PATCH, testsuite/guality] Use line number vars in gdb-test Message-ID: <20180628174930.qo67pkvnphg3c3qm@delia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170912 (1.9.0) X-IsSubscribed: yes Hi, I played around with pr45882.c and ran into FAILs. It took me a while to realize that the FAILs where due to the gdb-test (a dg-final action) using absolute line numbers, and me adding lines before the gdb-test lines. I've written this patch, which factors out the handling of relative line numbers as well as line number variables from process-message, and reuses the functionality in gdb-test. This enables the line number variables functionality in gdb-test. [ There's one quirk: line number variables have a define-before-use semantics (with matching used-before-defined error) but in the test-case the use in gdb-test preceeds the definition in gdb-line. This doesn't cause errors, because the dg-final actions are executed after the definition has taken effect. ] [ Relative line numbers still don't work in gdb-test, but that's due to an orthogonal issue: gdb-test is a dg-final action, and while dg-final receives the line number on which it occurred as it's first argument, it doesn't pass on this line number to the argument list of the action. I'll submit a follow-on rfc patch for this. ] Tested pr45882.c. Tested one test-case with relative line numbers, and one with line number variables to make sure I didn't break process-message. OK for trunk if bootstrap and reg-test succeeds? Thanks, - Tom [testsuite/guality] Use line number vars in gdb-test 2018-06-28 Tom de Vries * gcc.dg/guality/pr45882.c (foo): Add line number var for breakpoint line, and use it. * lib/gcc-dg.exp (get-absolute-line): Factor out of ... (process-message): ... here. * lib/gcc-gdb-test.exp (gdb-test): Use get-absolute-line. --- gcc/testsuite/gcc.dg/guality/pr45882.c | 10 ++--- gcc/testsuite/lib/gcc-dg.exp | 73 +++++++++++++++++++++------------- gcc/testsuite/lib/gcc-gdb-test.exp | 3 +- 3 files changed, 52 insertions(+), 34 deletions(-) diff --git a/gcc/testsuite/gcc.dg/guality/pr45882.c b/gcc/testsuite/gcc.dg/guality/pr45882.c index ece35238a30..da9e2755590 100644 --- a/gcc/testsuite/gcc.dg/guality/pr45882.c +++ b/gcc/testsuite/gcc.dg/guality/pr45882.c @@ -9,11 +9,11 @@ volatile short int v; __attribute__((noinline,noclone,used)) int foo (int i, int j) { - int b = i; /* { dg-final { gdb-test 16 "b" "7" } } */ - int c = i + 4; /* { dg-final { gdb-test 16 "c" "11" } } */ - int d = a[i]; /* { dg-final { gdb-test 16 "d" "112" } } */ - int e = a[i + 6]; /* { dg-final { gdb-test 16 "e" "142" } } */ - ++v; + int b = i; /* { dg-final { gdb-test bpline "b" "7" } } */ + int c = i + 4; /* { dg-final { gdb-test bpline "c" "11" } } */ + int d = a[i]; /* { dg-final { gdb-test bpline "d" "112" } } */ + int e = a[i + 6]; /* { dg-final { gdb-test bpline "e" "142" } } */ + ++v; /* { dg-line bpline } */ return ++j; } diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index a15c5d5e2a6..22065c7e3fe 100644 --- a/gcc/testsuite/lib/gcc-dg.exp +++ b/gcc/testsuite/lib/gcc-dg.exp @@ -1039,6 +1039,49 @@ proc dg-line { linenr varname } { } } +# Get the absolute line number corresponding to: +# - a relative line number (a non-null useline is required), or +# - a line number variable reference. +# Argument 0 is the line number on which line was used +# Argument 1 is the relative line number or line number variable reference +# +proc get-absolute-line { useline line } { + if { [regsub "^\.\[+-\](\[0-9\]+)$" $line "\\1" num] && $useline != "" } { + # Handle relative line specification, .+1 or .-1 etc. + set num [expr $useline [string index $line 1] $num] + return $num + } + + if { ! [regsub "^(\[a-zA-Z\]\[a-zA-Z0-9_\]*)$" $line "\\1" varname] } { + return $line + } + + # Handle linenr variable defined by dg-line + set org_varname $varname + set varname "saved_linenr_$varname" + eval global $varname + + # Generate used-but-not-defined error. + eval set var_defined [info exists $varname] + if { ! $var_defined } { + if { "$useline" != "" } { + error "dg-line var $org_varname used at line $uselinenr, but not defined" + } else { + error "dg-line var $org_varname used, but not defined" + } + return + } + + # Note that varname has been used. + set varname_used "used_$varname" + eval global $varname_used + eval set $varname_used 1 + + # Get line number from var and use it. + eval set num \$$varname + set line $num +} + # Modify the regular expression saved by a DejaGnu message directive to # include a prefix and to force the expression to match a single line. # MSGPROC is the procedure to call. @@ -1049,34 +1092,8 @@ proc process-message { msgproc msgprefix dgargs } { upvar dg-messages dg-messages if { [llength $dgargs] == 5 } { - if { [regsub "^\.\[+-\](\[0-9\]+)$" [lindex $dgargs 4] "\\1" num] } { - # Handle relative line specification, .+1 or .-1 etc. - set num [expr [lindex $dgargs 0] [string index [lindex $dgargs 4] 1] $num] - set dgargs [lreplace $dgargs 4 4 $num] - } elseif { [regsub "^(\[a-zA-Z\]\[a-zA-Z0-9_\]*)$" [lindex $dgargs 4] "\\1" varname] } { - # Handle linenr variable defined by dg-line - - set org_varname $varname - set varname "saved_linenr_$varname" - eval global $varname - - # Generate used-but-not-defined error. - eval set var_defined [info exists $varname] - if { ! $var_defined } { - set linenr [expr [lindex $dgargs 0]] - error "dg-line var $org_varname used at line $linenr, but not defined" - return - } - - # Note that varname has been used. - set varname_used "used_$varname" - eval global $varname_used - eval set $varname_used 1 - - # Get line number from var and use it. - eval set num \$$varname - set dgargs [lreplace $dgargs 4 4 $num] - } + set num [get-absolute-line [lindex $dgargs 0] [lindex $dgargs 4]] + set dgargs [lreplace $dgargs 4 4 $num] } # Process the dg- directive, including adding the regular expression diff --git a/gcc/testsuite/lib/gcc-gdb-test.exp b/gcc/testsuite/lib/gcc-gdb-test.exp index 2ef9ca15c12..5457e7a793e 100644 --- a/gcc/testsuite/lib/gcc-gdb-test.exp +++ b/gcc/testsuite/lib/gcc-gdb-test.exp @@ -60,7 +60,8 @@ proc gdb-test { args } { set cmd_file "[file rootname [file tail $prog]].gdb" set fd [open $cmd_file "w"] - puts $fd "break [lindex $args 0]" + set line [get-absolute-line "" [lindex $args 0]] + puts $fd "break $line" puts $fd "run" puts $fd "$command $var" if { $command == "print" } {