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
|
# Copyright 1997, 1998, 2004, 2005 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.
# This file is part of the gdb testsuite.
# tests for exception-handling support
# Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
# Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-08
# This file used to have two copies of the tests with different
# compiler flags for hp-ux. Instead, the user should set CXXOPTS
# or run runtest with --target_board unix/gdb:debug_flags="..."
# to choose the compiler flags.
#
# The interesting compiler flags are: "aCC +A -Wl,-a,-archive" .
# Static-linked executables use a different mechanism to get the
# address of the notification hook in the C++ support library.
# TODO: this file is not ready for production yet. If you are working
# on C++ exception support for gdb, you can take out the "continue"
# statement and try your luck. -- chastain 2004-01-09
# TODO: this file has many absolute line numbers.
# Replace them with gdb_get_line_number.
set ws "\[\r\n\t \]+"
set nl "\[\r\n\]+"
if $tracelevel then {
strace $tracelevel
}
if { [skip_cplus_tests] } { continue }
# On SPU this test fails because the executable exceeds local storage size.
if { [istarget "spu*-*-*"] } {
return 0
}
set testfile "exception"
set srcfile ${testfile}.cc
set binfile ${objdir}/${subdir}/${testfile}
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
untested exception.exp
return -1
}
# 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
}
# As I said before, this test script is not ready yet!
continue
# Set a catch catchpoint
gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)"
# Set a throw catchpoint
gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \
"catch throw (static executable)"
# The catchpoints should be listed in the list of breakpoints.
set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
set re_1_main "1${ws}breakpoint${ws}keep${ws}y${ws}$hex${ws}in main.*breakpoint already hit.*"
set re_2_catch "2${ws}catch catch${ws}keep${ws}y${ws}$hex${ws}exception catch"
set re_3_catch "3${ws}catch throw${ws}keep${ws}y${ws}$hex${ws}exception throw"
set re_2_bp "2${ws}breakpoint${ws}keep${ws}y${ws}$hex${ws}exception catch"
set re_3_bp "3${ws}breakpoint${ws}keep${ws}y${ws}$hex${ws}exception throw"
set name "info breakpoints"
gdb_test_multiple "info breakpoints" $name {
-re "$re_head${ws}$re_1_main${ws}$re_2_catch${ws}$re_3_catch\r\n$gdb_prompt $" {
pass $name
}
-re "$re_head${ws}$re_1_main${ws}$re_2_bp${ws}$re_3_bp\r\n$gdb_prompt $" {
# TODO: gdb HEAD 2004-01-08 does this. Is this okay?
unresolved $name
}
}
# Some targets support "info catch".
# Some do not.
set name "info catch"
gdb_test_multiple "info catch" $name {
-re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
unsupported $name
}
-re "No catches.\r\n$gdb_prompt $" {
# TODO: gdb HEAD 2004-01-08 does this. Is this okay?
unresolved $name
}
}
# Get the first exception thrown
set name "continue to first throw"
gdb_test_multiple "continue" $name {
-re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
pass $name
}
-re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\)\r\n.*\r\n$gdb_prompt $" {
# TODO: gdb HEAD 2004-01-08 does this. Is this okay?
unresolved $name
}
}
# Backtrace from the throw point.
# This should get to user code.
set name "backtrace after first throw"
gdb_test_multiple "backtrace" $name {
-re ".*#\[0-9\]+${ws}$hex in foo \\(i=20\\) at .*${srcfile}:30\r\n#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*${srcfile}:48\r\n$gdb_prompt $" {
pass $name
}
}
# Continue to the catch.
set name "continue to first catch"
gdb_test_multiple "continue" $name {
-re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
pass $name
}
-re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\)\r\n.*\r\n$gdb_prompt $" {
# TODO: gdb HEAD 2004-01-08 does this. Is this okay?
unresolved $name
}
}
# Backtrace from the catch point.
# This should get to user code.
set name "backtrace after first catch"
gdb_test_multiple "backtrace" $name {
-re ".*#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*$srcfile:50\r\n$gdb_prompt $" {
pass $name
}
}
# Continue to second throw.
set name "continue to second throw"
gdb_test_multiple "continue" $name {
-re "Continuing.${ws}Got an except 13${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
pass $name
}
-re "Continuing.${ws}Got an except 13${ws}Catchpoint \[0-9\]+ \\(exception thrown\\)\r\n.*\r\n$gdb_prompt $" {
# TODO: gdb HEAD 2004-01-08 does this. Is this okay?
unresolved $name
}
}
# Backtrace from the throw point.
# This should get to user code.
set name "backtrace after second throw"
gdb_test_multiple "backtrace" $name {
-re ".*#\[0-9\]+${ws}$hex in foo \\(i=20\\) at .*${srcfile}:30\r\n#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*${srcfile}:56\r\n$gdb_prompt $" {
pass $name
}
}
# Continue to second catch.
set name "continue to second catch"
gdb_test_multiple "continue" $name {
-re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
pass $name
}
-re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\)\r\n.*\r\n$gdb_prompt $" {
# TODO: gdb HEAD 2004-01-08 does this. Is this okay?
unresolved $name
}
}
# Backtrace from the catch point.
# This should get to user code.
set name "backtrace after second catch"
gdb_test_multiple "backtrace" $name {
-re ".*#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*$srcfile:58\r\n$gdb_prompt $" {
pass $name
}
}
# That is all for now.
#
# The original code had:
#
# continue to re-throw ; backtrace
# continue to catch ; backtrace
# continue to throw out of main
#
# The problem is that "re-throw" does not show a throw; only a catch.
# I do not know if this is because of a bug, or because the generated
# code is optimized for a throw into the same function.
#
# -- chastain 2004-01-09
|