Reverting merge from trunk
[official-gcc.git] / gcc / testsuite / lib / gcc-gdb-test.exp
blob026830f110dead7fe3e3e1164cb13a8cb88f9963
1 # Copyright (C) 2009-2013 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]] {
29 "S" { }
30 "N" { return }
31 "F" { setup_xfail "*-*-*" }
32 "P" { }
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.
39 upvar 2 name testcase
40 upvar 2 prog prog
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]"
49 puts $fd "run"
50 puts $fd "print [lindex $args 1]"
51 puts $fd "print [lindex $args 2]"
52 puts $fd "quit"
53 close $fd
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"
59 file delete $cmd_file
60 return
63 remote_expect target [timeout_value] {
64 # Too old GDB
65 -re "Unhandled dwarf expression|Error in sourced command file" {
66 unsupported "$testname"
67 remote_close target
68 file delete $cmd_file
69 return
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 } {
75 pass "$testname"
76 } else {
77 # We need the -- to disambiguate $first from an option,
78 # as it may be negative.
79 send_log -- "$first != $second\n"
80 fail "$testname"
82 remote_close target
83 file delete $cmd_file
84 return
86 timeout {
87 unsupported "$testname"
88 remote_close target
89 file delete $cmd_file
90 return
94 unsupported "$testname"
95 remote_close target
96 file delete $cmd_file
97 return