public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, testsuite/guality] Use line number vars in gdb-test
@ 2018-06-28 19:03 Tom de Vries
  2018-06-28 19:04 ` Tom de Vries
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Tom de Vries @ 2018-06-28 19:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: Rainer Orth, Mike Stump

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  <tdevries@suse.de>

	* 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" } {

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

* Re: [PATCH, testsuite/guality] Use line number vars in gdb-test
  2018-06-28 19:03 [PATCH, testsuite/guality] Use line number vars in gdb-test Tom de Vries
@ 2018-06-28 19:04 ` Tom de Vries
  2018-06-28 19:39 ` [RFC, testsuite/guality] Use relative line numbers " Tom de Vries
  2018-06-29  2:37 ` [PATCH, testsuite/guality] Use line number vars in gdb-test Jeff Law
  2 siblings, 0 replies; 7+ messages in thread
From: Tom de Vries @ 2018-06-28 19:04 UTC (permalink / raw)
  To: gcc-patches; +Cc: Rainer Orth, Mike Stump

[ resending. It seems this did not get through to the mail archive. ]

On Thu, Jun 28, 2018 at 07:49:30PM +0200, Tom de Vries wrote:
> 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  <tdevries@suse.de>
> 
> 	* 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" } {

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

* [RFC, testsuite/guality] Use relative line numbers in gdb-test
  2018-06-28 19:03 [PATCH, testsuite/guality] Use line number vars in gdb-test Tom de Vries
  2018-06-28 19:04 ` Tom de Vries
@ 2018-06-28 19:39 ` Tom de Vries
  2018-07-02 15:16   ` Mike Stump
  2018-07-04 19:32   ` Richard Sandiford
  2018-06-29  2:37 ` [PATCH, testsuite/guality] Use line number vars in gdb-test Jeff Law
  2 siblings, 2 replies; 7+ messages in thread
From: Tom de Vries @ 2018-06-28 19:39 UTC (permalink / raw)
  To: gcc-patches; +Cc: Rainer Orth, Mike Stump

[ was: [PATCH, testsuite/guality] Use line number vars in gdb-test ]

On Thu, Jun 28, 2018 at 07:49:30PM +0200, Tom de Vries wrote:
> 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. ]
>

This patch adds a dg-final override that passes it's first argument to the
gdb-test action.  This allows us to use relative line numbers in gdb-test.

Tested pr45882.c.

Any comments?
 
Thanks,
- Tom

[testsuite/guality] Use relative line numbers in gdb-test

2018-06-28  Tom de Vries  <tdevries@suse.de>

	* gcc.dg/guality/pr45882.c (foo): Use relative line numbers.
	* lib/gcc-dg.exp (dg-final): New proc.
	* lib/gcc-gdb-test.exp (gdb-test): Add and handle additional line number
	argument.

---
 gcc/testsuite/gcc.dg/guality/pr45882.c | 10 +++++-----
 gcc/testsuite/lib/gcc-dg.exp           | 20 ++++++++++++++++++++
 gcc/testsuite/lib/gcc-gdb-test.exp     |  4 ++--
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/guality/pr45882.c b/gcc/testsuite/gcc.dg/guality/pr45882.c
index da9e2755590..02d74389ea0 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 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 } */
+  int b = i;		/* { dg-final { gdb-test .+4 "b" "7" } } */
+  int c = i + 4;	/* { dg-final { gdb-test .+3 "c" "11" } } */
+  int d = a[i];		/* { dg-final { gdb-test .+2 "d" "112" } } */
+  int e = a[i + 6];	/* { dg-final { gdb-test .+1 "e" "142" } } */
+  ++v;
   return ++j;
 }
 
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index 22065c7e3fe..6f88ce2213e 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -114,6 +114,26 @@ if [info exists ADDITIONAL_TORTURE_OPTIONS] {
 	[concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
 }
 
+proc dg-final { args } {
+    upvar dg-final-code final-code
+
+    if { [llength $args] > 2 } {
+	error "[lindex $args 0]: too many arguments"
+    }
+    set line [lindex $args 0]
+    set code [lindex $args 1]
+    set directive [lindex $code 0]
+    set withline \
+	[switch $directive {
+	    gdb-test {expr {1}}
+	    default  {expr {0}}
+	}]
+    if { $withline == 1 } {
+	set code [linsert $code 1 $line]
+    }
+    append final-code "$code\n"
+}
+
 global orig_environment_saved
 
 # Deduce generated files from tool flags, return finalcode string
diff --git a/gcc/testsuite/lib/gcc-gdb-test.exp b/gcc/testsuite/lib/gcc-gdb-test.exp
index 5457e7a793e..c446f5b122d 100644
--- a/gcc/testsuite/lib/gcc-gdb-test.exp
+++ b/gcc/testsuite/lib/gcc-gdb-test.exp
@@ -26,7 +26,7 @@
 #   calling print on it in gdb. When asking for the type it is
 #   the literal string with extra whitespace removed.
 # Argument 3 handles expected failures and the like
-proc gdb-test { args } {
+proc gdb-test { useline args } {
     if { ![isnative] || [is_remote target] } { return }
 
     if { [llength $args] >= 4 } {
@@ -60,7 +60,7 @@ proc gdb-test { args } {
     set cmd_file "[file rootname [file tail $prog]].gdb"
 
     set fd [open $cmd_file "w"]
-    set line [get-absolute-line "" [lindex $args 0]]
+    set line [get-absolute-line $useline [lindex $args 0]]
     puts $fd "break $line"
     puts $fd "run"
     puts $fd "$command $var"

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

* Re: [PATCH, testsuite/guality] Use line number vars in gdb-test
  2018-06-28 19:03 [PATCH, testsuite/guality] Use line number vars in gdb-test Tom de Vries
  2018-06-28 19:04 ` Tom de Vries
  2018-06-28 19:39 ` [RFC, testsuite/guality] Use relative line numbers " Tom de Vries
@ 2018-06-29  2:37 ` Jeff Law
  2 siblings, 0 replies; 7+ messages in thread
