annotate libstdc++-v3/testsuite/lib/gdb-test.exp @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1 # Copyright (C) 2009-2018 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
kono
parents:
diff changeset
58 lappend gdb_tests $var $result 0
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
kono
parents:
diff changeset
67 lappend gdb_tests $var $result 1
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
kono
parents:
diff changeset
74 lappend gdb_tests $var $result whatis
kono
parents:
diff changeset
75 }
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 # Utility for testing variable values using gdb, invoked via dg-final.
kono
parents:
diff changeset
78 # Tests all tests indicated by note-test and regexp-test.
kono
parents:
diff changeset
79 #
kono
parents:
diff changeset
80 # Argument 0 is the marker on which to put a breakpoint
kono
parents:
diff changeset
81 # Argument 2 handles expected failures and the like
kono
parents:
diff changeset
82 proc gdb-test { marker {selector {}} {load_xmethods 0} } {
kono
parents:
diff changeset
83 if { ![isnative] || [is_remote target] } { return }
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 if {[string length $selector] > 0} {
kono
parents:
diff changeset
86 switch [dg-process-target $selector] {
kono
parents:
diff changeset
87 "S" { }
kono
parents:
diff changeset
88 "N" { return }
kono
parents:
diff changeset
89 "F" { setup_xfail "*-*-*" }
kono
parents:
diff changeset
90 "P" { }
kono
parents:
diff changeset
91 }
kono
parents:
diff changeset
92 }
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 set do_whatis_tests [gdb_batch_check "python print(gdb.type_printers)" \
kono
parents:
diff changeset
95 "\\\[\\\]"]
kono
parents:
diff changeset
96 if {!$do_whatis_tests} {
kono
parents:
diff changeset
97 send_log "skipping 'whatis' tests - gdb too old"
kono
parents:
diff changeset
98 }
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 # This assumes that we are three frames down from dg-test, and that
kono
parents:
diff changeset
101 # it still stores the filename of the testcase in a local variable "name".
kono
parents:
diff changeset
102 # A cleaner solution would require a new DejaGnu release.
kono
parents:
diff changeset
103 upvar 2 name testcase
kono
parents:
diff changeset
104 upvar 2 prog prog
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 set line [get_line_number $prog $marker]
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 set gdb_name $::env(GUALITY_GDB_NAME)
kono
parents:
diff changeset
109 set testname "$testcase"
kono
parents:
diff changeset
110 set output_file "[file rootname [file tail $prog]].exe"
kono
parents:
diff changeset
111 set cmd_file "[file rootname [file tail $prog]].gdb"
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 global srcdir
kono
parents:
diff changeset
114 set printer_code [file join $srcdir .. python libstdcxx v6 printers.py]
kono
parents:
diff changeset
115 set xmethod_code [file join $srcdir .. python libstdcxx v6 xmethods.py]
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 global gdb_tests
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 set fd [open $cmd_file "w"]
kono
parents:
diff changeset
120 # We don't want the system copy of the pretty-printers loaded
kono
parents:
diff changeset
121 puts $fd "set auto-load no"
kono
parents:
diff changeset
122 # Now that we've disabled auto-load, it's safe to set the target file
kono
parents:
diff changeset
123 puts $fd "file ./$output_file"
kono
parents:
diff changeset
124 # Load & register *our* copy of the pretty-printers
kono
parents:
diff changeset
125 puts $fd "source $printer_code"
kono
parents:
diff changeset
126 puts $fd "python register_libstdcxx_printers(None)"
kono
parents:
diff changeset
127 if { $load_xmethods } {
kono
parents:
diff changeset
128 # Load a& register xmethods.
kono
parents:
diff changeset
129 puts $fd "source $xmethod_code"
kono
parents:
diff changeset
130 puts $fd "python register_libstdcxx_xmethods(None)"
kono
parents:
diff changeset
131 }
kono
parents:
diff changeset
132 # And start the program
kono
parents:
diff changeset
133 puts $fd "break $line"
kono
parents:
diff changeset
134 puts $fd "run"
kono
parents:
diff changeset
135 # So we can verify that we're using the right libs ...
kono
parents:
diff changeset
136 puts $fd "info share"
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 set count 0
kono
parents:
diff changeset
139 foreach {var result kind} $gdb_tests {
kono
parents:
diff changeset
140 incr count
kono
parents:
diff changeset
141 set gdb_var($count) $var
kono
parents:
diff changeset
142 set gdb_expected($count) $result
kono
parents:
diff changeset
143 if {$kind == "whatis"} {
kono
parents:
diff changeset
144 if {$do_whatis_tests} {
kono
parents:
diff changeset
145 set gdb_is_type($count) 1
kono
parents:
diff changeset
146 set gdb_command($count) "whatis $var"
kono
parents:
diff changeset
147 } else {
kono
parents:
diff changeset
148 unsupported "$testname"
kono
parents:
diff changeset
149 close $fd
kono
parents:
diff changeset
150 return
kono
parents:
diff changeset
151 }
kono
parents:
diff changeset
152 } else {
kono
parents:
diff changeset
153 set gdb_is_type($count) 0
kono
parents:
diff changeset
154 set gdb_is_regexp($count) $kind
kono
parents:
diff changeset
155 set gdb_command($count) "print $var"
kono
parents:
diff changeset
156 }
kono
parents:
diff changeset
157 puts $fd $gdb_command($count)
kono
parents:
diff changeset
158 }
kono
parents:
diff changeset
159 set gdb_tests {}
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 puts $fd "quit"
kono
parents:
diff changeset
162 close $fd
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 set res [remote_spawn target "$gdb_name -nx -nw -quiet -batch -x $cmd_file "]
kono
parents:
diff changeset
165 if { $res < 0 || $res == "" } {
kono
parents:
diff changeset
166 unsupported "$testname"
kono
parents:
diff changeset
167 return
kono
parents:
diff changeset
168 }
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 set test_counter 0
kono
parents:
diff changeset
171 remote_expect target [timeout_value] {
kono
parents:
diff changeset
172 -re {^(type|\$([0-9]+)) = ([^\n\r]*)[\n\r]+} {
kono
parents:
diff changeset
173 send_log "got: $expect_out(buffer)"
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 incr test_counter
kono
parents:
diff changeset
176 set first $expect_out(3,string)
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 if {$gdb_is_type($test_counter)} {
kono
parents:
diff changeset
179 if {$expect_out(1,string) != "type"} {
kono
parents:
diff changeset
180 error "gdb failure"
kono
parents:
diff changeset
181 }
kono
parents:
diff changeset
182 set match [expr {![string compare $first \
kono
parents:
diff changeset
183 $gdb_expected($test_counter)]}]
kono
parents:
diff changeset
184 } elseif {$gdb_is_regexp($test_counter)} {
kono
parents:
diff changeset
185 set match [regexp -- $gdb_expected($test_counter) $first]
kono
parents:
diff changeset
186 } else {
kono
parents:
diff changeset
187 set match [expr {![string compare $first \
kono
parents:
diff changeset
188 $gdb_expected($test_counter)]}]
kono
parents:
diff changeset
189 }
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 if {$match} {
kono
parents:
diff changeset
192 pass "$testname $gdb_command($test_counter)"
kono
parents:
diff changeset
193 } else {
kono
parents:
diff changeset
194 fail "$testname $gdb_command($test_counter)"
kono
parents:
diff changeset
195 verbose " got =>$first<="
kono
parents:
diff changeset
196 verbose "expected =>$gdb_expected($test_counter)<="
kono
parents:
diff changeset
197 }
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 if {$test_counter == $count} {
kono
parents:
diff changeset
200 remote_close target
kono
parents:
diff changeset
201 return
kono
parents:
diff changeset
202 } else {
kono
parents:
diff changeset
203 exp_continue
kono
parents:
diff changeset
204 }
kono
parents:
diff changeset
205 }
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 -re {Python scripting is not supported in this copy of GDB.[\n\r]+} {
kono
parents:
diff changeset
208 unsupported "$testname"
kono
parents:
diff changeset
209 remote_close target
kono
parents:
diff changeset
210 return
kono
parents:
diff changeset
211 }
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 -re {Error while executing Python code.[\n\r]} {
kono
parents:
diff changeset
214 fail "$testname"
kono
parents:
diff changeset
215 remote_close target
kono
parents:
diff changeset
216 return
kono
parents:
diff changeset
217 }
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 -re {^[^$][^\n\r]*[\n\r]+} {
kono
parents:
diff changeset
220 send_log "skipping: $expect_out(buffer)"
kono
parents:
diff changeset
221 exp_continue
kono
parents:
diff changeset
222 }
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 timeout {
kono
parents:
diff changeset
225 unsupported "$testname"
kono
parents:
diff changeset
226 remote_close target
kono
parents:
diff changeset
227 return
kono
parents:
diff changeset
228 }
kono
parents:
diff changeset
229 }
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 remote_close target
kono
parents:
diff changeset
232 unsupported "$testname"
kono
parents:
diff changeset
233 return
kono
parents:
diff changeset
234 }
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 # Invoke gdb with a command and pattern-match the output.
kono
parents:
diff changeset
237 proc gdb_batch_check {command pattern} {
kono
parents:
diff changeset
238 set gdb_name $::env(GUALITY_GDB_NAME)
kono
parents:
diff changeset
239 set cmd "$gdb_name -nw -nx -quiet -batch -ex \"$command\""
kono
parents:
diff changeset
240 send_log "Spawning: $cmd\n"
kono
parents:
diff changeset
241 if [catch { set res [remote_spawn target "$cmd"] } ] {
kono
parents:
diff changeset
242 return 0
kono
parents:
diff changeset
243 }
kono
parents:
diff changeset
244 if { $res < 0 || $res == "" } {
kono
parents:
diff changeset
245 return 0
kono
parents:
diff changeset
246 }
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 remote_expect target [timeout_value] {
kono
parents:
diff changeset
249 -re $pattern {
kono
parents:
diff changeset
250 return 1
kono
parents:
diff changeset
251 }
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 -re {^[^\n\r]*[\n\r]+} {
kono
parents:
diff changeset
254 verbose "skipping: $expect_out(buffer)"
kono
parents:
diff changeset
255 exp_continue
kono
parents:
diff changeset
256 }
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 timeout {
kono
parents:
diff changeset
259 remote_close target
kono
parents:
diff changeset
260 return 0
kono
parents:
diff changeset
261 }
kono
parents:
diff changeset
262 }
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 remote_close target
kono
parents:
diff changeset
265 return 0
kono
parents:
diff changeset
266 }
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 # Check for a new-enough version of gdb. The pretty-printer tests
kono
parents:
diff changeset
269 # require gdb 7.3, but we don't want to test versions, so instead we
kono
parents:
diff changeset
270 # check for the python "lookup_global_symbol" method, which is in 7.3
kono
parents:
diff changeset
271 # but not earlier versions.
kono
parents:
diff changeset
272 # Return 1 if the version is ok, 0 otherwise.
kono
parents:
diff changeset
273 proc gdb_version_check {} {
kono
parents:
diff changeset
274 return [gdb_batch_check "python print(gdb.lookup_global_symbol)" \
kono
parents:
diff changeset
275 "<built-in function lookup_global_symbol>"]
kono
parents:
diff changeset
276 }
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 # Check for a version of gdb which supports xmethod tests. It is done
kono
parents:
diff changeset
279 # in a manner similar to the check for a version of gdb which supports the
kono
parents:
diff changeset
280 # pretty-printer tests below.
kono
parents:
diff changeset
281 proc gdb_version_check_xmethods {} {
kono
parents:
diff changeset
282 return [gdb_batch_check \
kono
parents:
diff changeset
283 "python import gdb.xmethod; print(gdb.xmethod.XMethod)" \
kono
parents:
diff changeset
284 "<class 'gdb\\.xmethod\\.XMethod'>"]
kono
parents:
diff changeset
285 }
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 # Like dg-runtest but keep the .exe around. dg-test has an option for
kono
parents:
diff changeset
288 # this but there is no way to pass it through dg-runtest.
kono
parents:
diff changeset
289 proc gdb-dg-runtest {args} {
kono
parents:
diff changeset
290 global dg-interpreter-batch-mode
kono
parents:
diff changeset
291 set saved-dg-interpreter-batch-mode ${dg-interpreter-batch-mode}
kono
parents:
diff changeset
292 set dg-interpreter-batch-mode 1
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 eval dg-runtest $args
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 set dg-interpreter-batch-mode ${saved-dg-interpreter-batch-mode}
kono
parents:
diff changeset
297 }