1 # Copyright (C) 1997, 1998 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
21 # tests for exception-handling support
22 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
24 # This file is part of the gdb testsuite
26 # Note: These tests are geared to the HP aCC compiler,
27 # which has an idiosyncratic way of emitting debug info
28 # for exceptions -- it uses a callback mechanism, which
29 # is different from the way g++ records exception info
32 # The tests are in two parts; the first part deals with
33 # statically linked (archive-bound) executables, and the
34 # second part repeats those tests with dynamically linked
35 # (shared bound) executables. (In the latter case we use
36 # a different mechanism to get the address of the notification
37 # hook in the C++ support library.) The tests themselves are
38 # the same in both parts.
42 # IF YOU CHANGE A TEST IN ONE PART MAKE SURE YOU CHANGE IT
43 # --------------------------------------------------------
44 # IN THE OTHER PART TOO!
45 # ----------------------
53 if { [skip_hp_tests] } then { continue }
56 # test running programs
59 # Part I : Archive-bound executables
60 # ----------------------------------
62 set testfile "exception"
63 set srcfile ${testfile}.cc
64 set binfile ${objdir}/${subdir}/${testfile}
66 if [get_compiler_info ${binfile} "c++"] {
71 if { $gcc_compiled } then { continue }
73 set cmdline "$CXX_FOR_TARGET ${srcdir}/${subdir}/${srcfile} +A -Wl,-a,archive -g -o ${binfile}"
75 remote_exec build $cmdline
77 # Start with a fresh gdb
84 gdb_reinitialize_dir $srcdir/$subdir
87 if ![runto_main] then {
88 perror "couldn't run to breakpoint"
92 # Set a catch catchpoint
94 send_gdb "catch catch\n"
96 -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
97 pass "catch catch (static executable)"
99 -re ".*$gdb_prompt $" { fail "catch catch (static executable)" }
100 timeout { fail "(timeout) catch catch (static executable)" }
103 # Set a throw catchpoint
105 send_gdb "catch throw\n"
107 -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
108 pass "catch throw (static executable)"
110 -re ".*$gdb_prompt $" { fail "catch throw (static executable)" }
111 timeout { fail "(timeout) catch throw (static executable)" }
114 # The catchpoints should be listed in the list of breakpoints.
116 send_gdb "info break\n"
118 -re ".*\[0-9\]*\[ \]*catch catch\[ \]*keep y\[ \]*exception catch\[ \]*\r\n\[0-9\]*\[ \]*catch throw\[ \]*keep y\[ \]*exception throw\[ \]*\r\n$gdb_prompt $" {
119 pass "info break with catchpoints (static executable)"
121 -re ".*$gdb_prompt $" { fail "info break (static executable)" }
122 timeout { fail "(timeout) info break (static executable)" }
125 # Info catch currently does not work with HP aCC. No easy way to
126 # list the active handlers on the stack.
128 send_gdb "info catch\n"
130 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
131 pass "info catch (static executable)"
133 -re ".*$gdb_prompt $" { fail "info catch (static executable)" }
134 timeout { fail "(timeout) info catch (static executable)" }
137 # Get the first exception thrown
139 send_gdb "continue\n"
141 -re "Continuing.*Catchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
142 pass "caught a throw (static executable)"
144 -re ".*$gdb_prompt $" { fail "didn't catch a throw (static executable)" }
145 timeout { fail "(timeout) after continue -- didn't catch a throw? (static executable)" }
148 send_gdb "backtrace\n"
150 -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 $" {
151 pass "backtrace after throw (static executable)"
153 -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 $" {
154 pass "backtrace after throw (static executable)"
156 -re ".*$gdb_prompt $" { fail "backtrace after throw (static executable)" }
157 timeout { fail "(timeout) backtrace after throw (static executable)" }
160 # Now intercept it when it is caught.
162 send_gdb "continue\n"
164 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
165 pass "caught a catch (static executable)"
167 -re ".*$gdb_prompt $" { fail "didn't catch a catch (static executable)" }
168 timeout { fail "(timeout) after continue -- didn't catch a catch? (static executable)" }
171 send_gdb "backtrace\n"
173 -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 $" {
174 pass "backtrace after catch (static executable)"
176 -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 $" {
177 pass "backtrace after catch (static executable)"
179 -re ".*$gdb_prompt $" { fail "backtrace after catch (static executable)" }
180 timeout { fail "(timeout) backtrace after catch (static executable)" }
183 send_gdb "continue\n"
185 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
186 pass "caught a throw (2) (static executable)"
188 -re ".*$gdb_prompt $" { fail "didn't catch a throw (2) (static executable)" }
189 timeout { fail "(timeout) after continue -- didn't catch a throw (2)? (static executable)" }
192 send_gdb "continue\n"
194 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
195 pass "caught a catch (2) (static executable)"
197 -re ".*$gdb_prompt $" { fail "didn't catch a catch (2) (static executable)" }
198 timeout { fail "(timeout) after continue -- didn't catch a catch (2)? (static executable)" }
201 # Now the exception will be rethrown.
203 send_gdb "continue\n"
205 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
206 pass "caught a rethrow (static executable)"
208 -re ".*$gdb_prompt $" { fail "didn't catch a rethrow (static executable)" }
209 timeout { fail "(timeout) after continue -- didn't catch a rethrow? (static executable)" }
212 send_gdb "continue\n"
214 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:3\[68\], catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
215 # FIXME: guo: why XFAIL? need comment
216 xfail "caught a catch (3) (static executable)"
218 -re ".*$gdb_prompt $" { fail "didn't catch a catch (3) (static executable)" }
219 timeout { fail "(timeout) after continue -- didn't catch a catch (3)? (static executable)" }
222 send_gdb "backtrace\n"
224 -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 $" {
225 # FIXME: guo: why XFAIL? need comment
226 xfail "backtrace after catch (3) (static executable)"
228 -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 $" {
229 # FIXME: guo: why XFAIL? need comment
230 xfail "backtrace after catch (3) (static executable)"
232 -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (static executable)" }
233 timeout { fail "(timeout) backtrace after catch (3) (static executable)" }
236 # Now the exception will be thrown, but not catch-able anywhere.
238 send_gdb "continue\n"
240 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location unknown\r\n.*$gdb_prompt $" {
241 pass "caught an uncatchable throw (static executable)"
243 -re ".*$gdb_prompt $" { fail "didn't catch an uncatchable throw (static executable)" }
244 timeout { fail "(timeout) after continue -- didn't catch an uncatchable throw? (static executable)" }
247 # Part II : Shared-bound executables
248 # ----------------------------------
250 # Start with a fresh gdb
253 gdb_reinitialize_dir $srcdir/$subdir
258 set testfile "exception"
259 set srcfile ${testfile}.cc
260 set binfile ${objdir}/${subdir}/${testfile}
262 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
263 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will a
270 gdb_reinitialize_dir $srcdir/$subdir
274 if ![runto_main] then {
275 perror "couldn't run to breakpoint"
279 # Set a catch catchpoint
281 send_gdb "catch catch\n"
283 -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
284 pass "catch catch (dynamic executable)"
286 -re ".*$gdb_prompt $" { fail "catch catch (dynamic executable)" }
287 timeout { fail "(timeout) catch catch (dynamic executable)" }
290 # Set a throw catchpoint
292 send_gdb "catch throw\n"
294 -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
295 pass "catch throw (dynamic executable)"
297 -re ".*$gdb_prompt $" { fail "catch throw (dynamic executable)" }
298 timeout { fail "(timeout) catch throw (dynamic executable)" }
301 # The catchpoints should be listed in the list of breakpoints.
303 send_gdb "info break\n"
305 -re ".*\[0-9\]*\[ \]*catch catch\[ \]*keep y\[ \]*exception catch\[ \]*\r\n\[0-9\]*\[ \]*catch throw\[ \]*keep y\[ \]*exception throw\[ \]*\r\n$gdb_prompt $" {
306 pass "info break with catchpoints (dynamic executable)"
308 -re ".*$gdb_prompt $" { fail "info break (dynamic executable)" }
309 timeout { fail "(timeout) info break (dynamic executable)" }
312 # Info catch currently does not work with HP aCC. No easy way to
313 # list the active handlers on the stack.
315 send_gdb "info catch\n"
317 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
318 pass "info catch (dynamic executable)"
320 -re ".*$gdb_prompt $" { fail "info catch (dynamic executable)" }
321 timeout { fail "(timeout) info catch (dynamic executable)" }
324 # Get the first exception thrown
326 send_gdb "continue\n"
328 -re "Continuing.*Catchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
329 pass "caught a throw (dynamic executable)"
331 -re ".*$gdb_prompt $" { fail "didn't catch a throw (dynamic executable)" }
332 timeout { fail "(timeout) after continue -- didn't catch a throw? (dynamic executable)" }
335 send_gdb "backtrace\n"
337 -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 $" {
338 pass "backtrace after throw (dynamic executable)"
340 -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 $" {
341 pass "backtrace after throw (dynamic executable)"
343 -re ".*$gdb_prompt $" { fail "backtrace after throw (dynamic executable)" }
344 timeout { fail "(timeout) backtrace after throw (dynamic executable)" }
347 # Now intercept it when it is caught.
349 send_gdb "continue\n"
351 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
352 pass "caught a catch (dynamic executable)"
354 -re ".*$gdb_prompt $" { fail "didn't catch a catch (dynamic executable)" }
355 timeout { fail "(timeout) after continue -- didn't catch a catch? (dynamic executable)" }
358 send_gdb "backtrace\n"
360 -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 $" {
361 pass "backtrace after catch (dynamic executable)"
363 -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 $" {
364 pass "backtrace after catch (dynamic executable)"
366 -re ".*$gdb_prompt $" { fail "backtrace after catch (dynamic executable)" }
367 timeout { fail "(timeout) backtrace after catch (dynamic executable)" }
370 send_gdb "continue\n"
372 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
373 pass "caught a throw (2) (dynamic executable)"
375 -re ".*$gdb_prompt $" { fail "didn't catch a throw (2) (dynamic executable)" }
376 timeout { fail "(timeout) after continue -- didn't catch a throw (2)? (dynamic executable)" }
379 send_gdb "continue\n"
381 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
382 pass "caught a catch (2) (dynamic executable)"
384 -re ".*$gdb_prompt $" { fail "didn't catch a catch (2) (dynamic executable)" }
385 timeout { fail "(timeout) after continue -- didn't catch a catch (2)? (dynamic executable)" }
388 # Now the exception will be rethrown.
390 send_gdb "continue\n"
392 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
393 pass "caught a rethrow (dynamic executable)"
395 -re ".*$gdb_prompt $" { fail "didn't catch a rethrow (dynamic executable)" }
396 timeout { fail "(timeout) after continue -- didn't catch a rethrow? (dynamic executable)" }
400 #The throw location should be at line 38 instead of 36.
401 setup_xfail hppa*-*-* CLLbs14858
402 send_gdb "continue\n"
404 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:3\[68\], catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
405 # FIXME: guo: according to comment above the RE is wrong!
406 pass "caught a catch (3) (dynamic executable)"
408 -re ".*$gdb_prompt $" { fail "didn't catch a catch (3) (dynamic executable)" }
409 timeout { fail "(timeout) after continue -- didn't catch a catch (3)? (dynamic executable)" }
413 #The line number for main() should be at exception.cc:38 instead of exception.cc:36
414 setup_xfail hppa*-*-* CLLbs14858
415 send_gdb "backtrace\n"
417 -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 $" {
418 # FIXME: guo: according to comment above the RE is wrong!
419 pass "backtrace after catch (3) (dynamic executable)"
421 -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 $" {
422 # FIXME: guo: according to comment above the RE is wrong!
423 pass "backtrace after catch (3) (dynamic executable)"
425 -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (dynamic executable)" }
426 timeout { fail "(timeout) backtrace after catch (3) (dynamic executable)" }
429 # Now the exception will be thrown, but not catch-able anywhere.
431 send_gdb "continue\n"
433 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location unknown\r\n.*$gdb_prompt $" {
434 pass "caught an uncatchable throw (dynamic executable)"
436 -re ".*$gdb_prompt $" { fail "didn't catch an uncatchable throw (dynamic executable)" }
437 timeout { fail "(timeout) after continue -- didn't catch an uncatchable throw? (dynamic executable)" }