[testsuite/guality] Use line number vars in gdb-test

Message ID 20180628174930.qo67pkvnphg3c3qm@delia
State New
Headers show
Series
  • [testsuite/guality] Use line number vars in gdb-test
Related show

Commit Message

Tom de Vries June 28, 2018, 5:49 p.m.
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(-)

Comments

Tom de Vries June 28, 2018, 6:08 p.m. | #1
[ 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" } {
Jeff Law June 29, 2018, 12:06 a.m. | #2
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

Patch

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