2004-01-08 Michael Chastain <mec.gnu@mindspring.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / exception.exp
1 # Copyright 1997, 1998, 2004 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # Note: every line number in this file is too low by 21,
21 # because I added a copyright notice to exception.cc.
22 # -- chastain 2004-01-08
23
24 #
25 # tests for exception-handling support
26 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
27
28 # This file is part of the gdb testsuite
29
30 # Note: These tests are geared to the HP aCC compiler,
31 # which has an idiosyncratic way of emitting debug info
32 # for exceptions -- it uses a callback mechanism, which
33 # is different from the way g++ records exception info
34 # for debugging
35
36 # The tests are in two parts; the first part deals with
37 # statically linked (archive-bound) executables, and the
38 # second part repeats those tests with dynamically linked
39 # (shared bound) executables. (In the latter case we use
40 # a different mechanism to get the address of the notification
41 # hook in the C++ support library.) The tests themselves are
42 # the same in both parts.
43 #
44 # IMPORTANT:
45 # ---------
46 # IF YOU CHANGE A TEST IN ONE PART MAKE SURE YOU CHANGE IT
47 # --------------------------------------------------------
48 # IN THE OTHER PART TOO!
49 # ----------------------
50
51
52
53 if $tracelevel then {
54 strace $tracelevel
55 }
56
57 if { [skip_hp_tests] } then { continue }
58
59 #
60 # test running programs
61 #
62
63 # Part I : Archive-bound executables
64 # ----------------------------------
65
66 set testfile "exception"
67 set srcfile ${testfile}.cc
68 set binfile ${objdir}/${subdir}/${testfile}
69
70 if [get_compiler_info ${binfile} "c++"] {
71 return -1;
72 }
73
74
75 if { $gcc_compiled } then { continue }
76
77 set cmdline "$CXX_FOR_TARGET ${srcdir}/${subdir}/${srcfile} +A -Wl,-a,archive -g -o ${binfile}"
78
79 remote_exec build $cmdline
80
81 # Start with a fresh gdb
82
83 set prms_id 0
84 set bug_id 0
85
86 gdb_exit
87 gdb_start
88 gdb_reinitialize_dir $srcdir/$subdir
89 gdb_load ${binfile}
90
91 if ![runto_main] then {
92 perror "couldn't run to breakpoint"
93 continue
94 }
95
96 # Set a catch catchpoint
97
98 send_gdb "catch catch\n"
99 gdb_expect {
100 -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
101 pass "catch catch (static executable)"
102 }
103 -re ".*$gdb_prompt $" { fail "catch catch (static executable)" }
104 timeout { fail "(timeout) catch catch (static executable)" }
105 }
106
107 # Set a throw catchpoint
108
109 send_gdb "catch throw\n"
110 gdb_expect {
111 -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
112 pass "catch throw (static executable)"
113 }
114 -re ".*$gdb_prompt $" { fail "catch throw (static executable)" }
115 timeout { fail "(timeout) catch throw (static executable)" }
116 }
117
118 # The catchpoints should be listed in the list of breakpoints.
119
120 send_gdb "info break\n"
121 gdb_expect {
122 -re ".*\[0-9\]*\[ \]*catch catch\[ \]*keep y\[ \]*exception catch\[ \]*\r\n\[0-9\]*\[ \]*catch throw\[ \]*keep y\[ \]*exception throw\[ \]*\r\n$gdb_prompt $" {
123 pass "info break with catchpoints (static executable)"
124 }
125 -re ".*$gdb_prompt $" { fail "info break (static executable)" }
126 timeout { fail "(timeout) info break (static executable)" }
127 }
128
129 # Info catch currently does not work with HP aCC. No easy way to
130 # list the active handlers on the stack.
131
132 send_gdb "info catch\n"
133 gdb_expect {
134 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
135 pass "info catch (static executable)"
136 }
137 -re ".*$gdb_prompt $" { fail "info catch (static executable)" }
138 timeout { fail "(timeout) info catch (static executable)" }
139 }
140
141 # Get the first exception thrown
142
143 send_gdb "continue\n"
144 gdb_expect {
145 -re "Continuing.*Catchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
146 pass "caught a throw (static executable)"
147 }
148 -re ".*$gdb_prompt $" { fail "didn't catch a throw (static executable)" }
149 timeout { fail "(timeout) after continue -- didn't catch a throw? (static executable)" }
150 }
151
152 send_gdb "backtrace\n"
153 gdb_expect {
154 -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=__EH_NOTIFY_THROW.*\r\n#2\[ \]*$hex in __eh_notify_throw.*\r\n#3\[ \]*$hex in foo \\(i=20\\) at .*exception\\.cc:8\r\n#4\[ \]*$hex in main.* at .*exception\\.cc:26\r\n$gdb_prompt $" {
155 pass "backtrace after throw (static executable)"
156 }
157 -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=\[0-9\].*\r\n#2\[ \]*$hex in __eh_notify_throw.*\r\n#3\[ \]*$hex in foo \\(i=20\\) at .*exception\\.cc:8\r\n#4\[ \]*$hex in main.* at .*exception\\.cc:26\r\n$gdb_prompt $" {
158 pass "backtrace after throw (static executable)"
159 }
160 -re ".*$gdb_prompt $" { fail "backtrace after throw (static executable)" }
161 timeout { fail "(timeout) backtrace after throw (static executable)" }
162 }
163
164 # Now intercept it when it is caught.
165
166 send_gdb "continue\n"
167 gdb_expect {
168 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
169 pass "caught a catch (static executable)"
170 }
171 -re ".*$gdb_prompt $" { fail "didn't catch a catch (static executable)" }
172 timeout { fail "(timeout) after continue -- didn't catch a catch? (static executable)" }
173 }
174
175 send_gdb "backtrace\n"
176 gdb_expect {
177 -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=__EH_NOTIFY_CATCH.*\r\n.*\r\n#3\[ \]*$hex in __throw__.*\r\n#4\[ \]*$hex in foo \\(i=20\\) at .*exception.cc:8\r\n#5\[ \]*$hex in main.* at .*exception.cc:26\r\n$gdb_prompt $" {
178 pass "backtrace after catch (static executable)"
179 }
180 -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=\[0-9\].*\r\n.*\r\n#3\[ \]*$hex in __throw__.*\r\n#4\[ \]*$hex in foo \\(i=20\\) at .*exception.cc:8\r\n#5\[ \]*$hex in main.* at .*exception.cc:26\r\n$gdb_prompt $" {
181 pass "backtrace after catch (static executable)"
182 }
183 -re ".*$gdb_prompt $" { fail "backtrace after catch (static executable)" }
184 timeout { fail "(timeout) backtrace after catch (static executable)" }
185 }
186
187 send_gdb "continue\n"
188 gdb_expect {
189 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
190 pass "caught a throw (2) (static executable)"
191 }
192 -re ".*$gdb_prompt $" { fail "didn't catch a throw (2) (static executable)" }
193 timeout { fail "(timeout) after continue -- didn't catch a throw (2)? (static executable)" }
194 }
195
196 send_gdb "continue\n"
197 gdb_expect {
198 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
199 pass "caught a catch (2) (static executable)"
200 }
201 -re ".*$gdb_prompt $" { fail "didn't catch a catch (2) (static executable)" }
202 timeout { fail "(timeout) after continue -- didn't catch a catch (2)? (static executable)" }
203 }
204
205 # Now the exception will be rethrown.
206
207 send_gdb "continue\n"
208 gdb_expect {
209 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
210 pass "caught a rethrow (static executable)"
211 }
212 -re ".*$gdb_prompt $" { fail "didn't catch a rethrow (static executable)" }
213 timeout { fail "(timeout) after continue -- didn't catch a rethrow? (static executable)" }
214 }
215
216 send_gdb "continue\n"
217 gdb_expect {
218 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:3\[68\], catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
219 # FIXME: guo: why XFAIL? need comment
220 xfail "caught a catch (3) (static executable)"
221 }
222 -re ".*$gdb_prompt $" { fail "didn't catch a catch (3) (static executable)" }
223 timeout { fail "(timeout) after continue -- didn't catch a catch (3)? (static executable)" }
224 }
225
226 send_gdb "backtrace\n"
227 gdb_expect {
228 -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=__EH_NOTIFY_CATCH.*\r\n.*\r\n#3\[ \]*$hex in __rethrow.*\r\n#4\[ \]*$hex in main.* at .*exception\\.cc:3\[68\]\r\n#5\[ \]*$hex in foo \\(i=20\\) at .*exception.cc:8\r\n#6\[ \]*$hex in main.* at .*exception.cc:34\r\n$gdb_prompt $" {
229 # FIXME: guo: why XFAIL? need comment
230 xfail "backtrace after catch (3) (static executable)"
231 }
232 -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=\[0-9\].*\r\n.*\r\n#3\[ \]*$hex in __rethrow.*\r\n#4\[ \]*$hex in main.* at .*exception\\.cc:3\[68\]\r\n#5\[ \]*$hex in foo \\(i=20\\) at .*exception.cc:8\r\n#6\[ \]*$hex in main.* at .*exception.cc:34\r\n$gdb_prompt $" {
233 # FIXME: guo: why XFAIL? need comment
234 xfail "backtrace after catch (3) (static executable)"
235 }
236 -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (static executable)" }
237 timeout { fail "(timeout) backtrace after catch (3) (static executable)" }
238 }
239
240 # Now the exception will be thrown, but not catch-able anywhere.
241
242 send_gdb "continue\n"
243 gdb_expect {
244 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location unknown\r\n.*$gdb_prompt $" {
245 pass "caught an uncatchable throw (static executable)"
246 }
247 -re ".*$gdb_prompt $" { fail "didn't catch an uncatchable throw (static executable)" }
248 timeout { fail "(timeout) after continue -- didn't catch an uncatchable throw? (static executable)" }
249 }
250
251 # Part II : Shared-bound executables
252 # ----------------------------------
253
254 # Start with a fresh gdb
255 gdb_exit
256 gdb_start
257 gdb_reinitialize_dir $srcdir/$subdir
258
259 set prms_id 0
260 set bug_id 0
261
262 set testfile "exception"
263 set srcfile ${testfile}.cc
264 set binfile ${objdir}/${subdir}/${testfile}
265
266 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
267 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will a
268 utomatically fail."
269 }
270
271
272 gdb_exit
273 gdb_start
274 gdb_reinitialize_dir $srcdir/$subdir
275 gdb_load ${binfile}
276
277
278 if ![runto_main] then {
279 perror "couldn't run to breakpoint"
280 continue
281 }
282
283 # Set a catch catchpoint
284
285 send_gdb "catch catch\n"
286 gdb_expect {
287 -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
288 pass "catch catch (dynamic executable)"
289 }
290 -re ".*$gdb_prompt $" { fail "catch catch (dynamic executable)" }
291 timeout { fail "(timeout) catch catch (dynamic executable)" }
292 }
293
294 # Set a throw catchpoint
295
296 send_gdb "catch throw\n"
297 gdb_expect {
298 -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
299 pass "catch throw (dynamic executable)"
300 }
301 -re ".*$gdb_prompt $" { fail "catch throw (dynamic executable)" }
302 timeout { fail "(timeout) catch throw (dynamic executable)" }
303 }
304
305 # The catchpoints should be listed in the list of breakpoints.
306
307 send_gdb "info break\n"
308 gdb_expect {
309 -re ".*\[0-9\]*\[ \]*catch catch\[ \]*keep y\[ \]*exception catch\[ \]*\r\n\[0-9\]*\[ \]*catch throw\[ \]*keep y\[ \]*exception throw\[ \]*\r\n$gdb_prompt $" {
310 pass "info break with catchpoints (dynamic executable)"
311 }
312 -re ".*$gdb_prompt $" { fail "info break (dynamic executable)" }
313 timeout { fail "(timeout) info break (dynamic executable)" }
314 }
315
316 # Info catch currently does not work with HP aCC. No easy way to
317 # list the active handlers on the stack.
318
319 send_gdb "info catch\n"
320 gdb_expect {
321 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
322 pass "info catch (dynamic executable)"
323 }
324 -re ".*$gdb_prompt $" { fail "info catch (dynamic executable)" }
325 timeout { fail "(timeout) info catch (dynamic executable)" }
326 }
327
328 # Get the first exception thrown
329
330 send_gdb "continue\n"
331 gdb_expect {
332 -re "Continuing.*Catchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
333 pass "caught a throw (dynamic executable)"
334 }
335 -re ".*$gdb_prompt $" { fail "didn't catch a throw (dynamic executable)" }
336 timeout { fail "(timeout) after continue -- didn't catch a throw? (dynamic executable)" }
337 }
338
339 send_gdb "backtrace\n"
340 gdb_expect {
341 -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=__EH_NOTIFY_THROW.*\r\n#2\[ \]*$hex in __eh_notify_throw.*\r\n#3\[ \]*$hex in foo \\(i=20\\) at .*exception\\.cc:8\r\n#4\[ \]*$hex in main.* at .*exception\\.cc:26\r\n$gdb_prompt $" {
342 pass "backtrace after throw (dynamic executable)"
343 }
344 -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=\[0-9\].*\r\n#2\[ \]*$hex in __eh_notify_throw.*\r\n#3\[ \]*$hex in foo \\(i=20\\) at .*exception\\.cc:8\r\n#4\[ \]*$hex in main.* at .*exception\\.cc:26\r\n$gdb_prompt $" {
345 pass "backtrace after throw (dynamic executable)"
346 }
347 -re ".*$gdb_prompt $" { fail "backtrace after throw (dynamic executable)" }
348 timeout { fail "(timeout) backtrace after throw (dynamic executable)" }
349 }
350
351 # Now intercept it when it is caught.
352
353 send_gdb "continue\n"
354 gdb_expect {
355 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
356 pass "caught a catch (dynamic executable)"
357 }
358 -re ".*$gdb_prompt $" { fail "didn't catch a catch (dynamic executable)" }
359 timeout { fail "(timeout) after continue -- didn't catch a catch? (dynamic executable)" }
360 }
361
362 send_gdb "backtrace\n"
363 gdb_expect {
364 -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=__EH_NOTIFY_CATCH.*\r\n.*\r\n#3\[ \]*$hex in __throw__.*\r\n#4\[ \]*$hex in foo \\(i=20\\) at .*exception.cc:8\r\n#5\[ \]*$hex in main.* at .*exception.cc:26\r\n$gdb_prompt $" {
365 pass "backtrace after catch (dynamic executable)"
366 }
367 -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=\[0-9\].*\r\n.*\r\n#3\[ \]*$hex in __throw__.*\r\n#4\[ \]*$hex in foo \\(i=20\\) at .*exception.cc:8\r\n#5\[ \]*$hex in main.* at .*exception.cc:26\r\n$gdb_prompt $" {
368 pass "backtrace after catch (dynamic executable)"
369 }
370 -re ".*$gdb_prompt $" { fail "backtrace after catch (dynamic executable)" }
371 timeout { fail "(timeout) backtrace after catch (dynamic executable)" }
372 }
373
374 send_gdb "continue\n"
375 gdb_expect {
376 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
377 pass "caught a throw (2) (dynamic executable)"
378 }
379 -re ".*$gdb_prompt $" { fail "didn't catch a throw (2) (dynamic executable)" }
380 timeout { fail "(timeout) after continue -- didn't catch a throw (2)? (dynamic executable)" }
381 }
382
383 send_gdb "continue\n"
384 gdb_expect {
385 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
386 pass "caught a catch (2) (dynamic executable)"
387 }
388 -re ".*$gdb_prompt $" { fail "didn't catch a catch (2) (dynamic executable)" }
389 timeout { fail "(timeout) after continue -- didn't catch a catch (2)? (dynamic executable)" }
390 }
391
392 # Now the exception will be rethrown.
393
394 send_gdb "continue\n"
395 gdb_expect {
396 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
397 pass "caught a rethrow (dynamic executable)"
398 }
399 -re ".*$gdb_prompt $" { fail "didn't catch a rethrow (dynamic executable)" }
400 timeout { fail "(timeout) after continue -- didn't catch a rethrow? (dynamic executable)" }
401 }
402
403 #DTS CLLbs14858
404 #The throw location should be at line 38 instead of 36.
405 setup_xfail hppa*-*-* CLLbs14858
406 send_gdb "continue\n"
407 gdb_expect {
408 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:3\[68\], catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
409 # FIXME: guo: according to comment above the RE is wrong!
410 pass "caught a catch (3) (dynamic executable)"
411 }
412 -re ".*$gdb_prompt $" { fail "didn't catch a catch (3) (dynamic executable)" }
413 timeout { fail "(timeout) after continue -- didn't catch a catch (3)? (dynamic executable)" }
414 }
415
416 #DTS CLLbs14858
417 #The line number for main() should be at exception.cc:38 instead of exception.cc:36
418 setup_xfail hppa*-*-* CLLbs14858
419 send_gdb "backtrace\n"
420 gdb_expect {
421 -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=__EH_NOTIFY_CATCH.*\r\n.*\r\n#3\[ \]*$hex in __rethrow.*\r\n#4\[ \]*$hex in main.* at .*exception\\.cc:3\[68\]\r\n#5\[ \]*$hex in foo \\(i=20\\) at .*exception.cc:8\r\n#6\[ \]*$hex in main.* at .*exception.cc:34\r\n$gdb_prompt $" {
422 # FIXME: guo: according to comment above the RE is wrong!
423 pass "backtrace after catch (3) (dynamic executable)"
424 }
425 -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=\[0-9\].*\r\n.*\r\n#3\[ \]*$hex in __rethrow.*\r\n#4\[ \]*$hex in main.* at .*exception\\.cc:3\[68\]\r\n#5\[ \]*$hex in foo \\(i=20\\) at .*exception.cc:8\r\n#6\[ \]*$hex in main.* at .*exception.cc:34\r\n$gdb_prompt $" {
426 # FIXME: guo: according to comment above the RE is wrong!
427 pass "backtrace after catch (3) (dynamic executable)"
428 }
429 -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (dynamic executable)" }
430 timeout { fail "(timeout) backtrace after catch (3) (dynamic executable)" }
431 }
432
433 # Now the exception will be thrown, but not catch-able anywhere.
434
435 send_gdb "continue\n"
436 gdb_expect {
437 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location unknown\r\n.*$gdb_prompt $" {
438 pass "caught an uncatchable throw (dynamic executable)"
439 }
440 -re ".*$gdb_prompt $" { fail "didn't catch an uncatchable throw (dynamic executable)" }
441 timeout { fail "(timeout) after continue -- didn't catch an uncatchable throw? (dynamic executable)" }
442 }
443
This page took 0.039628 seconds and 5 git commands to generate.