From: Jeff Law @ 2018-06-29  2:37 UTC (permalink / raw)
  To: Tom de Vries, gcc-patches; +Cc: Rainer Orth, Mike Stump

On 06/28/2018 11:49 AM, Tom de Vries wrote:
> 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  <tdevries@suse.de>
> 
> 	* 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.
I prefer the relative line numbers, but either approach is fine with me.
 Your call.

jeff

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

* Re: [RFC, testsuite/guality] Use relative line numbers in gdb-test
  2018-06-28 19:39 ` [RFC, testsuite/guality] Use relative line numbers " Tom de Vries
@ 2018-07-02 15:16   ` Mike Stump
  2018-07-04 19:32   ` Richard Sandiford
  1 sibling, 0 replies; 7+ messages in thread
From: Mike Stump @ 2018-07-02 15:16 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gcc-patches, Rainer Orth

On Jun 28, 2018, at 12:39 PM, Tom de Vries <tdevries@suse.de> wrote:
> This patch adds a dg-final override that passes it's first argument to the
> gdb-test action.  This allows us to use relative line numbers in gdb-test.
> 
> Tested pr45882.c.
> 
> Any comments?

> 2018-06-28  Tom de Vries  <tdevries@suse.de>
> 
> 	* gcc.dg/guality/pr45882.c (foo): Use relative line numbers.
> 	* lib/gcc-dg.exp (dg-final): New proc.
> 	* lib/gcc-gdb-test.exp (gdb-test): Add and handle additional line number
> 	argument.

I like it.  :-)  I'd approve it.  Anyone not like it?

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

* Re: [RFC, testsuite/guality] Use relative line numbers in gdb-test
  2018-06-28 19:39 ` [RFC, testsuite/guality] Use relative line numbers " Tom de Vries
  2018-07-02 15:16   ` Mike Stump
@ 2018-07-04 19:32   ` Richard Sandiford
  2018-07-05  8:34     ` [testsuite] Simplify dg-final Tom de Vries
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Sandiford @ 2018-07-04 19:32 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gcc-patches, Rainer Orth, Mike Stump

Tom de Vries <tdevries@suse.de> writes:
> [ was: [PATCH, testsuite/guality] Use line number vars in gdb-test ]
> On Thu, Jun 28, 2018 at 07:49:30PM +0200, Tom de Vries wrote:
>> 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. ]
>>
>
> This patch adds a dg-final override that passes it's first argument to the
> gdb-test action.  This allows us to use relative line numbers in gdb-test.
>
> Tested pr45882.c.
>
> Any comments?
>  
> Thanks,
> - Tom
>
> [testsuite/guality] Use relative line numbers in gdb-test
>
> 2018-06-28  Tom de Vries  <tdevries@suse.de>
>
> 	* gcc.dg/guality/pr45882.c (foo): Use relative line numbers.
> 	* lib/gcc-dg.exp (dg-final): New proc.
> 	* lib/gcc-gdb-test.exp (gdb-test): Add and handle additional line number
> 	argument.
>
> ---
>  gcc/testsuite/gcc.dg/guality/pr45882.c | 10 +++++-----
>  gcc/testsuite/lib/gcc-dg.exp           | 20 ++++++++++++++++++++
>  gcc/testsuite/lib/gcc-gdb-test.exp     |  4 ++--
>  3 files changed, 27 insertions(+), 7 deletions(-)
>
> diff --git a/gcc/testsuite/gcc.dg/guality/pr45882.c b/gcc/testsuite/gcc.dg/guality/pr45882.c
> index da9e2755590..02d74389ea0 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 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 } */
> +  int b = i;		/* { dg-final { gdb-test .+4 "b" "7" } } */
> +  int c = i + 4;	/* { dg-final { gdb-test .+3 "c" "11" } } */
> +  int d = a[i];		/* { dg-final { gdb-test .+2 "d" "112" } } */
> +  int e = a[i + 6];	/* { dg-final { gdb-test .+1 "e" "142" } } */
> +  ++v;
>    return ++j;
>  }
>  
> diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
> index 22065c7e3fe..6f88ce2213e 100644
> --- a/gcc/testsuite/lib/gcc-dg.exp
> +++ b/gcc/testsuite/lib/gcc-dg.exp
> @@ -114,6 +114,26 @@ if [info exists ADDITIONAL_TORTURE_OPTIONS] {
>  	[concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
>  }
>  
> +proc dg-final { args } {
> +    upvar dg-final-code final-code
> +
> +    if { [llength $args] > 2 } {
> +	error "[lindex $args 0]: too many arguments"
> +    }
> +    set line [lindex $args 0]
> +    set code [lindex $args 1]
> +    set directive [lindex $code 0]
> +    set withline \
> +	[switch $directive {
> +	    gdb-test {expr {1}}
> +	    default  {expr {0}}
> +	}]
> +    if { $withline == 1 } {
> +	set code [linsert $code 1 $line]
> +    }
> +    append final-code "$code\n"
> +}

Like the idea, but I think:

    set withline \
	[switch $directive {
	    gdb-test {expr {1}}
	    default  {expr {0}}
	}]
    if { $withline == 1 } {
	set code [linsert $code 1 $line]
    }

would be clearer as:

    switch $directive {
	gdb-test {
	    set code [linsert $code 1 $line]
	}
    }

Thanks,
Richard

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

* [testsuite] Simplify dg-final
  2018-07-04 19:32   ` Richard Sandiford
