annotate libstdc++-v3/testsuite/lib/gdb-test.exp @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1 # Copyright (C) 2009-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 # This program is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
5 # the Free Software Foundation; either version 3 of the License, or
kono
parents:
diff changeset
6 # (at your option) any later version.
kono
parents:
diff changeset
7 #
kono
parents:
diff changeset
8 # This program is distributed in the hope that it will be useful,
kono
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
11 # GNU General Public License for more details.
kono
parents:
diff changeset
12 #
kono
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
14 # along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
15 # <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 global gdb_tests
kono
parents:
diff changeset
18 set gdb_tests {}
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 # Scan a file for markers and fill in the gdb_marker array for that
kono
parents:
diff changeset
21 # file. Any error in this script is simply thrown; errors here are
kono
parents:
diff changeset
22 # programming errors in the test suite itself and should not be
kono
parents:
diff changeset
23 # caught.
kono
parents:
diff changeset
24 proc scan_gdb_markers {filename} {
kono
parents:
diff changeset
25 global gdb_markers
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 if {[info exists gdb_markers($filename,-)]} {
kono
parents:
diff changeset
28 return
kono
parents:
diff changeset
29 }
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 set fd [open $filename]
kono
parents:
diff changeset
32 set lineno 1
kono
parents:
diff changeset
33 while {! [eof $fd]} {
kono
parents:
diff changeset
34 set line [gets $fd]
kono
parents:
diff changeset
35 if {[regexp -- "Mark (\[a-zA-Z0-9\]+)" $line ignore marker]} {
kono
parents:
diff changeset
36 set gdb_markers($filename,$marker) $lineno
kono
parents:
diff changeset
37 }
kono
parents:
diff changeset
38 incr lineno
kono
parents:
diff changeset
39 }
kono
parents:
diff changeset
40 close $fd
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 set gdb_markers($filename,-) {}
kono
parents:
diff changeset
43 }
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 # Find a marker in a source file, and return the marker's line number.
kono
parents:
diff changeset
46 proc get_line_number {filename marker} {
kono
parents:
diff changeset
47 global gdb_markers
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 scan_gdb_markers $filename
kono
parents:
diff changeset
50 return $gdb_markers($filename,$marker)
kono
parents:
diff changeset
51 }
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 # Make note of a gdb test. A test consists of a variable name and an
kono
parents:
diff changeset
54 # expected result.
kono
parents:
diff changeset
55 proc note-test {var result} {
kono
parents:
diff changeset
56 global gdb_tests
kono
parents:
diff changeset
57
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
58 lappend gdb_tests $var $result print 0
111
kono
parents:
diff changeset
59 }
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 # A test that uses a regular expression. This is like note-test, but
kono
parents:
diff changeset
62 # the result is a regular expression that is matched against the
kono
parents:
diff changeset
63 # output.
kono
parents:
diff changeset
64 proc regexp-test {var result} {
kono
parents:
diff changeset
65 global gdb_tests
kono
parents:
diff changeset
66
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
67 lappend gdb_tests $var $result print 1
111
kono
parents:
diff changeset
68 }
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 # A test of 'whatis'. This tests a type rather than a variable.
kono
parents:
diff changeset
71 proc whatis-test {var result} {
kono
parents:
diff changeset
72 global gdb_tests
kono
parents:
diff changeset
73
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
74 lappend gdb_tests $var $result whatis 0
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
75 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
76
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
77 # A test of 'whatis' that uses a regular expression. This tests a type rather
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
78 # than a variable.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
79 proc whatis-regexp-test {var result} {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
80 global gdb_tests
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
81
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
82 lappend gdb_tests $var $result whatis 1
111
kono
parents:
diff changeset
83 }
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 # Utility for testing variable values using gdb, invoked via dg-final.
kono
parents:
diff changeset
86 # Tests all tests indicated by note-test and regexp-test.
kono
parents:
diff changeset
87 #
kono
parents:
diff changeset
88 # Argument 0 is the marker on which to put a breakpoint
kono
parents:
diff changeset
89 # Argument 2 handles expected failures and the like
kono
parents:
diff changeset
90 proc gdb-test { marker {selector {}} {load_xmethods 0} } {
kono
parents:
diff changeset
91 if { ![isnative] || [is_remote target] } { return }
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 if {[string length $selector] > 0} {
kono
parents:
diff changeset
94 switch [dg-process-target $selector] {
kono
parents:
diff changeset
95 "S" { }
kono
parents:
diff changeset
96 "N" { return }
kono
parents:
diff changeset
97 "F" { setup_xfail "*-*-*" }
kono
parents:
diff changeset
98 "P" { }
kono
parents:
diff changeset
99 }
kono
parents:
diff changeset
100 }
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 set do_whatis_tests [gdb_batch_check "python print(gdb.type_printers)" \
kono
parents:
diff changeset
103 "\\\[\\\]"]
kono
parents:
diff changeset
104 if {!$do_whatis_tests} {
kono
parents:
diff changeset
105 send_log "skipping 'whatis' tests - gdb too old"
kono
parents:
diff changeset
106 }
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 # This assumes that we are three frames down from dg-test, and that
kono
parents:
diff changeset
109 # it still stores the filename of the testcase in a local variable "name".
kono
parents:
diff changeset
110 # A cleaner solution would require a new DejaGnu release.
kono
parents:
diff changeset
111 upvar 2 name testcase
kono
parents:
diff changeset
112 upvar 2 prog prog
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 set line [get_line_number $prog $marker]
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 set gdb_name $::env(GUALITY_GDB_NAME)
kono
parents:
diff changeset
117 set testname "$testcase"
kono
parents:
diff changeset
118 set output_file "[file rootname [file tail $prog]].exe"
kono
parents:
diff changeset
119 set cmd_file "[file rootname [file tail $prog]].gdb"
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 global srcdir
kono
parents:
diff changeset
122 set printer_code [file join $srcdir .. python libstdcxx v6 printers.py]
kono
parents:
diff changeset
123 set xmethod_code [file join $srcdir .. python libstdcxx v6 xmethods.py]
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 global gdb_tests
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 set fd [open $cmd_file "w"]
kono
parents:
diff changeset
128 # We don't want the system copy of the pretty-printers loaded
kono
parents:
diff changeset
129 puts $fd "set auto-load no"
kono
parents:
diff changeset
130 # Now that we've disabled auto-load, it's safe to set the target file
kono
parents:
diff changeset
131 puts $fd "file ./$output_file"
kono
parents:
diff changeset
132 # Load & register *our* copy of the pretty-printers
kono
parents:
diff changeset
133 puts $fd "source $printer_code"
kono
parents:
diff changeset
134 puts $fd "python register_libstdcxx_printers(None)"
kono
parents:
diff changeset
135 if { $load_xmethods } {
kono
parents:
diff changeset
136 # Load a& register xmethods.
kono
parents:
diff changeset
137 puts $fd "source $xmethod_code"
kono
parents:
diff changeset
138 puts $fd "python register_libstdcxx_xmethods(None)"
kono
parents:
diff changeset
139 }
kono
parents:
diff changeset
140 # And start the program
kono
parents:
diff changeset
141 puts $fd "break $line"
kono
parents:
diff changeset
142 puts $fd "run"
kono
parents:
diff changeset
143 # So we can verify that we're using the right libs ...
kono
parents:
diff changeset
144 puts $fd "info share"
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 set count 0
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
147 foreach {var result kind rexp} $gdb_tests {
111
kono
parents:
diff changeset
148 incr count
kono
parents:
diff changeset
149 set gdb_var($count) $var
kono
parents:
diff changeset
150 set gdb_expected($count) $result
kono
parents:
diff changeset
151 if {$kind == "whatis"} {
kono
parents:
diff changeset
152 if {$do_whatis_tests} {
kono
parents:
diff changeset
153 set gdb_is_type($count) 1
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
154 set gdb_is_regexp($count) $rexp
111
kono
parents:
diff changeset
155 set gdb_command($count) "whatis $var"
kono
parents:
diff changeset
156 } else {
kono
parents:
diff changeset
157 unsupported "$testname"
kono
parents:
diff changeset
158 close $fd
kono
parents:
diff changeset
159 return
kono
parents:
diff changeset
160 }
kono
parents:
diff changeset
161 } else {
kono
parents:
diff changeset
162 set gdb_is_type($count) 0
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
163 set gdb_is_regexp($count) $rexp
111
kono
parents:
diff changeset
164 set gdb_command($count) "print $var"
kono
parents:
diff changeset
165 }
kono
parents:
diff changeset
166 puts $fd $gdb_command($count)
kono
parents:
diff changeset
167 }
kono
parents:
diff changeset
168 set gdb_tests {}
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 puts $fd "quit"
kono
parents:
diff changeset
171 close $fd
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 set res [remote_spawn target "$gdb_name -nx -nw -quiet -batch -x $cmd_file "]
kono
parents:
diff changeset
174 if { $res < 0 || $res == "" } {
kono
parents:
diff changeset
175 unsupported "$testname"
kono
parents:
diff changeset
176 return
kono
parents:
diff changeset
177 }
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 set test_counter 0
kono
parents:
diff changeset
180 remote_expect target [timeout_value] {
kono
parents:
diff changeset
181 -re {^(type|\$([0-9]+)) = ([^\n\r]*)[\n\r]+} {
kono
parents:
diff changeset
182 send_log "got: $expect_out(buffer)"
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 incr test_counter
kono
parents:
diff changeset
185 set first $expect_out(3,string)
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 if {$gdb_is_type($test_counter)} {
kono
parents:
diff changeset
188 if {$expect_out(1,string) != "type"} {
kono
parents:
diff changeset
189 error "gdb failure"
kono
parents:
diff changeset
190 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
191 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
192
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
193 if {$gdb_is_regexp($test_counter)} {
111
kono
parents:
diff changeset
194 set match [regexp -- $gdb_expected($test_counter) $first]
kono
parents:
diff changeset
195 } else {
kono
parents:
diff changeset
196 set match [expr {![string compare $first \
kono
parents:
diff changeset
197 $gdb_expected($test_counter)]}]
kono
parents:
diff changeset
198 }
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 if {$match} {
kono
parents:
diff changeset
201 pass "$testname $gdb_command($test_counter)"
kono
parents:
diff changeset
202 } else {
kono
parents:
diff changeset
203 fail "$testname $gdb_command($test_counter)"
kono
parents:
diff changeset
204 verbose " got =>$first<="
kono
parents:
diff changeset
205 verbose "expected =>$gdb_expected($test_counter)<="
kono
parents:
diff changeset
206 }
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 if {$test_counter == $count} {
kono
parents:
diff changeset
209 remote_close target
kono
parents:
diff changeset
210 return
kono
parents:
diff changeset
211 } else {
kono
parents:
diff changeset
212 exp_continue
kono
parents:
diff changeset
213 }
kono
parents:
diff changeset
214 }
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 -re {Python scripting is not supported in this copy of GDB.[\n\r]+} {
kono
parents:
diff changeset
217 unsupported "$testname"
kono
parents:
diff changeset
218 remote_close target
kono
parents:
diff changeset
219 return
kono
parents:
diff changeset
220 }
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 -re {Error while executing Python code.[\n\r]} {
kono
parents:
diff changeset
223 fail "$testname"
kono
parents:
diff changeset
224 remote_close target
kono
parents:
diff changeset
225 return
kono
parents:
diff changeset
226 }
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 -re {^[^$][^\n\r]*[\n\r]+} {
kono
parents:
diff changeset
229 send_log "skipping: $expect_out(buffer)"
kono
parents:
diff changeset
230 exp_continue
kono
parents:
diff changeset
231 }
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 timeout {
kono
parents:
diff changeset
234 unsupported "$testname"
kono
parents:
diff changeset
235 remote_close target
kono
parents:
diff changeset
236 return
kono
parents:
diff changeset
237 }
kono
parents:
diff changeset
238 }
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 remote_close target
kono
parents:
diff changeset
241 unsupported "$testname"
kono
parents:
diff changeset
242 return
kono
parents:
diff changeset
243 }
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 # Invoke gdb with a command and pattern-match the output.
kono
parents:
diff changeset
246 proc gdb_batch_check {command pattern} {
kono
parents:
diff changeset
247 set gdb_name $::env(GUALITY_GDB_NAME)
kono
parents:
diff changeset
248 set cmd "$gdb_name -nw -nx -quiet -batch -ex \"$command\""
kono
parents:
diff changeset
249 send_log "Spawning: $cmd\n"
kono
parents:
diff changeset
250 if [catch { set res [remote_spawn target "$cmd"] } ] {
kono
parents:
diff changeset
251 return 0
kono
parents:
diff changeset
252 }
kono
parents:
diff changeset
253 if { $res < 0 || $res == "" } {
kono
parents:
diff changeset
254 return 0
kono
parents:
diff changeset
255 }
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 remote_expect target [timeout_value] {
kono
parents:
diff changeset
258 -re $pattern {
kono
parents:
diff changeset
259 return 1
kono
parents:
diff changeset
260 }
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 -re {^[^\n\r]*[\n\r]+} {
kono
parents:
diff changeset
263 verbose "skipping: $expect_out(buffer)"
kono
parents:
diff changeset
264 exp_continue
kono
parents:
diff changeset
265 }
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 timeout {
kono
parents:
diff changeset
268 remote_close target
kono
parents:
diff changeset
269 return 0
kono
parents:
diff changeset
270 }
kono
parents:
diff changeset
271 }
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 remote_close target
kono
parents:
diff changeset
274 return 0
kono
parents:
diff changeset
275 }
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 # Check for a new-enough version of gdb. The pretty-printer tests
kono
parents:
diff changeset
278 # require gdb 7.3, but we don't want to test versions, so instead we
kono
parents:
diff changeset
279 # check for the python "lookup_global_symbol" method, which is in 7.3
kono
parents:
diff changeset
280 # but not earlier versions.
kono
parents:
diff changeset
281 # Return 1 if the version is ok, 0 otherwise.
kono
parents:
diff changeset
282 proc gdb_version_check {} {
kono
parents:
diff changeset
283 return [gdb_batch_check "python print(gdb.lookup_global_symbol)" \
kono
parents:
diff changeset
284 "<built-in function lookup_global_symbol>"]
kono
parents:
diff changeset
285 }
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 # Check for a version of gdb which supports xmethod tests. It is done
kono
parents:
diff changeset
288 # in a manner similar to the check for a version of gdb which supports the
kono
parents:
diff changeset
289 # pretty-printer tests below.
kono
parents:
diff changeset
290 proc gdb_version_check_xmethods {} {
kono
parents:
diff changeset
291 return [gdb_batch_check \
kono
parents:
diff changeset
292 "python import gdb.xmethod; print(gdb.xmethod.XMethod)" \
kono
parents:
diff changeset
293 "<class 'gdb\\.xmethod\\.XMethod'>"]
kono
parents:
diff changeset
294 }
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 # Like dg-runtest but keep the .exe around. dg-test has an option for
kono
parents:
diff changeset
297 # this but there is no way to pass it through dg-runtest.
kono
parents:
diff changeset
298 proc gdb-dg-runtest {args} {
kono
parents:
diff changeset
299 global dg-interpreter-batch-mode
kono
parents:
diff changeset
300 set saved-dg-interpreter-batch-mode ${dg-interpreter-batch-mode}
kono
parents:
diff changeset
301 set dg-interpreter-batch-mode 1
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 eval dg-runtest $args
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 set dg-interpreter-batch-mode ${saved-dg-interpreter-batch-mode}
kono
parents:
diff changeset
306 }