summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.hp/gdb.aCC/exception.exp
blob: a0914ae5ba4ea397d22029727867605d5cae7679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# Copyright (C) 1997, 1998 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  

# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu

#
# tests for exception-handling support
# Written by Satish Pai <pai@apollo.hp.com> 1997-07-23

# This file is part of the gdb testsuite

# Note: These tests are geared to the HP aCC compiler,
# which has an idiosyncratic way of emitting debug info
# for exceptions -- it uses a callback mechanism, which
# is different from the way g++ records exception info
# for debugging

# The tests are in two parts; the first part deals with
# statically linked (archive-bound) executables, and the
# second part repeats those tests with dynamically linked
# (shared bound) executables.  (In the latter case we use
# a different mechanism to get the address of the notification
# hook in the C++ support library.) The tests themselves are
# the same in both parts.
# 
# IMPORTANT:
# ---------
# IF YOU CHANGE A TEST IN ONE PART MAKE SURE YOU CHANGE IT
# --------------------------------------------------------
# IN THE OTHER PART TOO!
# ----------------------



if $tracelevel then {
        strace $tracelevel
        }

if { [skip_hp_tests] } then { continue }

#
# test running programs
#

# Part I : Archive-bound executables
# ----------------------------------

set testfile "exception"
set srcfile ${testfile}.cc
set binfile ${objdir}/${subdir}/${testfile}
 
if [get_compiler_info ${binfile} "c++"] {
    return -1;
}
 
 
if { $gcc_compiled } then { continue }

set cmdline "$CXX_FOR_TARGET ${srcdir}/${subdir}/${srcfile} +A -Wl,-a,archive -g -o ${binfile}"

remote_exec build $cmdline

# Start with a fresh gdb

set prms_id 0
set bug_id 0

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}

if ![runto_main] then {
    perror "couldn't run to breakpoint"
    continue
}

# Set a catch catchpoint

send_gdb "catch catch\n"
gdb_expect {
   -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
       pass "catch catch (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "catch catch  (static executable)" }
   timeout { fail "(timeout) catch catch  (static executable)" }
}

# Set a throw catchpoint

send_gdb "catch throw\n"
gdb_expect {
   -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
       pass "catch throw (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "catch throw (static executable)" }
   timeout { fail "(timeout) catch throw (static executable)" }
}

# The catchpoints should be listed in the list of breakpoints.

send_gdb "info break\n"
gdb_expect {
   -re ".*\[0-9\]*\[ \]*catch catch\[ \]*keep y\[ \]*exception catch\[ \]*\r\n\[0-9\]*\[ \]*catch throw\[ \]*keep y\[ \]*exception throw\[ \]*\r\n$gdb_prompt $" {
       pass "info break with catchpoints (static executable)"
   }    
   -re ".*$gdb_prompt $" { fail "info break (static executable)" }
   timeout { fail "(timeout) info break (static executable)" }
}

# Info catch currently does not work with HP aCC. No easy way to
# list the active handlers on the stack.

send_gdb "info catch\n"
gdb_expect {
   -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
       pass "info catch (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "info catch (static executable)" }
   timeout { fail "(timeout) info catch (static executable)" }
}

# Get the first exception thrown
       
send_gdb "continue\n"
gdb_expect {
   -re "Continuing.*Catchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
      pass "caught a throw (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch a throw (static executable)" }
   timeout { fail "(timeout) after continue -- didn't catch a throw? (static executable)" }
}

send_gdb "backtrace\n"
gdb_expect {
   -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 $" {
      pass "backtrace after throw (static executable)"
   }
   -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 $" {
      pass "backtrace after throw (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "backtrace after throw (static executable)" }
   timeout { fail "(timeout) backtrace after throw (static executable)" }
}

# Now intercept it when it is caught.

send_gdb "continue\n"
gdb_expect {
   -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
      pass "caught a catch (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch a catch (static executable)" }
   timeout { fail "(timeout) after continue -- didn't catch a catch? (static executable)" }
}

send_gdb "backtrace\n"
gdb_expect {
   -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 $" {
      pass "backtrace after catch (static executable)"
   }
   -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 $" {
      pass "backtrace after catch (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "backtrace after catch (static executable)" }
   timeout { fail "(timeout) backtrace after catch (static executable)" }
}
      
send_gdb "continue\n"
gdb_expect {
   -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
      pass "caught a throw (2) (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch a throw (2) (static executable)" }
   timeout { fail "(timeout) after continue -- didn't catch a throw (2)? (static executable)" }
}

send_gdb "continue\n"
gdb_expect {
   -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
      pass "caught a catch (2) (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch a catch (2) (static executable)" }
   timeout { fail "(timeout) after continue -- didn't catch a catch (2)? (static executable)" }
}

# Now the exception will be rethrown.

send_gdb "continue\n"
gdb_expect {
   -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
      pass "caught a rethrow (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch a rethrow (static executable)" }
   timeout { fail "(timeout) after continue -- didn't catch a rethrow? (static executable)" }
}

send_gdb "continue\n"
gdb_expect {
   -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:3\[68\], catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
      # FIXME: guo: why XFAIL?  need comment
      xfail "caught a catch (3) (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch a catch (3) (static executable)" }
   timeout { fail "(timeout) after continue -- didn't catch a catch (3)? (static executable)" }
}

send_gdb "backtrace\n"
gdb_expect {
   -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 $" {
      # FIXME: guo: why XFAIL?  need comment
      xfail "backtrace after catch (3) (static executable)"
   }
   -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 $" {
      # FIXME: guo: why XFAIL?  need comment
      xfail "backtrace after catch (3) (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (static executable)" }
   timeout { fail "(timeout) backtrace after catch (3) (static executable)" }
}

