Switch the license of all .exp files to GPLv3.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / ovldbreak.exp
CommitLineData
6aba47ca 1# Copyright (C) 1998, 1999, 2001, 2004, 2007 Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c 16# written by Elena Zannoni (ezannoni@cygnus.com)
b2bbed47 17# modified by Michael Chastain (chastain@redhat.com)
c906108c
SS
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
26if $tracelevel then {
27 strace $tracelevel
28 }
29
30#
31# test running programs
32#
33set prms_id 0
34set bug_id 0
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
MC
128# This is the expected menu for overload1arg.
129# Note the arg type variations on lines 6 and 13.
130# This accommodates different versions of g++.
c906108c 131
b2bbed47 132set 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 133
c906108c
SS
134
135
b2bbed47 136# Set breakpoints on foo::overload1arg, one by one.
c906108c 137
b2bbed47
MC
138set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 12 2 111
139set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 11 3 112
140set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 10 4 113
141set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 9 5 114
142set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 8 6 115
143set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 7 7 116
144set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 6 8 117
145set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 5 9 118
146set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 4 10 119
147set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 3 11 120
148set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 2 12 121
149set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 13 13 110
c906108c
SS
150
151
c906108c 152
b2bbed47 153# Verify the breakpoints.
c906108c
SS
154
155gdb_test "info break" \
156 "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*
d8937120 157\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main at.*$srcfile:49\r
c906108c 158\[\t \]+breakpoint already hit 1 time\r
d8937120
MC
159\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
160\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
161\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
162\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short\\) at.*$srcfile:114\r
163\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r
164\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
165\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
166\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long\\) at.*$srcfile:118\r
167\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r
168\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
169\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
170\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((void|)\\) at.*$srcfile:110" \
b2bbed47 171 "breakpoint info (after setting one-by-one)"
c906108c
SS
172
173
174
b2bbed47
MC
175# Test choice "cancel".
176# This is copy-and-paste from set_bp_overloaded.
c906108c
SS
177
178send_gdb "break foo::overload1arg\n"
179gdb_expect {
b2bbed47
MC
180 -re "$menu_overload1arg" {
181 pass "bp menu for foo::overload1arg choice cancel"
182 # Choose cancel.
183 send_gdb "0\n"
184 gdb_expect {
185 -re "canceled\r\n$gdb_prompt $" {
186 pass "set bp on overload1arg canceled"
187 }
188 -re "cancelled\r\n$gdb_prompt $" {
189 pass "set bp on overload1arg canceled"
190 }
191 -re ".*$gdb_prompt $" {
192 fail "set bp on overload1arg canceled (bad message)"
193 }
194 timeout {
195 fail "set bp on overload1arg canceled (timeout)"
196 take_gdb_out_of_choice_menu
197 }
198 }
199 }
200 -re ".*\r\n> " {
201 fail "bp menu for foo::overload1arg choice cancel (bad menu)"
202 take_gdb_out_of_choice_menu
203 }
204 -re ".*$gdb_prompt $" {
205 fail "bp menu for foo::overload1arg choice cancel (no menu)"
206 }
207 timeout {
208 fail "bp menu for foo::overload1arg choice cancel (timeout)"
209 take_gdb_out_of_choice_menu
210 }
211}
c906108c
SS
212
213gdb_test "info break" \
214 "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*
d8937120 215\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main at.*$srcfile:49\r
c906108c 216\[\t \]+breakpoint already hit 1 time\r
d8937120
MC
217\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
218\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
219\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
220\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short\\) at.*$srcfile:114\r
221\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r
222\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
223\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
224\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long\\) at.*$srcfile:118\r
225\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r
226\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
227\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
228\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((void|)\\) at.*$srcfile:110" \
b2bbed47 229 "breakpoint info (after cancel)"
c906108c
SS
230
231
232
b2bbed47 233# Delete these breakpoints.
c906108c
SS
234
235send_gdb "delete breakpoints\n"
236gdb_expect {
b2bbed47 237 -re "Delete all breakpoints.* $" {
c906108c
SS
238 send_gdb "y\n"
239 gdb_expect {
240 -re ".*$gdb_prompt $" {
b2bbed47
MC
241 pass "delete all breakpoints"
242 }
243 timeout {
244 fail "delete all breakpoints (timeout)"
c906108c 245 }
c906108c
SS
246 }
247 }
b2bbed47
MC
248 timeout {
249 fail "delete all breakpoints (timeout)"
250 }
c906108c
SS
251}
252
b2bbed47 253gdb_test "info breakpoints" "No breakpoints or watchpoints." "breakpoint info (after delete)"
c906108c
SS
254
255
c906108c 256
b2bbed47
MC
257# Test choice "all".
258# This is copy-and-paste from set_bp_overloaded.
c906108c 259
b2bbed47
MC
260send_gdb "break foo::overload1arg\n"
261gdb_expect {
262 -re "$menu_overload1arg" {
263 pass "bp menu for foo::overload1arg choice all"
264 # Choose all.
265 send_gdb "1\n"
266 gdb_expect {
ab5b5d61 267 -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
268 pass "set bp on overload1arg all"
269 }
270 -re ".*$gdb_prompt $" {
271 fail "set bp on overload1arg all (bad message)"
272 }
273 timeout {
274 fail "set bp on overload1arg all (timeout)"
275 take_gdb_out_of_choice_menu
276 }
277 }
278 }
279 -re ".*\r\n> " {
280 fail "bp menu for foo::overload1arg choice all (bad menu)"
281 take_gdb_out_of_choice_menu
282 }
283 -re ".*$gdb_prompt $" {
284 fail "bp menu for foo::overload1arg choice all (no menu)"
285 }
286 timeout {
287 fail "bp menu for foo::overload1arg choice all (timeout)"
288 take_gdb_out_of_choice_menu
289 }
290}
c906108c
SS
291
292gdb_test "info break" \
293 "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*
d8937120
MC
294\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
295\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
296\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r
297\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long\\) at.*$srcfile:118\r
298\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
299\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
300\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r
301\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short\\) at.*$srcfile:114\r
302\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
303\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
304\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
305\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((void|)\\) at.*$srcfile:110" \
b2bbed47
MC
306 "breakpoint info (after setting on all)"
307
c906108c
SS
308
309
b2bbed47
MC
310# Run through each breakpoint.
311
d1fe6965
DC
312# NOTE: carlton/2003-02-03: I'm seeing failures on some of the tests,
313# with the wrong arg being printed out. Michael Chastain sees
314# failures at times, too, albeit fewer than I do.
315
316proc continue_to_bp_overloaded {might_kfail bpnumber argtype actuals} {
dfcd3bfb 317 global gdb_prompt hex decimal srcfile
b2bbed47
MC
318
319 send_gdb "continue\n"
c906108c 320 gdb_expect {
b2bbed47
MC
321 -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 $" {
322 pass "continue to bp overloaded : ${argtype}"
323 }
d1fe6965
DC
324 -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 $" {
325 if $might_kfail {
326 kfail "gdb/1025" "continue to bp overloaded : ${argtype}"
327 } else {
328 fail "continue to bp overloaded : ${argtype}"
329 }
330 }
b2bbed47
MC
331 -re ".*$gdb_prompt $" {
332 fail "continue to bp overloaded : ${argtype}"
333 }
334 timeout {
335 fail "continue to bp overloaded : ${argtype} (timeout)"
336 }
c906108c 337 }
dfcd3bfb 338}
c906108c 339
d1fe6965
DC
340continue_to_bp_overloaded 0 25 "(void|)" ""
341continue_to_bp_overloaded 1 24 "char" "arg=2 \\'\\\\002\\'"
342continue_to_bp_overloaded 1 23 "signed char" "arg=3 \\'\\\\003\\'"
343continue_to_bp_overloaded 1 22 "unsigned char" "arg=4 \\'\\\\004\\'"
344continue_to_bp_overloaded 1 21 "short" "arg=5"
345continue_to_bp_overloaded 1 20 "unsigned short" "arg=6"
346continue_to_bp_overloaded 0 19 "int" "arg=7"
347continue_to_bp_overloaded 0 18 "(unsigned|unsigned int)" "arg=8"
348continue_to_bp_overloaded 0 17 "long" "arg=9"
349continue_to_bp_overloaded 0 16 "unsigned long" "arg=10"
350continue_to_bp_overloaded 0 15 "float" "arg=100"
351continue_to_bp_overloaded 1 14 "double" "arg=200"
b2bbed47
MC
352
353
dfcd3bfb 354
b2bbed47 355# That's all, folks.
dfcd3bfb
JM
356
357gdb_continue_to_end "finish program"
This page took 0.727687 seconds and 4 git commands to generate.