From 1dd61ee507f808d0fdffee0ed3c17377e424bdd7 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 29 Sep 2009 12:38:19 +0200 Subject: [PATCH] guality.exp (gdb-test): New proc for use in dg-final. * gcc.dg/guality/guality.exp (gdb-test): New proc for use in dg-final. * gcc.dg/guality/pr41353-1.c: New test. From-SVN: r152271 --- gcc/testsuite/ChangeLog | 5 ++ gcc/testsuite/gcc.dg/guality/guality.exp | 91 ++++++++++++++++++++++++ gcc/testsuite/gcc.dg/guality/pr41353-1.c | 56 +++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/guality/pr41353-1.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 35e21e23f28..1894032299d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-09-29 Jakub Jelinek + + * gcc.dg/guality/guality.exp (gdb-test): New proc for use in dg-final. + * gcc.dg/guality/pr41353-1.c: New test. + 2009-09-29 Daniel Kraft PR fortran/39626 diff --git a/gcc/testsuite/gcc.dg/guality/guality.exp b/gcc/testsuite/gcc.dg/guality/guality.exp index 15a6e5e6342..b3f3319b102 100644 --- a/gcc/testsuite/gcc.dg/guality/guality.exp +++ b/gcc/testsuite/gcc.dg/guality/guality.exp @@ -15,8 +15,94 @@ proc check_guality {args} { return $ret } +# Utility for testing variable values using gdb, invoked via dg-final. +# Call pass if variable has the desired value, otherwise fail. +# +# Argument 0 is the line number on which to put a breakpoint +# Argument 1 is the name of the variable to be checked +# Argument 2 is the expected value of the variable +# Argument 3 handles expected failures and the like +proc gdb-test { args } { + if { ![isnative] || [is_remote target] } { return } + + if { [llength $args] >= 4 } { + switch [dg-process-target [lindex $args 3]] { + "S" { } + "N" { return } + "F" { setup_xfail "*-*-*" } + "P" { } + } + } + + # This assumes that we are three frames down from dg-test, and that + # it still stores the filename of the testcase in a local variable "name". + # A cleaner solution would require a new DejaGnu release. + upvar 2 name testcase + upvar 2 prog prog + + set gdb_name $::env(GUALITY_GDB_NAME) + set testname "$testcase line [lindex $args 0] [lindex $args 1] == [lindex $args 2]" + set output_file "[file rootname [file tail $prog]].exe" + set cmd_file "[file rootname [file tail $prog]].gdb" + + set fd [open $cmd_file "w"] + puts $fd "break [lindex $args 0]" + puts $fd "run" + puts $fd "print [lindex $args 1]" + puts $fd "print [lindex $args 2]" + puts $fd "quit" + close $fd + + send_log "Spawning: $gdb_name -nx -nw -quiet -x $cmd_file ./$output_file\n" + set res [remote_spawn target "$gdb_name -nx -nw -quiet -x $cmd_file ./$output_file"] + if { $res < 0 || $res == "" } { + unsupported "$testname" + return + } + + remote_expect target [timeout_value] { + -re {[\n\r]\$1 = ([^\n\r]*)[\n\r]+\$2 = ([^\n\r]*)[\n\r]} { + set first $expect_out(1,string) + set second $expect_out(2,string) + if { $first == $second } { + pass "$testname" + } else { + send_log "$first != $second\n" + fail "$testname" + } + remote_close target + return + } + # Too old GDB + -re "Unhandled dwarf expression|Error in sourced command file" { + unsupported "$testname" + remote_close target + return + } + timeout { + unsupported "$testname" + remote_close target + return + } + } + + remote_close target + unsupported "$testname" + return +} + dg-init +global GDB +if ![info exists ::env(GUALITY_GDB_NAME)] { + if [info exists GDB] { + set guality_gdb_name "$GDB" + } else { + set guality_gdb_name "[transform gdb]" + } + setenv GUALITY_GDB_NAME "$guality_gdb_name" +} + if {[check_guality " #include \"$srcdir/$subdir/guality.h\" volatile long int varl = 6; @@ -28,4 +114,9 @@ if {[check_guality " "]} { gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" } + +if [info exists guality_gdb_name] { + unsetenv GUALITY_GDB_NAME +} + dg-finish diff --git a/gcc/testsuite/gcc.dg/guality/pr41353-1.c b/gcc/testsuite/gcc.dg/guality/pr41353-1.c new file mode 100644 index 00000000000..29ba7351677 --- /dev/null +++ b/gcc/testsuite/gcc.dg/guality/pr41353-1.c @@ -0,0 +1,56 @@ +/* PR debug/41353 */ +/* { dg-do run } */ +/* { dg-options "-g" } */ + +int vari = 17, varj; + +__attribute__((noinline)) int +f1 (void) +{ + /* { dg-final { gdb-test 17 "vari" "17" } } */ + int vari1 = 2 * vari; /* { dg-final { gdb-test 17 "vari1" "2 * 17" } } */ + int vari2 = 3 * vari; /* { dg-final { gdb-test 17 "vari2" "3 * 17" } } */ + int vari3 = 2 * vari; /* { dg-final { gdb-test 17 "vari3" "2 * 17" } } */ + int vari4 = 3 * vari; /* { dg-final { gdb-test 17 "vari4" "3 * 17" } } */ + int vari5 = 4 * vari; /* { dg-final { gdb-test 17 "vari5" "4 * 17" } } */ + int vari6 = 5 * vari; /* { dg-final { gdb-test 17 "vari6" "5 * 17" } } */ + return varj; +} + +__attribute__((noinline)) int +f2 (int i, int j) +{ + j += i; + /* { dg-final { gdb-test 28 "i" "37" } } */ + /* { dg-final { gdb-test 28 "j" "28 + 37" { xfail *-*-* } } } */ + int i1 = 2 * i; /* { dg-final { gdb-test 28 "i1" "2 * 37" } } */ + int i2 = 3 * i; /* { dg-final { gdb-test 28 "i2" "3 * 37" } } */ + return j; +} + +__attribute__((noinline)) int +f3 (int i) +{ + asm volatile ("" : "+r" (i)); + /* { dg-final { gdb-test 39 "i" "12" } } */ + int i1 = 2 * i; /* { dg-final { gdb-test 39 "i1" "2 * 12" } } */ + int i2 = 2 * i; /* { dg-final { gdb-test 39 "i2" "2 * 12" } } */ + int i3 = 3 * i; /* { dg-final { gdb-test 39 "i3" "3 * 12" } } */ + return i; +} + +int (*volatile fnp1) (void) = f1; +int (*volatile fnp2) (int, int) = f2; +int (*volatile fnp3) (int) = f3; + +int +main (int argc, char *argv[]) +{ + asm volatile ("" : : "r" (&fnp1) : "memory"); + asm volatile ("" : : "r" (&fnp2) : "memory"); + asm volatile ("" : : "r" (&fnp3) : "memory"); + fnp1 (); + fnp2 (37, 28); + fnp3 (12); + return 0; +}