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