1 # Copyright 1997, 1998, 2004 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
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
25 # tests for exception-handling support
26 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
28 # This file is part of the gdb testsuite
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
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.
46 # IF YOU CHANGE A TEST IN ONE PART MAKE SURE YOU CHANGE IT
47 # --------------------------------------------------------
48 # IN THE OTHER PART TOO!
49 # ----------------------
57 if { [skip_hp_tests] } then { continue }
60 # test running programs
63 # Part I : Archive-bound executables
64 # ----------------------------------
66 set testfile "exception"
67 set srcfile ${testfile}.cc
68 set binfile ${objdir}/${subdir}/${testfile}
70 if [get_compiler_info ${binfile} "c++"] {
75 if { $gcc_compiled } then { continue }
77 set cmdline "$CXX_FOR_TARGET ${srcdir}/${subdir}/${srcfile} +A -Wl,-a,archive -g -o ${binfile}"
79 remote_exec build $cmdline
81 # Start with a fresh gdb
88 gdb_reinitialize_dir $srcdir/$subdir
91 if ![runto_main] then {
92 perror "couldn't run to breakpoint"
96 # Set a catch catchpoint
98 send_gdb "catch catch\n"
100 -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
101 pass "catch catch (static executable)"
103 -re ".*$gdb_prompt $" { fail "catch catch (static executable)" }
104 timeout { fail "(timeout) catch catch (static executable)" }
107 # Set a throw catchpoint
109 send_gdb "catch throw\n"
111 -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
112 pass "catch throw (static executable)"
114 -re ".*$gdb_prompt $" { fail "catch throw (static executable)" }
115 timeout { fail "(timeout) catch throw (static executable)" }
118 # The catchpoints should be listed in the list of breakpoints.
120 send_gdb "info break\n"
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)"
125 -re ".*$gdb_prompt $" { fail "info break (static executable)" }
126 timeout { fail "(timeout) info break (static executable)" }
129 # Info catch currently does not work with HP aCC. No easy way to
130 # list the active handlers on the stack.
132 send_gdb "info catch\n"
134 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
135 pass "info catch (static executable)"
137 -re ".*$gdb_prompt $" { fail "info catch (static executable)" }
138 timeout { fail "(timeout) info catch (static executable)" }
141 # Get the first exception thrown
143 send_gdb "continue\n"
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)"
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)" }
152 send_gdb "backtrace\n"
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)"
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)"
160 -re ".*$gdb_prompt $" { fail "backtrace after throw (static executable)" }
161 timeout { fail "(timeout) backtrace after throw (static executable)" }
164 # Now intercept it when it is caught.
166 send_gdb "continue\n"
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)"
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)" }
175 send_gdb "backtrace\n"
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)"
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)"
183 -re ".*$gdb_prompt $" { fail "backtrace after catch (static executable)" }
184 timeout { fail "(timeout) backtrace after catch (static executable)" }
187 send_gdb "continue\n"
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)"
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)" }
196 send_gdb "continue\n"
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)"
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)" }
205 # Now the exception will be rethrown.
207 send_gdb "continue\n"
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)"
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)" }
216 send_gdb "continue\n"
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)"
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)" }
226 send_gdb "backtrace\n"
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)"
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)"
236 -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (static executable)" }
237 timeout { fail "(timeout) backtrace after catch (3) (static executable)" }
240 # Now the exception will be thrown, but not catch-able anywhere.
242 send_gdb "continue\n"
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)"
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)" }
251 # Part II : Shared-bound executables
252 # ----------------------------------
254 # Start with a fresh gdb
257 gdb_reinitialize_dir $srcdir/$subdir
262 set testfile "exception"
263 set srcfile ${testfile}.cc
264 set binfile ${objdir}/${subdir}/${testfile}
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
274 gdb_reinitialize_dir $srcdir/$subdir
278 if ![runto_main] then {
279 perror "couldn't run to breakpoint"
283 # Set a catch catchpoint
285 send_gdb "catch catch\n"
287 -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
288 pass "catch catch (dynamic executable)"
290 -re ".*$gdb_prompt $" { fail "catch catch (dynamic executable)" }
291 timeout { fail "(timeout) catch catch (dynamic executable)" }
294 # Set a throw catchpoint
296 send_gdb "catch throw\n"
298 -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
299 pass "catch throw (dynamic executable)"
301 -re ".*$gdb_prompt $" { fail "catch throw (dynamic executable)" }
302 timeout { fail "(timeout) catch throw (dynamic executable)" }
305 # The catchpoints should be listed in the list of breakpoints.
307 send_gdb "info break\n"
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)"
312 -re ".*$gdb_prompt $" { fail "info break (dynamic executable)" }
313 timeout { fail "(timeout) info break (dynamic executable)" }
316 # Info catch currently does not work with HP aCC. No easy way to
317 # list the active handlers on the stack.
319 send_gdb "info catch\n"
321 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
322 pass "info catch (dynamic executable)"
324 -re ".*$gdb_prompt $" { fail "info catch (dynamic executable)" }
325 timeout { fail "(timeout) info catch (dynamic executable)" }
328 # Get the first exception thrown
330 send_gdb "continue\n"
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)"
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)" }
339 send_gdb "backtrace\n"
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)"
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)"
347 -re ".*$gdb_prompt $" { fail "backtrace after throw (dynamic executable)" }
348 timeout { fail "(timeout) backtrace after throw (dynamic executable)" }
351 # Now intercept it when it is caught.
353 send_gdb "continue\n"
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)"
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)" }
362 send_gdb "backtrace\n"
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)"
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)"
370 -re ".*$gdb_prompt $" { fail "backtrace after catch (dynamic executable)" }
371 timeout { fail "(timeout) backtrace after catch (dynamic executable)" }
374 send_gdb "continue\n"
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)"
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)" }
383 send_gdb "continue\n"
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)"
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)" }
392 # Now the exception will be rethrown.
394 send_gdb "continue\n"
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)"
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)" }
404 #The throw location should be at line 38 instead of 36.
405 setup_xfail hppa*-*-* CLLbs14858
406 send_gdb "continue\n"
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)"
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)" }
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"
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)"
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)"
429 -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (dynamic executable)" }
430 timeout { fail "(timeout) backtrace after catch (3) (dynamic executable)" }
433 # Now the exception will be thrown, but not catch-able anywhere.
435 send_gdb "continue\n"
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)"
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)" }