Commit | Line | Data |
---|---|---|
c906108c SS |
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 | ||
7a292a7a | 53 | if { [skip_hp_tests] } then { continue } |
c906108c SS |
54 | |
55 | # | |
56 | # test running programs | |
57 | # | |
58 | ||
59 | # Part I : Archive-bound executables | |
60 | # ---------------------------------- | |
61 | ||
62 | set testfile "exception" | |
63 | set srcfile ${testfile}.cc | |
64 | set binfile ${objdir}/${subdir}/${testfile} | |
65 | ||
66 | if [get_compiler_info ${binfile} "c++"] { | |
67 | return -1; | |
68 | } | |
69 | ||
70 | ||
7a292a7a | 71 | if { $gcc_compiled } then { continue } |
c906108c SS |
72 | |
73 | set cmdline "$CXX ${srcdir}/${subdir}/${srcfile} +A -Wl,-a,archive -g -o ${binfile}" | |
74 | ||
75 | remote_exec build $cmdline | |
76 | ||
77 | # Start with a fresh gdb | |
78 | ||
79 | set prms_id 0 | |
80 | set bug_id 0 | |
81 | ||
82 | gdb_exit | |
83 | gdb_start | |
84 | gdb_reinitialize_dir $srcdir/$subdir | |
85 | gdb_load ${binfile} | |
86 | ||
87 | if ![runto_main] then { | |
88 | perror "couldn't run to breakpoint" | |
89 | continue | |
90 | } | |
91 | ||
92 | # Set a catch catchpoint | |
93 | ||
94 | send_gdb "catch catch\n" | |
95 | gdb_expect { | |
96 | -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" { | |
97 | pass "catch catch (static executable)" | |
98 | } | |
99 | -re ".*$gdb_prompt $" { fail "catch catch (static executable)" } | |
100 | timeout { fail "(timeout) catch catch (static executable)" } | |
101 | } | |
102 | ||
103 | # Set a throw catchpoint | |
104 | ||
105 | send_gdb "catch throw\n" | |
106 | gdb_expect { | |
107 | -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" { | |
108 | pass "catch throw (static executable)" | |
109 | } | |
110 | -re ".*$gdb_prompt $" { fail "catch throw (static executable)" } | |
111 | timeout { fail "(timeout) catch throw (static executable)" } | |
112 | } | |
113 | ||
114 | # The catchpoints should be listed in the list of breakpoints. | |
115 | ||
116 | send_gdb "info break\n" | |
117 | gdb_expect { | |
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)" | |
120 | } | |
121 | -re ".*$gdb_prompt $" { fail "info break (static executable)" } | |
122 | timeout { fail "(timeout) info break (static executable)" } | |
123 | } | |
124 | ||
125 | # Info catch currently does not work with HP aCC. No easy way to | |
126 | # list the active handlers on the stack. | |
127 | ||
128 | send_gdb "info catch\n" | |
129 | gdb_expect { | |
130 | -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" { | |
131 | pass "info catch (static executable)" | |
132 | } | |
133 | -re ".*$gdb_prompt $" { fail "info catch (static executable)" } | |
134 | timeout { fail "(timeout) info catch (static executable)" } | |
135 | } | |
136 | ||
137 | # Get the first exception thrown | |
138 | ||
139 | send_gdb "continue\n" | |
140 | gdb_expect { | |
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)" | |
143 | } | |
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)" } | |
146 | } | |
147 | ||
148 | send_gdb "backtrace\n" | |
149 | gdb_expect { | |
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)" | |
152 | } | |
153 | -re ".*$gdb_prompt $" { fail "backtrace after throw (static executable)" } | |
154 | timeout { fail "(timeout) backtrace after throw (static executable)" } | |
155 | } | |
156 | ||
157 | # Now intercept it when it is caught. | |
158 | ||
159 | send_gdb "continue\n" | |
160 | gdb_expect { | |
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)" | |
163 | } | |
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)" } | |
166 | } | |
167 | ||
168 | send_gdb "backtrace\n" | |
169 | gdb_expect { | |
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)" | |
172 | } | |
173 | -re ".*$gdb_prompt $" { fail "backtrace after catch (static executable)" } | |
174 | timeout { fail "(timeout) backtrace after catch (static executable)" } | |
175 | } | |
176 | ||
177 | send_gdb "continue\n" | |
178 | gdb_expect { | |
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)" | |
181 | } | |
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)" } | |
184 | } | |
185 | ||
186 | send_gdb "continue\n" | |
187 | gdb_expect { | |
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)" | |
190 | } | |
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)" } | |
193 | } | |
194 | ||
195 | # Now the exception will be rethrown. | |
196 | ||
197 | send_gdb "continue\n" | |
198 | gdb_expect { | |
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)" | |
201 | } | |
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)" } | |
204 | } | |
205 | ||
206 | send_gdb "continue\n" | |
207 | gdb_expect { | |
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)" | |
210 | } | |
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)" } | |
213 | } | |
214 | ||
215 | send_gdb "backtrace\n" | |
216 | gdb_expect { | |
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)" | |
219 | } | |
220 | -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (static executable)" } | |
221 | timeout { fail "(timeout) backtrace after catch (3) (static executable)" } | |
222 | } | |
223 | ||
224 | # Now the exception will be thrown, but not catch-able anywhere. | |
225 | ||
226 | send_gdb "continue\n" | |
227 | gdb_expect { | |
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)" | |
230 | } | |
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)" } | |
233 | } | |
234 | ||
235 | # Part II : Shared-bound executables | |
236 | # ---------------------------------- | |
237 | ||
238 | # Start with a fresh gdb | |
239 | gdb_exit | |
240 | gdb_start | |
241 | gdb_reinitialize_dir $srcdir/$subdir | |
242 | ||
243 | set prms_id 0 | |
244 | set bug_id 0 | |
245 | ||
246 | set testfile "exception" | |
247 | set srcfile ${testfile}.cc | |
248 | set binfile ${objdir}/${subdir}/${testfile} | |
249 | ||
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 | |
252 | utomatically fail." | |
253 | } | |
254 | ||
255 | ||
256 | gdb_exit | |
257 | gdb_start | |
258 | gdb_reinitialize_dir $srcdir/$subdir | |
259 | gdb_load ${binfile} | |
260 | ||
261 | ||
262 | if ![runto_main] then { | |
263 | perror "couldn't run to breakpoint" | |
264 | continue | |
265 | } | |
266 | ||
267 | # Set a catch catchpoint | |
268 | ||
269 | send_gdb "catch catch\n" | |
270 | gdb_expect { | |
271 | -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" { | |
272 | pass "catch catch (dynamic executable)" | |
273 | } | |
274 | -re ".*$gdb_prompt $" { fail "catch catch (dynamic executable)" } | |
275 | timeout { fail "(timeout) catch catch (dynamic executable)" } | |
276 | } | |
277 | ||
278 | # Set a throw catchpoint | |
279 | ||
280 | send_gdb "catch throw\n" | |
281 | gdb_expect { | |
282 | -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" { | |
283 | pass "catch throw (dynamic executable)" | |
284 | } | |
285 | -re ".*$gdb_prompt $" { fail "catch throw (dynamic executable)" } | |
286 | timeout { fail "(timeout) catch throw (dynamic executable)" } | |
287 | } | |
288 | ||
289 | # The catchpoints should be listed in the list of breakpoints. | |
290 | ||
291 | send_gdb "info break\n" | |
292 | gdb_expect { | |
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)" | |
295 | } | |
296 | -re ".*$gdb_prompt $" { fail "info break (dynamic executable)" } | |
297 | timeout { fail "(timeout) info break (dynamic executable)" } | |
298 | } | |
299 | ||
300 | # Info catch currently does not work with HP aCC. No easy way to | |
301 | # list the active handlers on the stack. | |
302 | ||
303 | send_gdb "info catch\n" | |
304 | gdb_expect { | |
305 | -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" { | |
306 | pass "info catch (dynamic executable)" | |
307 | } | |
308 | -re ".*$gdb_prompt $" { fail "info catch (dynamic executable)" } | |
309 | timeout { fail "(timeout) info catch (dynamic executable)" } | |
310 | } | |
311 | ||
312 | # Get the first exception thrown | |
313 | ||
314 | send_gdb "continue\n" | |
315 | gdb_expect { | |
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)" | |
318 | } | |
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)" } | |
321 | } | |
322 | ||
323 | send_gdb "backtrace\n" | |
324 | gdb_expect { | |
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)" | |
327 | } | |
328 | -re ".*$gdb_prompt $" { fail "backtrace after throw (dynamic executable)" } | |
329 | timeout { fail "(timeout) backtrace after throw (dynamic executable)" } | |
330 | } | |
331 | ||
332 | # Now intercept it when it is caught. | |
333 | ||
334 | send_gdb "continue\n" | |
335 | gdb_expect { | |
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)" | |
338 | } | |
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)" } | |
341 | } | |
342 | ||
343 | send_gdb "backtrace\n" | |
344 | gdb_expect { | |
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)" | |
347 | } | |
348 | -re ".*$gdb_prompt $" { fail "backtrace after catch (dynamic executable)" } | |
349 | timeout { fail "(timeout) backtrace after catch (dynamic executable)" } | |
350 | } | |
351 | ||
352 | send_gdb "continue\n" | |
353 | gdb_expect { | |
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)" | |
356 | } | |
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)" } | |
359 | } | |
360 | ||
361 | send_gdb "continue\n" | |
362 | gdb_expect { | |
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)" | |
365 | } | |
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)" } | |
368 | } | |
369 | ||
370 | # Now the exception will be rethrown. | |
371 | ||
372 | send_gdb "continue\n" | |
373 | gdb_expect { | |
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)" | |
376 | } | |
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)" } | |
379 | } | |
380 | ||
381 | send_gdb "continue\n" | |
382 | gdb_expect { | |
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)" | |
385 | } | |
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)" } | |
388 | } | |
389 | ||
390 | send_gdb "backtrace\n" | |
391 | gdb_expect { | |
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)" | |
394 | } | |
395 | -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (dynamic executable)" } | |
396 | timeout { fail "(timeout) backtrace after catch (3) (dynamic executable)" } | |
397 | } | |
398 | ||
399 | # Now the exception will be thrown, but not catch-able anywhere. | |
400 | ||
401 | send_gdb "continue\n" | |
402 | gdb_expect { | |
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)" | |
405 | } | |
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)" } | |
408 | } | |
409 |