]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.hp/exception.exp
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.hp / exception.exp
1 # Copyright (C) 1997, 1998 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 #
21 # tests for exception-handling support
22 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
23
24 # This file is part of the gdb testsuite
25
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
30 # for debugging
31
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.
39 #
40 # IMPORTANT:
41 # ---------
42 # IF YOU CHANGE A TEST IN ONE PART MAKE SURE YOU CHANGE IT
43 # --------------------------------------------------------
44 # IN THE OTHER PART TOO!
45 # ----------------------
46
47
48
49 if $tracelevel then {
50 strace $tracelevel
51 }
52
53
54 #
55 # test running programs
56 #
57
58 # Part I : Archive-bound executables
59 # ----------------------------------
60
61 set testfile "exception"
62 set srcfile ${testfile}.cc
63 set binfile ${objdir}/${subdir}/${testfile}
64
65 if [get_compiler_info ${binfile} "c++"] {
66 return -1;
67 }
68
69
70 if {[skip_hp_tests $gcc_compiled]} then { continue }
71
72 set cmdline "$CXX ${srcdir}/${subdir}/${srcfile} +A -Wl,-a,archive -g -o ${binfile}"
73
74 remote_exec build $cmdline
75
76 # Start with a fresh gdb
77
78 set prms_id 0
79 set bug_id 0
80
81 gdb_exit
82 gdb_start
83 gdb_reinitialize_dir $srcdir/$subdir
84 gdb_load ${binfile}
85
86 if ![runto_main] then {
87 perror "couldn't run to breakpoint"
88 continue
89 }
90
91 # Set a catch catchpoint
92
93 send_gdb "catch catch\n"
94 gdb_expect {
95 -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
96 pass "catch catch (static executable)"
97 }
98 -re ".*$gdb_prompt $" { fail "catch catch (static executable)" }
99 timeout { fail "(timeout) catch catch (static executable)" }
100 }
101
102 # Set a throw catchpoint
103
104 send_gdb "catch throw\n"
105 gdb_expect {
106 -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
107 pass "catch throw (static executable)"
108 }
109 -re ".*$gdb_prompt $" { fail "catch throw (static executable)" }
110 timeout { fail "(timeout) catch throw (static executable)" }
111 }
112
113 # The catchpoints should be listed in the list of breakpoints.
114
115 send_gdb "info break\n"
116 gdb_expect {
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)"
119 }
120 -re ".*$gdb_prompt $" { fail "info break (static executable)" }
121 timeout { fail "(timeout) info break (static executable)" }
122 }
123
124 # Info catch currently does not work with HP aCC. No easy way to
125 # list the active handlers on the stack.
126
127 send_gdb "info catch\n"
128 gdb_expect {
129 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
130 pass "info catch (static executable)"
131 }
132 -re ".*$gdb_prompt $" { fail "info catch (static executable)" }
133 timeout { fail "(timeout) info catch (static executable)" }
134 }
135
136 # Get the first exception thrown
137
138 send_gdb "continue\n"
139 gdb_expect {
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)"
142 }
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)" }
145 }
146
147 send_gdb "backtrace\n"
148 gdb_expect {
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)"
151 }
152 -re ".*$gdb_prompt $" { fail "backtrace after throw (static executable)" }
153 timeout { fail "(timeout) backtrace after throw (static executable)" }
154 }
155
156 # Now intercept it when it is caught.
157
158 send_gdb "continue\n"
159 gdb_expect {
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)"
162 }
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)" }
165 }
166
167 send_gdb "backtrace\n"
168 gdb_expect {
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)"
171 }
172 -re ".*$gdb_prompt $" { fail "backtrace after catch (static executable)" }
173 timeout { fail "(timeout) backtrace after catch (static executable)" }
174 }
175
176 send_gdb "continue\n"
177 gdb_expect {
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)"
180 }
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)" }
183 }
184
185 send_gdb "continue\n"
186 gdb_expect {
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)"
189 }
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)" }
192 }
193
194 # Now the exception will be rethrown.
195
196 send_gdb "continue\n"
197 gdb_expect {
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)"
200 }
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)" }
203 }
204
205 send_gdb "continue\n"
206 gdb_expect {
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)"
209 }
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)" }
212 }
213
214 send_gdb "backtrace\n"
215 gdb_expect {
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)"
218 }
219 -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (static executable)" }
220 timeout { fail "(timeout) backtrace after catch (3) (static executable)" }
221 }
222
223 # Now the exception will be thrown, but not catch-able anywhere.
224
225 send_gdb "continue\n"
226 gdb_expect {
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)"
229 }
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)" }
232 }
233
234 # Part II : Shared-bound executables
235 # ----------------------------------
236
237 # Start with a fresh gdb
238 gdb_exit
239 gdb_start
240 gdb_reinitialize_dir $srcdir/$subdir
241
242 set prms_id 0
243 set bug_id 0
244
245 set testfile "exception"
246 set srcfile ${testfile}.cc
247 set binfile ${objdir}/${subdir}/${testfile}
248
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
251 utomatically fail."
252 }
253
254
255 gdb_exit
256 gdb_start
257 gdb_reinitialize_dir $srcdir/$subdir
258 gdb_load ${binfile}
259
260
261 if ![runto_main] then {
262 perror "couldn't run to breakpoint"
263 continue
264 }
265
266 # Set a catch catchpoint
267
268 send_gdb "catch catch\n"
269 gdb_expect {
270 -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
271 pass "catch catch (dynamic executable)"
272 }
273 -re ".*$gdb_prompt $" { fail "catch catch (dynamic executable)" }
274 timeout { fail "(timeout) catch catch (dynamic executable)" }
275 }
276
277 # Set a throw catchpoint
278
279 send_gdb "catch throw\n"
280 gdb_expect {
281 -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
282 pass "catch throw (dynamic executable)"
283 }
284 -re ".*$gdb_prompt $" { fail "catch throw (dynamic executable)" }
285 timeout { fail "(timeout) catch throw (dynamic executable)" }
286 }
287
288 # The catchpoints should be listed in the list of breakpoints.
289
290 send_gdb "info break\n"
291 gdb_expect {
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)"
294 }
295 -re ".*$gdb_prompt $" { fail "info break (dynamic executable)" }
296 timeout { fail "(timeout) info break (dynamic executable)" }
297 }
298
299 # Info catch currently does not work with HP aCC. No easy way to
300 # list the active handlers on the stack.
301
302 send_gdb "info catch\n"
303 gdb_expect {
304 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
305 pass "info catch (dynamic executable)"
306 }
307 -re ".*$gdb_prompt $" { fail "info catch (dynamic executable)" }
308 timeout { fail "(timeout) info catch (dynamic executable)" }
309 }
310
311 # Get the first exception thrown
312
313 send_gdb "continue\n"
314 gdb_expect {
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)"
317 }
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)" }
320 }
321
322 send_gdb "backtrace\n"
323 gdb_expect {
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)"
326 }
327 -re ".*$gdb_prompt $" { fail "backtrace after throw (dynamic executable)" }
328 timeout { fail "(timeout) backtrace after throw (dynamic executable)" }
329 }
330
331 # Now intercept it when it is caught.
332
333 send_gdb "continue\n"
334 gdb_expect {
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)"
337 }
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)" }
340 }
341
342 send_gdb "backtrace\n"
343 gdb_expect {
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)"
346 }
347 -re ".*$gdb_prompt $" { fail "backtrace after catch (dynamic executable)" }
348 timeout { fail "(timeout) backtrace after catch (dynamic executable)" }
349 }
350
351 send_gdb "continue\n"
352 gdb_expect {
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)"
355 }
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)" }
358 }
359
360 send_gdb "continue\n"
361 gdb_expect {
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)"
364 }
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)" }
367 }
368
369 # Now the exception will be rethrown.
370
371 send_gdb "continue\n"
372 gdb_expect {
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)"
375 }
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)" }
378 }
379
380 send_gdb "continue\n"
381 gdb_expect {
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)"
384 }
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)" }
387 }
388
389 send_gdb "backtrace\n"
390 gdb_expect {
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)"
393 }
394 -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (dynamic executable)" }
395 timeout { fail "(timeout) backtrace after catch (3) (dynamic executable)" }
396 }
397
398 # Now the exception will be thrown, but not catch-able anywhere.
399
400 send_gdb "continue\n"
401 gdb_expect {
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)"
404 }
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)" }
407 }
408