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 ${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 ".*$gdb_prompt $" { fail "backtrace after throw (static executable)" }
154 timeout { fail "(timeout) backtrace after throw (static executable)" }
157 # Now intercept it when it is caught.
159 send_gdb "continue\n"
161 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
162 pass "caught a catch (static executable)"
164 -re ".*$gdb_prompt $" { fail "didn't catch a catch (static executable)" }
165 timeout { fail "(timeout) after continue -- didn't catch a catch? (static executable)" }
168 send_gdb "backtrace\n"
170 -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 $" {
171 pass "backtrace after catch (static executable)"
173 -re ".*$gdb_prompt $" { fail "backtrace after catch (static executable)" }
174 timeout { fail "(timeout) backtrace after catch (static executable)" }
177 send_gdb "continue\n"
179 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
180 pass "caught a throw (2) (static executable)"
182 -re ".*$gdb_prompt $" { fail "didn't catch a throw (2) (static executable)" }
183 timeout { fail "(timeout) after continue -- didn't catch a throw (2)? (static executable)" }
186 send_gdb "continue\n"
188 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
189 pass "caught a catch (2) (static executable)"
191 -re ".*$gdb_prompt $" { fail "didn't catch a catch (2) (static executable)" }
192 timeout { fail "(timeout) after continue -- didn't catch a catch (2)? (static executable)" }
195 # Now the exception will be rethrown.
197 send_gdb "continue\n"
199 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
200 pass "caught a rethrow (static executable)"
202 -re ".*$gdb_prompt $" { fail "didn't catch a rethrow (static executable)" }
203 timeout { fail "(timeout) after continue -- didn't catch a rethrow? (static executable)" }
206 send_gdb "continue\n"
208 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
209 pass "caught a catch (3) (static executable)"
211 -re ".*$gdb_prompt $" { fail "didn't catch a catch (3) (static executable)" }
212 timeout { fail "(timeout) after continue -- didn't catch a catch (3)? (static executable)" }
215 send_gdb "backtrace\n"
217 -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:38\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 $" {
218 pass "backtrace after catch (3) (static executable)"
220 -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (static executable)" }
221 timeout { fail "(timeout) backtrace after catch (3) (static executable)" }
224 # Now the exception will be thrown, but not catch-able anywhere.
226 send_gdb "continue\n"
228 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location unknown\r\n.*$gdb_prompt $" {
229 pass "caught an uncatchable throw (static executable)"
231 -re ".*$gdb_prompt $" { fail "didn't catch an uncatchable throw (static executable)" }
232 timeout { fail "(timeout) after continue -- didn't catch an uncatchable throw? (static executable)" }
235 # Part II : Shared-bound executables
236 # ----------------------------------
238 # Start with a fresh gdb
241 gdb_reinitialize_dir $srcdir/$subdir
246 set testfile "exception"
247 set srcfile ${testfile}.cc
248 set binfile ${objdir}/${subdir}/${testfile}
250 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
251 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will a
258 gdb_reinitialize_dir $srcdir/$subdir
262 if ![runto_main] then {
263 perror "couldn't run to breakpoint"
267 # Set a catch catchpoint
269 send_gdb "catch catch\n"
271 -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
272 pass "catch catch (dynamic executable)"
274 -re ".*$gdb_prompt $" { fail "catch catch (dynamic executable)" }
275 timeout { fail "(timeout) catch catch (dynamic executable)" }
278 # Set a throw catchpoint
280 send_gdb "catch throw\n"
282 -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
283 pass "catch throw (dynamic executable)"
285 -re ".*$gdb_prompt $" { fail "catch throw (dynamic executable)" }
286 timeout { fail "(timeout) catch throw (dynamic executable)" }
289 # The catchpoints should be listed in the list of breakpoints.
291 send_gdb "info break\n"
293 -re ".*\[0-9\]*\[ \]*catch catch\[ \]*keep y\[ \]*exception catch\[ \]*\r\n\[0-9\]*\[ \]*catch throw\[ \]*keep y\[ \]*exception throw\[ \]*\r\n$gdb_prompt $" {
294 pass "info break with catchpoints (dynamic executable)"
296 -re ".*$gdb_prompt $" { fail "info break (dynamic executable)" }
297 timeout { fail "(timeout) info break (dynamic executable)" }
300 # Info catch currently does not work with HP aCC. No easy way to
301 # list the active handlers on the stack.
303 send_gdb "info catch\n"
305 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
306 pass "info catch (dynamic executable)"
308 -re ".*$gdb_prompt $" { fail "info catch (dynamic executable)" }
309 timeout { fail "(timeout) info catch (dynamic executable)" }
312 # Get the first exception thrown
314 send_gdb "continue\n"
316 -re "Continuing.*Catchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
317 pass "caught a throw (dynamic executable)"
319 -re ".*$gdb_prompt $" { fail "didn't catch a throw (dynamic executable)" }
320 timeout { fail "(timeout) after continue -- didn't catch a throw? (dynamic executable)" }
323 send_gdb "backtrace\n"
325 -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 $" {
326 pass "backtrace after throw (dynamic executable)"
328 -re ".*$gdb_prompt $" { fail "backtrace after throw (dynamic executable)" }
329 timeout { fail "(timeout) backtrace after throw (dynamic executable)" }
332 # Now intercept it when it is caught.
334 send_gdb "continue\n"
336 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
337 pass "caught a catch (dynamic executable)"
339 -re ".*$gdb_prompt $" { fail "didn't catch a catch (dynamic executable)" }
340 timeout { fail "(timeout) after continue -- didn't catch a catch? (dynamic executable)" }
343 send_gdb "backtrace\n"
345 -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 $" {
346 pass "backtrace after catch (dynamic executable)"
348 -re ".*$gdb_prompt $" { fail "backtrace after catch (dynamic executable)" }
349 timeout { fail "(timeout) backtrace after catch (dynamic executable)" }
352 send_gdb "continue\n"
354 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
355 pass "caught a throw (2) (dynamic executable)"
357 -re ".*$gdb_prompt $" { fail "didn't catch a throw (2) (dynamic executable)" }
358 timeout { fail "(timeout) after continue -- didn't catch a throw (2)? (dynamic executable)" }
361 send_gdb "continue\n"
363 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
364 pass "caught a catch (2) (dynamic executable)"
366 -re ".*$gdb_prompt $" { fail "didn't catch a catch (2) (dynamic executable)" }
367 timeout { fail "(timeout) after continue -- didn't catch a catch (2)? (dynamic executable)" }
370 # Now the exception will be rethrown.
372 send_gdb "continue\n"
374 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
375 pass "caught a rethrow (dynamic executable)"
377 -re ".*$gdb_prompt $" { fail "didn't catch a rethrow (dynamic executable)" }
378 timeout { fail "(timeout) after continue -- didn't catch a rethrow? (dynamic executable)" }
381 send_gdb "continue\n"
383 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
384 pass "caught a catch (3) (dynamic executable)"
386 -re ".*$gdb_prompt $" { fail "didn't catch a catch (3) (dynamic executable)" }
387 timeout { fail "(timeout) after continue -- didn't catch a catch (3)? (dynamic executable)" }
390 send_gdb "backtrace\n"
392 -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:38\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 $" {
393 pass "backtrace after catch (3) (dynamic executable)"
395 -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (dynamic executable)" }
396 timeout { fail "(timeout) backtrace after catch (3) (dynamic executable)" }
399 # Now the exception will be thrown, but not catch-able anywhere.
401 send_gdb "continue\n"
403 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location unknown\r\n.*$gdb_prompt $" {
404 pass "caught an uncatchable throw (dynamic executable)"
406 -re ".*$gdb_prompt $" { fail "didn't catch an uncatchable throw (dynamic executable)" }
407 timeout { fail "(timeout) after continue -- didn't catch an uncatchable throw? (dynamic executable)" }