@ 2018-07-05  8:34     ` Tom de Vries
  0 siblings, 0 replies; 7+ messages in thread
From: Tom de Vries @ 2018-07-05  8:34 UTC (permalink / raw)
  To: gcc-patches, Rainer Orth, Mike Stump, richard.sandiford

[ was: [PATCH, testsuite/guality] Use line number vars in gdb-test ]

On Wed, Jul 04, 2018 at 08:32:49PM +0100, Richard Sandiford wrote:
> Tom de Vries <tdevries@suse.de> writes:
> > +proc dg-final { args } {
> > +    upvar dg-final-code final-code
> > +
> > +    if { [llength $args] > 2 } {
> > +	error "[lindex $args 0]: too many arguments"
> > +    }
> > +    set line [lindex $args 0]
> > +    set code [lindex $args 1]
> > +    set directive [lindex $code 0]
> > +    set withline \
> > +	[switch $directive {
> > +	    gdb-test {expr {1}}
> > +	    default  {expr {0}}
> > +	}]
> > +    if { $withline == 1 } {
> > +	set code [linsert $code 1 $line]
> > +    }
> > +    append final-code "$code\n"
> > +}
> 
> Like the idea, but I think:
> 
>     set withline \
> 	[switch $directive {
> 	    gdb-test {expr {1}}
> 	    default  {expr {0}}
> 	}]
>     if { $withline == 1 } {
> 	set code [linsert $code 1 $line]
>     }
> 
> would be clearer as:
> 
>     switch $directive {
> 	gdb-test {
> 	    set code [linsert $code 1 $line]
> 	}
>     }

Agreed, thanks for the comment.  Committed as below.

Thanks,
- Tom

[testsuite] Simplify dg-final

2018-07-05  Tom de Vries  <tdevries@suse.de>

	* lib/gcc-dg.exp (dg-final): Simplify tcl code.

---
 gcc/testsuite/lib/gcc-dg.exp | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index 9e0b3f4ef95..f5e6bef5dd9 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -123,13 +123,10 @@ proc dg-final { args } {
     set line [lindex $args 0]
     set code [lindex $args 1]
     set directive [lindex $code 0]
-    set withline \
-	[switch $directive {
-	    gdb-test {expr {1}}
-	    default  {expr {0}}
-	}]
-    if { $withline == 1 } {
-	set code [linsert $code 1 $line]
+    switch $directive {
+	gdb-test {
+	    set code [linsert $code 1 $line]
+	}
     }
     append final-code "$code\n"
 }

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

end of thread, other threads:[~2018-07-05  8:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-28 19:03 [PATCH, testsuite/guality] Use line number vars in gdb-test Tom de Vries
2018-06-28 19:04 ` Tom de Vries
2018-06-28 19:39 ` [RFC, testsuite/guality] Use relative line numbers " Tom de Vries
2018-07-02 15:16   ` Mike Stump
2018-07-04 19:32   ` Richard Sandiford
2018-07-05  8:34     ` [testsuite] Simplify dg-final Tom de Vries
2018-06-29  2:37 ` [PATCH, testsuite/guality] Use line number vars in gdb-test Jeff Law

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).