# Now the exception will be thrown, but not catch-able anywhere.

send_gdb "continue\n"
gdb_expect {
   -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location unknown\r\n.*$gdb_prompt $" {
      pass "caught an uncatchable throw (static executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch an uncatchable throw (static executable)" }
   timeout { fail "(timeout) after continue -- didn't catch an uncatchable throw? (static executable)" }
}

# Part II : Shared-bound executables
# ----------------------------------

# Start with a fresh gdb
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir

set prms_id 0
set bug_id 0

set testfile "exception"
set srcfile ${testfile}.cc
set binfile ${objdir}/${subdir}/${testfile}

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will a
utomatically fail."
}


gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}


if ![runto_main] then {
    perror "couldn't run to breakpoint"
    continue
}

# Set a catch catchpoint

send_gdb "catch catch\n"
gdb_expect {
   -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" {
       pass "catch catch (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "catch catch  (dynamic executable)" }
   timeout { fail "(timeout) catch catch  (dynamic executable)" }
}

# Set a throw catchpoint

send_gdb "catch throw\n"
gdb_expect {
   -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" {
       pass "catch throw (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "catch throw (dynamic executable)" }
   timeout { fail "(timeout) catch throw (dynamic executable)" }
}

# The catchpoints should be listed in the list of breakpoints.

send_gdb "info break\n"
gdb_expect {
   -re ".*\[0-9\]*\[ \]*catch catch\[ \]*keep y\[ \]*exception catch\[ \]*\r\n\[0-9\]*\[ \]*catch throw\[ \]*keep y\[ \]*exception throw\[ \]*\r\n$gdb_prompt $" {
       pass "info break with catchpoints (dynamic executable)"
   }    
   -re ".*$gdb_prompt $" { fail "info break (dynamic executable)" }
   timeout { fail "(timeout) info break (dynamic executable)" }
}

# Info catch currently does not work with HP aCC. No easy way to
# list the active handlers on the stack.

send_gdb "info catch\n"
gdb_expect {
   -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
       pass "info catch (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "info catch (dynamic executable)" }
   timeout { fail "(timeout) info catch (dynamic executable)" }
}

# Get the first exception thrown
       
send_gdb "continue\n"
gdb_expect {
   -re "Continuing.*Catchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
      pass "caught a throw (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch a throw (dynamic executable)" }
   timeout { fail "(timeout) after continue -- didn't catch a throw? (dynamic executable)" }
}

send_gdb "backtrace\n"
gdb_expect {
   -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 $" {
      pass "backtrace after throw (dynamic executable)"
   }
   -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 $" {
      pass "backtrace after throw (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "backtrace after throw (dynamic executable)" }
   timeout { fail "(timeout) backtrace after throw (dynamic executable)" }
}

# Now intercept it when it is caught.

send_gdb "continue\n"
gdb_expect {
   -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" {
      pass "caught a catch (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch a catch (dynamic executable)" }
   timeout { fail "(timeout) after continue -- didn't catch a catch? (dynamic executable)" }
}

send_gdb "backtrace\n"
gdb_expect {
   -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 $" {
      pass "backtrace after catch (dynamic executable)"
   }
   -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 $" {
      pass "backtrace after catch (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "backtrace after catch (dynamic executable)" }
   timeout { fail "(timeout) backtrace after catch (dynamic executable)" }
}
      
send_gdb "continue\n"
gdb_expect {
   -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
      pass "caught a throw (2) (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch a throw (2) (dynamic executable)" }
   timeout { fail "(timeout) after continue -- didn't catch a throw (2)? (dynamic executable)" }
}

send_gdb "continue\n"
gdb_expect {
   -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" {
      pass "caught a catch (2) (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch a catch (2) (dynamic executable)" }
   timeout { fail "(timeout) after continue -- didn't catch a catch (2)? (dynamic executable)" }
}

# Now the exception will be rethrown.

send_gdb "continue\n"
gdb_expect {
   -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
      pass "caught a rethrow (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch a rethrow (dynamic executable)" }
   timeout { fail "(timeout) after continue -- didn't catch a rethrow? (dynamic executable)" }
}

#DTS CLLbs14858
#The throw location should be at line 38 instead of 36.
setup_xfail hppa*-*-* CLLbs14858
send_gdb "continue\n"
gdb_expect {
   -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:3\[68\], catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" {
      # FIXME: guo: according to comment above the RE is wrong!
      pass "caught a catch (3) (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch a catch (3) (dynamic executable)" }
   timeout { fail "(timeout) after continue -- didn't catch a catch (3)? (dynamic executable)" }
}

#DTS CLLbs14858
#The line number for main() should be at exception.cc:38 instead of exception.cc:36
setup_xfail hppa*-*-* CLLbs14858
send_gdb "backtrace\n"
gdb_expect {
   -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 $" {
      # FIXME: guo: according to comment above the RE is wrong!
      pass "backtrace after catch (3) (dynamic executable)"
   }
   -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 $" {
      # FIXME: guo: according to comment above the RE is wrong!
      pass "backtrace after catch (3) (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "backtrace after catch (3) (dynamic executable)" }
   timeout { fail "(timeout) backtrace after catch (3) (dynamic executable)" }
}

# Now the exception will be thrown, but not catch-able anywhere.

send_gdb "continue\n"
gdb_expect {
   -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location unknown\r\n.*$gdb_prompt $" {
      pass "caught an uncatchable throw (dynamic executable)"
   }
   -re ".*$gdb_prompt $" { fail "didn't catch an uncatchable throw (dynamic executable)" }
   timeout { fail "(timeout) after continue -- didn't catch an uncatchable throw? (dynamic executable)" }
}