From: Tom de Vries Date: Fri, 29 Jun 2018 11:25:49 +0000 (+0000) Subject: [testsuite/guality] Use line number vars in gdb-test X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8864590b7cad2b491407069d94068b65359e78c0;p=gcc.git [testsuite/guality] Use line number vars in gdb-test 2018-06-29 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. From-SVN: r262248 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a9f7fd96662..c7fef19358d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2018-06-29 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. + 2018-06-29 Martin Liska PR tree-optimization/86263 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" } {