[ 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  <tdevr...@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"

Reply via email to