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 # ----------------------
55 # test running programs
58 # Part I : Archive-bound executables
59 # ----------------------------------
61 set testfile "exception"
62 set srcfile ${testfile}.cc
63 set binfile ${objdir}/${subdir}/${testfile}
65 if [get_compiler_info ${binfile} "c++"] {
70 if {[skip_hp_tests $gcc_compiled]} then { continue }
72 set cmdline "$CXX ${srcdir}/${subdir}/${srcfile} +A -Wl,-a,archive -g -o ${binfile}"
74 remote_exec build $cmdline
76 # Start with a fresh gdb
83 gdb_reinitialize_dir $srcdir/$subdir
86 if ![runto_main] then {
87 perror "couldn't run to breakpoint"
91 # Set a catch catchpoint
93 send_gdb "catch catch\n"
95 -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
96 pass "catch catch (static executable)"
98 -re ".*$gdb_prompt $" { fail "catch catch (static executable)" }
99 timeout { fail "(timeout) catch catch (static executable)" }
102 # Set a throw catchpoint
104 send_gdb "catch throw\n"
106 -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
107 pass "catch throw (static executable)"
109 -re ".*$gdb_prompt $" { fail "catch throw (static executable)" }
110 timeout { fail "(timeout) catch throw (static executable)" }
113 # The catchpoints should be listed in the list of breakpoints.
115 send_gdb "info break\n"
117 -re ".*\[0-9\]*\[ \]*catch catch\[ \]*keep y\[ \]*exception catch\[ \]*\r\n\[0-9\]*\[ \]*catch throw\[ \]*keep y\[ \]*exception throw\[ \]*\r\n$gdb_prompt $" {
118 pass "info break with catchpoints (static executable)"
120 -re ".*$gdb_prompt $" { fail "info break (static executable)" }
121 timeout { fail "(timeout) info break (static executable)" }
124 # Info catch currently does not work with HP aCC. No easy way to
125 # list the active handlers on the stack.
127 send_gdb "info catch\n"
129 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
130 pass "info catch (static executable)"
132 -re ".*$gdb_prompt $" { fail "info catch (static executable)" }
133 timeout { fail "(timeout) info catch (static executable)" }
136 # Get the first exception thrown
138 send_gdb "continue\n"
140 -re "Continuing.*Catchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
141 pass "caught a throw (static executable)"
143 -re ".*$gdb_prompt $" { fail "didn't catch a throw (static executable)" }
144 timeout { fail "(timeout) after continue -- didn't catch a throw? (static executable)" }
147 send_gdb "backtrace\n"
149 -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 $" {
150 pass "backtrace after throw (static executable)"
152 -re ".*$gdb_prompt $" { fail "backtrace after throw (static executable)" }
153 timeout { fail "(timeout) backtrace after throw (static executable)" }
156 # Now intercept it when it is caught.
158 send_gdb "continue\n"
160 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
161 pass "caught a catch (static executable)"
163 -re ".*$gdb_prompt $" { fail "didn't catch a catch (static executable)" }
164 timeout { fail "(timeout) after continue -- didn't catch a catch? (static executable)" }
167 send_gdb "backtrace\n"
169 -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 $" {
170 pass "backtrace after catch (static executable)"
172 -re ".*$gdb_prompt $" { fail "backtrace after catch (static executable)" }
173 timeout { fail "(timeout) backtrace after catch (static executable)" }
176 send_gdb "continue\n"
178 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
179 pass "caught a throw (2) (static executable)"
181 -re ".*$gdb_prompt $" { fail "didn't catch a throw (2) (static executable)" }
182 timeout { fail "(timeout) after continue -- didn't catch a throw (2)? (static executable)" }
185 send_gdb "continue\n"
187 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
188 pass "caught a catch (2) (static executable)"
190 -re ".*$gdb_prompt $" { fail "didn't catch a catch (2) (static executable)" }
191 timeout { fail "(timeout) after continue -- didn't catch a catch (2)? (static executable)" }
194 # Now the exception will be rethrown.
196 send_gdb "continue\n"
198 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
199 pass "caught a rethrow (static executable)"
201 -re ".*$gdb_prompt $" { fail "didn't catch a rethrow (static executable)" }
202 timeout { fail "(timeout) after continue -- didn't catch a rethrow? (static executable)" }
205 send_gdb "continue\n"
207 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
208 pass "caught a catch (3) (static executable)"
210 -re ".*$gdb_prompt $" { fail "didn't catch a catch (3) (static executable)" }
211 timeout { fail "(timeout) after continue -- didn't catch a catch (3)? (static executable)" }
214 send_gdb "backtrace\n"
216 -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 $" {
217 pass "backtrace after catch (3) (static executable)"
219 -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (static executable)" }
220 timeout { fail "(timeout) backtrace after catch (3) (static executable)" }
223 # Now the exception will be thrown, but not catch-able anywhere.
225 send_gdb "continue\n"
227 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location unknown\r\n.*$gdb_prompt $" {
228 pass "caught an uncatchable throw (static executable)"
230 -re ".*$gdb_prompt $" { fail "didn't catch an uncatchable throw (static executable)" }
231 timeout { fail "(timeout) after continue -- didn't catch an uncatchable throw? (static executable)" }
234 # Part II : Shared-bound executables
235 # ----------------------------------
237 # Start with a fresh gdb
240 gdb_reinitialize_dir $srcdir/$subdir
245 set testfile "exception"
246 set srcfile ${testfile}.cc
247 set binfile ${objdir}/${subdir}/${testfile}
249 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
250 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will a
257 gdb_reinitialize_dir $srcdir/$subdir
261 if ![runto_main] then {
262 perror "couldn't run to breakpoint"
266 # Set a catch catchpoint
268 send_gdb "catch catch\n"
270 -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
271 pass "catch catch (dynamic executable)"
273 -re ".*$gdb_prompt $" { fail "catch catch (dynamic executable)" }
274 timeout { fail "(timeout) catch catch (dynamic executable)" }
277 # Set a throw catchpoint
279 send_gdb "catch throw\n"
281 -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
282 pass "catch throw (dynamic executable)"
284 -re ".*$gdb_prompt $" { fail "catch throw (dynamic executable)" }
285 timeout { fail "(timeout) catch throw (dynamic executable)" }
288 # The catchpoints should be listed in the list of breakpoints.
290 send_gdb "info break\n"
292 -re ".*\[0-9\]*\[ \]*catch catch\[ \]*keep y\[ \]*exception catch\[ \]*\r\n\[0-9\]*\[ \]*catch throw\[ \]*keep y\[ \]*exception throw\[ \]*\r\n$gdb_prompt $" {
293 pass "info break with catchpoints (dynamic executable)"
295 -re ".*$gdb_prompt $" { fail "info break (dynamic executable)" }
296 timeout { fail "(timeout) info break (dynamic executable)" }
299 # Info catch currently does not work with HP aCC. No easy way to
300 # list the active handlers on the stack.
302 send_gdb "info catch\n"
304 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
305 pass "info catch (dynamic executable)"
307 -re ".*$gdb_prompt $" { fail "info catch (dynamic executable)" }
308 timeout { fail "(timeout) info catch (dynamic executable)" }
311 # Get the first exception thrown
313 send_gdb "continue\n"
315 -re "Continuing.*Catchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
316 pass "caught a throw (dynamic executable)"
318 -re ".*$gdb_prompt $" { fail "didn't catch a throw (dynamic executable)" }
319 timeout { fail "(timeout) after continue -- didn't catch a throw? (dynamic executable)" }
322 send_gdb "backtrace\n"
324 -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 $" {
325 pass "backtrace after throw (dynamic executable)"
327 -re ".*$gdb_prompt $" { fail "backtrace after throw (dynamic executable)" }
328 timeout { fail "(timeout) backtrace after throw (dynamic executable)" }
331 # Now intercept it when it is caught.
333 send_gdb "continue\n"
335 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
336 pass "caught a catch (dynamic executable)"
338 -re ".*$gdb_prompt $" { fail "didn't catch a catch (dynamic executable)" }
339 timeout { fail "(timeout) after continue -- didn't catch a catch? (dynamic executable)" }
342 send_gdb "backtrace\n"
344 -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 $" {
345 pass "backtrace after catch (dynamic executable)"
347 -re ".*$gdb_prompt $" { fail "backtrace after catch (dynamic executable)" }
348 timeout { fail "(timeout) backtrace after catch (dynamic executable)" }
351 send_gdb "continue\n"
353 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
354 pass "caught a throw (2) (dynamic executable)"
356 -re ".*$gdb_prompt $" { fail "didn't catch a throw (2) (dynamic executable)" }
357 timeout { fail "(timeout) after continue -- didn't catch a throw (2)? (dynamic executable)" }
360 send_gdb "continue\n"
362 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
363 pass "caught a catch (2) (dynamic executable)"
365 -re ".*$gdb_prompt $" { fail "didn't catch a catch (2) (dynamic executable)" }
366 timeout { fail "(timeout) after continue -- didn't catch a catch (2)? (dynamic executable)" }
369 # Now the exception will be rethrown.
371 send_gdb "continue\n"
373 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
374 pass "caught a rethrow (dynamic executable)"
376 -re ".*$gdb_prompt $" { fail "didn't catch a rethrow (dynamic executable)" }
377 timeout { fail "(timeout) after continue -- didn't catch a rethrow? (dynamic executable)" }
380 send_gdb "continue\n"
382 -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
383 pass "caught a catch (3) (dynamic executable)"
385 -re ".*$gdb_prompt $" { fail "didn't catch a catch (3) (dynamic executable)" }
386 timeout { fail "(timeout) after continue -- didn't catch a catch (3)? (dynamic executable)" }
389 send_gdb "backtrace\n"
391 -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 $" {
392 pass "backtrace after catch (3) (dynamic executable)"
394 -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (dynamic executable)" }
395 timeout { fail "(timeout) backtrace after catch (3) (dynamic executable)" }
398 # Now the exception will be thrown, but not catch-able anywhere.
400 send_gdb "continue\n"
402 -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location unknown\r\n.*$gdb_prompt $" {
403 pass "caught an uncatchable throw (dynamic executable)"
405 -re ".*$gdb_prompt $" { fail "didn't catch an uncatchable throw (dynamic executable)" }
406 timeout { fail "(timeout) after continue -- didn't catch an uncatchable throw? (dynamic executable)" }