Don't handle timeout inside gdb_test_multiple
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / ovldbreak.exp
1 # Copyright (C) 1998-2016 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # written by Elena Zannoni (ezannoni@cygnus.com)
17 # modified by Michael Chastain (chastain@redhat.com)
18
19 # This file is part of the gdb testsuite
20 #
21 # tests for overloaded member functions. Set breakpoints on
22 # overloaded member functions
23 #
24
25 global timeout
26 set timeout 15
27 #
28 # test running programs
29 #
30
31 if { [skip_cplus_tests] } { continue }
32
33 standard_testfile .cc
34
35 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
36 return -1
37 }
38
39 # set it up at a breakpoint so we can play with the variable values
40 #
41 if {![runto_main]} {
42 perror "couldn't run to breakpoint"
43 continue
44 }
45
46 # When I ask gdb to set a breakpoint on an overloaded function,
47 # gdb gives me a choice menu. I might get stuck in that choice menu
48 # (for example, if C++ name mangling is not working properly).
49 #
50 # This procedure issues a command that works at either the menu
51 # prompt or the command prompt to get back to the command prompt.
52 #
53 # Note that an empty line won't do it (it means 'repeat the previous command'
54 # at top level). A line with a single space in it works nicely.
55
56 proc take_gdb_out_of_choice_menu {} {
57 global gdb_prompt
58 gdb_test_multiple " " " " {
59 -re ".*$gdb_prompt $" {
60 }
61 }
62 }
63
64
65
66 # This procedure sets an overloaded breakpoint.
67 # When I ask for such a breakpoint, gdb gives me a menu of 'cancel' 'all'
68 # and a bunch of choices. I then choose from that menu by number.
69
70 proc set_bp_overloaded {name expectedmenu mychoice bpnumber linenumber} {
71 global gdb_prompt hex srcfile
72
73 # Get into the overload menu.
74 send_gdb "break $name\n"
75 gdb_expect {
76 -re "$expectedmenu" {
77 pass "bp menu for $name choice $mychoice"
78
79 # Choose my choice.
80 send_gdb "$mychoice\n"
81 gdb_expect {
82 -re "Breakpoint $bpnumber at $hex: file.*$srcfile, line $linenumber.\r\n$gdb_prompt $" {
83 pass "set bp $bpnumber on $name $mychoice line $linenumber"
84 }
85 -re ".*$gdb_prompt $" {
86 fail "set bp $bpnumber on $name $mychoice line $linenumber (bad bp)"
87 }
88 timeout {
89 fail "set bp $bpnumber on $name $mychoice line $linenumber (timeout)"
90 take_gdb_out_of_choice_menu
91 }
92 }
93 }
94 -re ".*\r\n> " {
95 fail "bp menu for $name choice $mychoice (bad menu)"
96 take_gdb_out_of_choice_menu
97 }
98 -re ".*$gdb_prompt $" {
99 fail "bp menu for $name choice $mychoice (no menu)"
100 }
101 timeout {
102 fail "bp menu for $name choice $mychoice (timeout)"
103 take_gdb_out_of_choice_menu
104 }
105 }
106 }
107
108 # Compute the expected menu for overload1arg.
109 # Note the arg type variations for void and integer types.
110 # This accommodates different versions of g++.
111
112 # Probe for the real types. This will do some unnecessary checking
113 # for some simple types (like "int"), but it's just easier to loop
114 # over all_types instead of calling out just the exceptions.
115 # This list /must/ remain in the same order that the methods are
116 # called in the source code. Otherwise the order in which breakpoints
117 # are hit (tested below) will be incorrect.
118 set all_types [list void char signed_char unsigned_char short_int \
119 unsigned_short_int int unsigned_int long_int \
120 unsigned_long_int float double]
121
122 # ARGUMENTS is an array that will map from synthetic type to argument
123 # expressions in the source code, which is of the form "arg = $decimal".
124 # ARGUMENTS stores this decimal number.
125 array set arguments {
126 void ""
127 char 2
128 signed_char 3
129 unsigned_char 4
130 short_int 5
131 unsigned_short_int 6
132 int 7
133 unsigned_int 8
134 long_int 9
135 unsigned_long_int 10
136 float 100(.0)?
137 double 200(.0)?
138 }
139
140 unset -nocomplain line types
141 foreach type $all_types {
142 # TYPES is an array that maps the synthetic names in ALL_TYPES
143 # to the real type used in the debugger. These will be checked
144 # below and changed if the debugger thinks they are different from
145 # their default values.
146 set types($type) [join [split $type "_"] " "]
147
148 # LINE is an array that will map from synthetic type to line number.
149 # in the source code.
150 set line($type) [gdb_get_line_number "fo1 $type"]
151
152 # Probe for the actual type.
153 gdb_test_multiple "print &foo::overload1arg($types($type))" \
154 "probe $types($type)" {
155 -re ".*\<foo::.*\>.*$gdb_prompt $" {
156 regexp {<.*>} $expect_out(0,string) func
157 regexp {\(.*\)} $func real_type
158
159 # Store the real type into TYPES.
160 set types($type) [string trim $real_type {()}]
161
162 # Create an inverse mapping of the actual type to
163 # the synthetic type.
164 set type_map("$types($type)") $type
165 pass "detect $type"
166 }
167 }
168 }
169
170 # This is a list of the actual overloaded method arguments.
171 set overloads {}
172 foreach type $all_types {
173 lappend overloads $types($type)
174 }
175
176 # Sort this list alphabetically.
177 set overloads [lsort $overloads]
178
179 # Create the menu list.
180 set items {"cancel" "all"}
181 foreach ovld $overloads {
182 lappend items "$srcfile:foo::overload1arg\\($ovld\\)"
183 }
184 set menu_items {}
185 set idx 0
186 foreach item $items {
187 lappend menu_items ".$idx. .*$item"
188 incr idx
189 }
190 set menu_overload1arg [join $menu_items {[\r\n]*}]
191 append menu_overload1arg {[\r\n]*> $}
192
193 # Set multiple-symbols to "ask", to allow us to test the use
194 # of the multiple-choice menu when breaking on an overloaded method.
195 gdb_test_no_output "set multiple-symbols ask"
196
197 # Set breakpoints on foo::overload1arg, one by one.
198 set bpnum 1
199 set method "foo::overload1arg"
200 for {set idx 0} {$idx < [llength $overloads]} {incr idx} {
201 set type [lindex $overloads $idx]
202 set_bp_overloaded $method $menu_overload1arg \
203 [expr {$idx + 2}] [incr bpnum] $line($type_map("$type"))
204 }
205
206 # Verify the breakpoints.
207 set bptable "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*"
208 append bptable "\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\[\r\n\]+"
209 append bptable "\[\t \]+breakpoint already hit 1 time\[\r\n\]+"
210 foreach ovld $overloads {
211 append bptable [format "\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(%s\\) at.*$srcfile:%d\[\r\n\]+" $ovld \
212 $line($type_map("$ovld"))]
213 }
214 gdb_test "info break" $bptable "breakpoint info (after setting one-by-one)"
215
216 # Test choice "cancel".
217 # This is copy-and-paste from set_bp_overloaded.
218
219 send_gdb "break foo::overload1arg\n"
220 gdb_expect {
221 -re "$menu_overload1arg" {
222 pass "bp menu for foo::overload1arg choice cancel"
223 # Choose cancel.
224 send_gdb "0\n"
225 gdb_expect {
226 -re "canceled\r\n$gdb_prompt $" {
227 pass "set bp on overload1arg canceled"
228 }
229 -re "cancelled\r\n$gdb_prompt $" {
230 pass "set bp on overload1arg canceled"
231 }
232 -re ".*$gdb_prompt $" {
233 fail "set bp on overload1arg canceled (bad message)"
234 }
235 timeout {
236 fail "set bp on overload1arg canceled (timeout)"
237 take_gdb_out_of_choice_menu
238 }
239 }
240 }
241 -re ".*\r\n> " {
242 fail "bp menu for foo::overload1arg choice cancel (bad menu)"
243 take_gdb_out_of_choice_menu
244 }
245 -re ".*$gdb_prompt $" {
246 fail "bp menu for foo::overload1arg choice cancel (no menu)"
247 }
248 timeout {
249 fail "bp menu for foo::overload1arg choice cancel (timeout)"
250 take_gdb_out_of_choice_menu
251 }
252 }
253
254 gdb_test "info break" $bptable "breakpoint info (after cancel)"
255
256 # Delete these breakpoints.
257
258 send_gdb "delete breakpoints\n"
259 gdb_expect {
260 -re "Delete all breakpoints.* $" {
261 send_gdb "y\n"
262 gdb_expect {
263 -re ".*$gdb_prompt $" {
264 pass "delete all breakpoints"
265 }
266 timeout {
267 fail "delete all breakpoints (timeout)"
268 }
269 }
270 }
271 timeout {
272 fail "delete all breakpoints (timeout)"
273 }
274 }
275
276 gdb_test "info breakpoints" "No breakpoints or watchpoints." "breakpoint info (after delete)"
277
278
279
280 # Test choice "all".
281 # This is copy-and-paste from set_bp_overloaded.
282
283 send_gdb "break foo::overload1arg\n"
284 gdb_expect {
285 -re "$menu_overload1arg" {
286 pass "bp menu for foo::overload1arg choice all"
287 # Choose all.
288 send_gdb "1\n"
289 gdb_expect {
290 -re "Breakpoint $decimal at $hex: foo::overload1arg. .12 locations.\r\n.*$gdb_prompt $" {
291 pass "set bp on overload1arg all"
292 }
293 -re ".*$gdb_prompt $" {
294 fail "set bp on overload1arg all (bad message)"
295 }
296 timeout {
297 fail "set bp on overload1arg all (timeout)"
298 take_gdb_out_of_choice_menu
299 }
300 }
301 }
302 -re ".*\r\n> " {
303 fail "bp menu for foo::overload1arg choice all (bad menu)"
304 take_gdb_out_of_choice_menu
305 }
306 -re ".*$gdb_prompt $" {
307 fail "bp menu for foo::overload1arg choice all (no menu)"
308 }
309 timeout {
310 fail "bp menu for foo::overload1arg choice all (timeout)"
311 take_gdb_out_of_choice_menu
312 }
313 }
314
315 # Create the breakpoint table for "info breakpoint".
316 set bptable "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*\[\r\n]+"
317 append bptable "\[0-9\]+\[\t \]+breakpoint\[\t \]+keep\[\t \]y\[\t \]+<MULTIPLE>.*\[\r\n\]+"
318 foreach ovld {void char signed_char unsigned_char short_int \
319 unsigned_short_int int unsigned_int long_int \
320 unsigned_long_int float double} {
321 append bptable [format "\[0-9\]+.\[0-9\]+\[\t \]+y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(%s\\) at.*$srcfile:%d\[\r\n\]+" \
322 $types($ovld) $line($ovld)]
323 }
324
325 gdb_test "info break" $bptable "breakpoint info (after setting on all)"
326
327 # Run through each breakpoint.
328 proc continue_to_bp_overloaded {bpnumber might_fail line argtype argument} {
329 global gdb_prompt hex decimal srcfile
330
331 if {$argument == ""} {
332 set actuals ""
333 } else {
334 set actuals "arg=$argument"
335 if {[regexp {char} $argtype]} {
336 append actuals " \\'\\\\00$argument\\'"
337 }
338 }
339
340 if {[string match $argtype "void"]} {
341 set body "return $decimal;"
342 } else {
343 set body "arg = 0; return $decimal;"
344 }
345
346 gdb_test_multiple "continue" "continue to bp overloaded : $argtype" {
347 -re "Continuing.\r\n\r\nBreakpoint $bpnumber, foo::overload1arg \\(this=${hex}(, )?$actuals\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" {
348 pass "continue to bp overloaded : $argtype"
349 }
350
351 -re "Continuing.\r\n\r\nBreakpoint $bpnumber, foo::overload1arg \\(this=${hex}, arg=.*\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" {
352 if $might_kfail {
353 kfail "c++/8130" "continue to bp overloaded : $argtype"
354 } else {
355 fail "continue to bp overloaded : $argtype"
356 }
357 }
358 }
359 }
360
361 # An array which describes which of these methods might be expected
362 # to kfail on GCC 2.95. See C++/8210.
363 array set might_fail {
364 void 0
365 char 1
366 signed_char 1
367 unsigned_char 1
368 short_int 1
369 unsigned_short_int 1
370 int 0
371 unsigned_int 0
372 long_int 0
373 unsigned_long_int 0
374 float 0
375 double 1
376 }
377
378 foreach type $all_types {
379 continue_to_bp_overloaded 14 $might_fail($type) $line($type) \
380 $type $arguments($type)
381 }
382
383 # Test breaking on an overloaded function when multiple-symbols
384 # is set to "cancel"
385 gdb_test_no_output "set multiple-symbols cancel"
386 gdb_test "break foo::foofunc" \
387 "canceled.*"
388
389 # Test breaking on an overloaded function when multiple-symbols
390 # is set to "all"
391 gdb_test_no_output "set multiple-symbols all"
392 gdb_test "break foo::foofunc" \
393 "Breakpoint \[0-9\]+ at ${hex}: foo::foofunc. .2 locations..*"
394
395 # That's all, folks.
396
397 unset -nocomplain line types
398 gdb_continue_to_end "finish program"
This page took 0.037711 seconds and 4 git commands to generate.