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