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/>.
20 # Scan a file for markers and fill in the gdb_marker array for that
21 # file. Any error in this script is simply thrown; errors here are
22 # programming errors in the test suite itself and should not be
24 proc scan_gdb_markers {filename} {
27 if {[info exists gdb_markers($filename,-)]} {
31 set fd [open $filename]
35 if {[regexp -- "Mark (\[a-zA-Z0-9\]+)" $line ignore marker]} {
36 set gdb_markers($filename,$marker) $lineno
42 set gdb_markers($filename,-) {}
45 # Find a marker in a source file, and return the marker's line number.
46 proc get_line_number {filename marker} {
49 scan_gdb_markers $filename
50 return $gdb_markers($filename,$marker)
53 # Make note of a gdb test. A test consists of a variable name and an
55 proc note-test {var result} {
58 lappend gdb_tests $var $result
61 # Utility for testing variable values using gdb, invoked via dg-final.
62 # Tests all tests indicated by note-test.
64 # Argument 0 is the marker on which to put a breakpoint
65 # Argument 2 handles expected failures and the like
66 proc gdb-test { marker {selector {}} } {
67 if { ![isnative] || [is_remote target] } { return }
69 if {[string length $selector] > 0} {
70 switch [dg-process-target $selector] {
73 "F" { setup_xfail "*-*-*" }
78 # This assumes that we are three frames down from dg-test, and that
79 # it still stores the filename of the testcase in a local variable "name".
80 # A cleaner solution would require a new DejaGnu release.
84 set line [get_line_number $prog $marker]
86 set gdb_name $::env(GUALITY_GDB_NAME)
87 set testname "$testcase"
88 set output_file "[file rootname [file tail $prog]].exe"
89 set cmd_file "[file rootname [file tail $prog]].gdb"
92 set pycode [file join $srcdir .. python libstdcxx v6 printers.py]
96 set fd [open $cmd_file "w"]
97 puts $fd "source $pycode"
98 puts $fd "python register_libstdcxx_printers(None)"
99 puts $fd "break $line"
103 foreach {var result} $gdb_tests {
104 puts $fd "print $var"
106 set gdb_var($count) $var
107 set gdb_expected($count) $result
114 send_log "Spawning: $gdb_name -nx -nw -quiet -batch -x $cmd_file ./$output_file\n"
115 set res [remote_spawn target "$gdb_name -nx -nw -quiet -batch -x $cmd_file ./$output_file"]
116 if { $res < 0 || $res == "" } {
117 unsupported "$testname"
121 remote_expect target [timeout_value] {
122 -re {^\$([0-9]+) = ([^\n\r]*)[\n\r]+} {
123 set num $expect_out(1,string)
124 set first $expect_out(2,string)
125 if { ![string compare $first $gdb_expected($num)] } {
126 pass "$testname print $gdb_var($num)"
128 fail "$testname print $gdb_var($num)"
129 verbose " got =>$first<="
130 verbose "expected =>$gdb_expected($num)<="
133 if {$num == $count} {
141 -re {Python scripting is not supported in this copy of GDB.[\n\r]+} {
142 unsupported "$testname"
147 -re {^[^$][^\n\r]*[\n\r]+} {
148 verbose "skipping: $expect_out(buffer)"
153 unsupported "$testname"
160 unsupported "$testname"
164 # Check for a new-enough version of gdb. The pretty-printer tests
165 # require gdb 7.3, but we don't want to test versions, so instead we
166 # check for the python "lookup_global_symbol" method, which is in 7.3
167 # but not earlier versions.
168 # Return 1 if the version is ok, 0 otherwise.
169 proc gdb_version_check {} {
172 set gdb_name $::env(GUALITY_GDB_NAME)
173 set cmd "$gdb_name -nw -nx -quiet -batch -ex \"python print gdb.lookup_global_symbol\""
174 send_log "Spawning: $cmd\n"
175 set res [remote_spawn target "$cmd"]
176 if { $res < 0 || $res == "" } {
180 remote_expect target [timeout_value] {
181 -re "<built-in function lookup_global_symbol>" {
185 -re {^[^\n\r]*[\n\r]+} {
186 verbose "skipping: $expect_out(buffer)"