/:
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / ovldbreak.exp
CommitLineData
4c38e0a4 1# Copyright (C) 1998, 1999, 2001, 2004, 2007, 2008, 2009, 2010
9b254dd1 2# Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c 17# written by Elena Zannoni (ezannoni@cygnus.com)
b2bbed47 18# modified by Michael Chastain (chastain@redhat.com)
c906108c
SS
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
cec808ec
KS
26global timeout
27set timeout 15
c906108c
SS
28if $tracelevel then {
29 strace $tracelevel
30 }
31
32#
33# test running programs
34#
c906108c 35
d4f3574e
SS
36if { [skip_cplus_tests] } { continue }
37
c906108c
SS
38set testfile "ovldbreak"
39set srcfile ${testfile}.cc
40set binfile ${objdir}/${subdir}/${testfile}
41
42if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
43 untested ovldbreak.exp
44 return -1
c906108c
SS
45}
46
47gdb_exit
48gdb_start
49gdb_reinitialize_dir $srcdir/$subdir
50gdb_load ${binfile}
51
52# set it up at a breakpoint so we can play with the variable values
53#
54if ![runto_main] then {
55 perror "couldn't run to breakpoint"
56 continue
57}
58
59
60
b2bbed47
MC
61# When I ask gdb to set a breakpoint on an overloaded function,
62# gdb gives me a choice menu. I might get stuck in that choice menu
63# (for example, if C++ name mangling is not working properly).
64#
65# This procedure issues a command that works at either the menu
66# prompt or the command prompt to get back to the command prompt.
67#
68# Note that an empty line won't do it (it means 'repeat the previous command'
69# at top level). A line with a single space in it works nicely.
c906108c 70
b2bbed47
MC
71proc take_gdb_out_of_choice_menu {} {
72 global gdb_prompt
73 send_gdb " \n"
74 gdb_expect {
75 -re ".*$gdb_prompt $" {
76 }
77 timeout {
78 perror "could not resynchronize to command prompt (timeout)"
79 continue
80 }
81 }
82}
c906108c
SS
83
84
c906108c 85
b2bbed47
MC
86# This procedure sets an overloaded breakpoint.
87# When I ask for such a breakpoint, gdb gives me a menu of 'cancel' 'all'
88# and a bunch of choices. I then choose from that menu by number.
c906108c 89
b2bbed47
MC
90proc set_bp_overloaded {name expectedmenu mychoice bpnumber linenumber} {
91 global gdb_prompt hex srcfile
c906108c 92
b2bbed47
MC
93 # Get into the overload menu.
94 send_gdb "break $name\n"
95 gdb_expect {
96 -re "$expectedmenu" {
97 pass "bp menu for $name choice $mychoice"
c906108c 98
b2bbed47
MC
99 # Choose my choice.
100 send_gdb "$mychoice\n"
c906108c 101 gdb_expect {
b2bbed47
MC
102 -re "Breakpoint $bpnumber at $hex: file.*$srcfile, line $linenumber.\r\n$gdb_prompt $" {
103 pass "set bp $bpnumber on $name $mychoice line $linenumber"
104 }
105 -re ".*$gdb_prompt $" {
106 fail "set bp $bpnumber on $name $mychoice line $linenumber (bad bp)"
107 }
108 timeout {
109 fail "set bp $bpnumber on $name $mychoice line $linenumber (timeout)"
110 take_gdb_out_of_choice_menu
111 }
112 }
113 }
114 -re ".*\r\n> " {
115 fail "bp menu for $name choice $mychoice (bad menu)"
116 take_gdb_out_of_choice_menu
117 }
118 -re ".*$gdb_prompt $" {
119 fail "bp menu for $name choice $mychoice (no menu)"
120 }
121 timeout {
122 fail "bp menu for $name choice $mychoice (timeout)"
123 take_gdb_out_of_choice_menu
124 }
125 }
126}
c906108c 127
b2bbed47 128# This is the expected menu for overload1arg.
cec808ec 129# Note the arg type variations for void and integer types.
b2bbed47 130# This accommodates different versions of g++.
c906108c 131
cec808ec
KS
132set menu_overload1arg "\\\[0\\\] cancel\r\n"
133append menu_overload1arg "\\\[1\\\] all\r\n"
134append menu_overload1arg "\\\[2\\\] foo::overload1arg\\(double\\) at.*$srcfile:121\r\n"
135append menu_overload1arg "\\\[3\\\] foo::overload1arg\\(float\\) at.*$srcfile:120\r\n"
136append menu_overload1arg "\\\[4\\\] foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r\n"
137append menu_overload1arg "\\\[5\\\] foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r\n"
138append menu_overload1arg "\\\[6\\\] foo::overload1arg\\((unsigned int|unsigned)\\) at.*$srcfile:117\r\n"
139append menu_overload1arg "\\\[7\\\] foo::overload1arg\\(int\\) at.*$srcfile:116\r\n"
140append menu_overload1arg "\\\[8\\\] foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r\n"
141append menu_overload1arg "\\\[9\\\] foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r\n"
142append menu_overload1arg "\\\[10\\\] foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r\n"
143append menu_overload1arg "\\\[11\\\] foo::overload1arg\\(signed char\\) at.*$srcfile:112\r\n"
144append menu_overload1arg "\\\[12\\\] foo::overload1arg\\(char\\) at.*$srcfile:111\r\n"
145append menu_overload1arg "\\\[13\\\] foo::overload1arg\\((void|)\\) at.*$srcfile:110\r\n"
146append menu_overload1arg "> $"
c906108c 147
eae06beb
JB
148# Set multiple-symbols to "ask", to allow us to test the use
149# of the multiple-choice menu when breaking on an overloaded method.
150gdb_test "set multiple-symbols ask" ""
c906108c 151
b2bbed47 152# Set breakpoints on foo::overload1arg, one by one.
c906108c 153
b2bbed47
MC
154set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 12 2 111
155set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 11 3 112
156set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 10 4 113
157set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 9 5 114
158set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 8 6 115
159set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 7 7 116
160set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 6 8 117
161set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 5 9 118
162set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 4 10 119
163set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 3 11 120
164set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 2 12 121
165set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 13 13 110
c906108c
SS
166
167
c906108c 168
b2bbed47 169# Verify the breakpoints.
c906108c
SS
170
171gdb_test "info break" \
54e52265 172 "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*
cec808ec 173\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\r
c906108c 174\[\t \]+breakpoint already hit 1 time\r
d8937120
MC
175\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
176\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
177\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
cec808ec
KS
178\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r
179\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r
d8937120
MC
180\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
181\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
cec808ec
KS
182\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r
183\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r
d8937120
MC
184\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
185\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
186\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((void|)\\) at.*$srcfile:110" \
b2bbed47 187 "breakpoint info (after setting one-by-one)"
c906108c
SS
188
189
190
b2bbed47
MC
191# Test choice "cancel".
192# This is copy-and-paste from set_bp_overloaded.
c906108c
SS
193
194send_gdb "break foo::overload1arg\n"
195gdb_expect {
b2bbed47
MC
196 -re "$menu_overload1arg" {
197 pass "bp menu for foo::overload1arg choice cancel"
198 # Choose cancel.
199 send_gdb "0\n"
200 gdb_expect {
201 -re "canceled\r\n$gdb_prompt $" {
202 pass "set bp on overload1arg canceled"
203 }
204 -re "cancelled\r\n$gdb_prompt $" {
205 pass "set bp on overload1arg canceled"
206 }
207 -re ".*$gdb_prompt $" {
208 fail "set bp on overload1arg canceled (bad message)"
209 }
210 timeout {
211 fail "set bp on overload1arg canceled (timeout)"
212 take_gdb_out_of_choice_menu
213 }
214 }
215 }
216 -re ".*\r\n> " {
217 fail "bp menu for foo::overload1arg choice cancel (bad menu)"
218 take_gdb_out_of_choice_menu
219 }
220 -re ".*$gdb_prompt $" {
221 fail "bp menu for foo::overload1arg choice cancel (no menu)"
222 }
223 timeout {
224 fail "bp menu for foo::overload1arg choice cancel (timeout)"
225 take_gdb_out_of_choice_menu
226 }
227}
c906108c
SS
228
229gdb_test "info break" \
54e52265 230 "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*
cec808ec 231\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\r
c906108c 232\[\t \]+breakpoint already hit 1 time\r
d8937120
MC
233\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
234\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
235\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
cec808ec
KS
236\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r
237\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r
d8937120
MC
238\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
239\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
cec808ec
KS
240\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r
241\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r
d8937120
MC
242\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
243\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
244\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((void|)\\) at.*$srcfile:110" \
b2bbed47 245 "breakpoint info (after cancel)"
c906108c
SS
246
247
248
b2bbed47 249# Delete these breakpoints.
c906108c
SS
250
251send_gdb "delete breakpoints\n"
252gdb_expect {
b2bbed47 253 -re "Delete all breakpoints.* $" {
c906108c
SS
254 send_gdb "y\n"
255 gdb_expect {
256 -re ".*$gdb_prompt $" {
b2bbed47
MC
257 pass "delete all breakpoints"
258 }
259 timeout {
260 fail "delete all breakpoints (timeout)"
c906108c 261 }
c906108c
SS
262 }
263 }
b2bbed47
MC
264 timeout {
265 fail "delete all breakpoints (timeout)"
266 }
c906108c
SS
267}
268
b2bbed47 269gdb_test "info breakpoints" "No breakpoints or watchpoints." "breakpoint info (after delete)"
c906108c
SS
270
271
c906108c 272
b2bbed47
MC
273# Test choice "all".
274# This is copy-and-paste from set_bp_overloaded.
c906108c 275
b2bbed47
MC
276send_gdb "break foo::overload1arg\n"
277gdb_expect {
278 -re "$menu_overload1arg" {
279 pass "bp menu for foo::overload1arg choice all"
280 # Choose all.
281 send_gdb "1\n"
282 gdb_expect {
ab5b5d61 283 -re "Breakpoint $decimal at $hex: file.*$srcfile, line 121.\r\nBreakpoint $decimal at $hex: file.*$srcfile, line 120.\r\nBreakpoint $decimal at $hex: file.*$srcfile, line 119.\r\nBreakpoint $decimal at $hex: file.*$srcfile, line 118.\r\nBreakpoint $decimal at $hex: file.*$srcfile, line 117.\r\nBreakpoint $decimal at $hex: file.*$srcfile, line 116.\r\nBreakpoint $decimal at $hex: file.*$srcfile, line 115.\r\nBreakpoint $decimal at $hex: file.*$srcfile, line 114.\r\nBreakpoint $decimal at $hex: file.*$srcfile, line 113.\r\nBreakpoint $decimal at $hex: file.*$srcfile, line 112.\r\nBreakpoint $decimal at $hex: file.*$srcfile, line 111.\r\nBreakpoint $decimal at $hex: file.*$srcfile, line 110.\r\nwarning: Multiple breakpoints were set.\r\nUse the .delete. command to delete unwanted breakpoints.\r\n$gdb_prompt $" {
b2bbed47
MC
284 pass "set bp on overload1arg all"
285 }
286 -re ".*$gdb_prompt $" {
287 fail "set bp on overload1arg all (bad message)"
288 }
289 timeout {
290 fail "set bp on overload1arg all (timeout)"
291 take_gdb_out_of_choice_menu
292 }
293 }
294 }
295 -re ".*\r\n> " {
296 fail "bp menu for foo::overload1arg choice all (bad menu)"
297 take_gdb_out_of_choice_menu
298 }
299 -re ".*$gdb_prompt $" {
300 fail "bp menu for foo::overload1arg choice all (no menu)"
301 }
302 timeout {
303 fail "bp menu for foo::overload1arg choice all (timeout)"
304 take_gdb_out_of_choice_menu
305 }
306}
c906108c
SS
307
308gdb_test "info break" \
54e52265 309 "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*
d8937120
MC
310\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
311\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
cec808ec
KS
312\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r
313\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r
d8937120
MC
314\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
315\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
cec808ec
KS
316\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r
317\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r
d8937120
MC
318\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
319\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
320\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
321\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((void|)\\) at.*$srcfile:110" \
b2bbed47
MC
322 "breakpoint info (after setting on all)"
323
c906108c
SS
324
325
b2bbed47
MC
326# Run through each breakpoint.
327
d1fe6965
DC
328# NOTE: carlton/2003-02-03: I'm seeing failures on some of the tests,
329# with the wrong arg being printed out. Michael Chastain sees
330# failures at times, too, albeit fewer than I do.
331
332proc continue_to_bp_overloaded {might_kfail bpnumber argtype actuals} {
dfcd3bfb 333 global gdb_prompt hex decimal srcfile
b2bbed47
MC
334
335 send_gdb "continue\n"
c906108c 336 gdb_expect {
b2bbed47
MC
337 -re "Continuing.\r\n\r\nBreakpoint ${bpnumber}, (${hex} in )?foo::overload1arg(\\(${argtype}\\))? \\(this=${hex}(, )?${actuals}\\) at.*${srcfile}:${decimal}\r\n${decimal}\[\t \]+int foo::overload1arg \\(${argtype}( arg)?\\).*\r\n.*$gdb_prompt $" {
338 pass "continue to bp overloaded : ${argtype}"
339 }
d1fe6965
DC
340 -re "Continuing.\r\n\r\nBreakpoint ${bpnumber}, (${hex} in )?foo::overload1arg(\\(${argtype}\\))? \\(this=${hex}, arg=.*\\) at.*${srcfile}:${decimal}\r\n${decimal}\[\t \]+int foo::overload1arg \\(${argtype}( arg)?\\).*\r\n.*$gdb_prompt $" {
341 if $might_kfail {
342 kfail "gdb/1025" "continue to bp overloaded : ${argtype}"
343 } else {
344 fail "continue to bp overloaded : ${argtype}"
345 }
346 }
b2bbed47
MC
347 -re ".*$gdb_prompt $" {
348 fail "continue to bp overloaded : ${argtype}"
349 }
350 timeout {
351 fail "continue to bp overloaded : ${argtype} (timeout)"
352 }
c906108c 353 }
dfcd3bfb 354}
c906108c 355
d1fe6965
DC
356continue_to_bp_overloaded 0 25 "(void|)" ""
357continue_to_bp_overloaded 1 24 "char" "arg=2 \\'\\\\002\\'"
358continue_to_bp_overloaded 1 23 "signed char" "arg=3 \\'\\\\003\\'"
359continue_to_bp_overloaded 1 22 "unsigned char" "arg=4 \\'\\\\004\\'"
360continue_to_bp_overloaded 1 21 "short" "arg=5"
361continue_to_bp_overloaded 1 20 "unsigned short" "arg=6"
362continue_to_bp_overloaded 0 19 "int" "arg=7"
363continue_to_bp_overloaded 0 18 "(unsigned|unsigned int)" "arg=8"
364continue_to_bp_overloaded 0 17 "long" "arg=9"
365continue_to_bp_overloaded 0 16 "unsigned long" "arg=10"
366continue_to_bp_overloaded 0 15 "float" "arg=100"
367continue_to_bp_overloaded 1 14 "double" "arg=200"
b2bbed47 368
eae06beb
JB
369# Test breaking on an overloaded function when multiple-symbols
370# is set to "cancel"
371gdb_test "set multiple-symbols cancel" ""
372gdb_test "break foo::foofunc" \
373 "canceled.*"
374
375# Test breaking on an overloaded function when multiple-symbols
376# is set to "all"
377gdb_test "set multiple-symbols all" ""
378gdb_test "break foo::foofunc" \
379 "Breakpoint \[0-9\]+ at ${hex}: file .*ovldbreak\\.cc, line \[0-9\]+\\.\r\nBreakpoint \[0-9\]+ at ${hex}: file .*ovldbreak\\.cc, line \[0-9\]+\\.\r\nwarning: Multiple breakpoints were set\\.\r\nUse the \"delete\" command to delete unwanted breakpoints\\."
dfcd3bfb 380
b2bbed47 381# That's all, folks.
dfcd3bfb
JM
382
383gdb_continue_to_end "finish program"
This page took 0.964826 seconds and 4 git commands to generate.