1 # Copyright (C) 2009, 2011 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
17 # Utility for testing variable values using gdb, invoked via dg-final.
18 # Call pass if variable has the desired value, otherwise fail.
20 # Argument 0 is the line number on which to put a breakpoint
21 # Argument 1 is the name of the variable to be checked
22 # Argument 2 is the expected value of the variable
23 # Argument 3 handles expected failures and the like
24 proc gdb-test { args } {
25 if { ![isnative] || [is_remote target] } { return }
27 if { [llength $args] >= 4 } {
28 switch [dg-process-target [lindex $args 3]] {
31 "F" { setup_xfail "*-*-*" }
36 # This assumes that we are three frames down from dg-test, and that
37 # it still stores the filename of the testcase in a local variable "name".
38 # A cleaner solution would require a new DejaGnu release.
42 set gdb_name $::env(GUALITY_GDB_NAME)
43 set testname "$testcase line [lindex $args 0] [lindex $args 1] == [lindex $args 2]"
44 set output_file "[file rootname [file tail $prog]].exe"
45 set cmd_file "[file rootname [file tail $prog]].gdb"
47 set fd [open $cmd_file "w"]
48 puts $fd "break [lindex $args 0]"
50 puts $fd "print [lindex $args 1]"
51 puts $fd "print [lindex $args 2]"
55 send_log "Spawning: $gdb_name -nx -nw -quiet -x $cmd_file ./$output_file\n"
56 set res [remote_spawn target "$gdb_name -nx -nw -quiet -x $cmd_file ./$output_file"]
57 if { $res < 0 || $res == "" } {
58 unsupported "$testname"
63 remote_expect target [timeout_value] {
65 -re "Unhandled dwarf expression|Error in sourced command file" {
66 unsupported "$testname"
71 -re {[\n\r]\$1 = ([^\n\r]*)[\n\r]+\$2 = ([^\n\r]*)[\n\r]} {
72 set first $expect_out(1,string)
73 set second $expect_out(2,string)
74 if { $first == $second } {
77 send_log "$first != $second\n"
85 unsupported "$testname"
92 unsupported "$testname"