]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/exception.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / exception.exp
1 # Copyright 1997, 1998, 2004, 2005, 2007 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 # This file is part of the gdb testsuite.
18 # tests for exception-handling support
19 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
20 # Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-08
21
22 # This file used to have two copies of the tests with different
23 # compiler flags for hp-ux. Instead, the user should set CXXOPTS
24 # or run runtest with --target_board unix/gdb:debug_flags="..."
25 # to choose the compiler flags.
26 #
27 # The interesting compiler flags are: "aCC +A -Wl,-a,-archive" .
28 # Static-linked executables use a different mechanism to get the
29 # address of the notification hook in the C++ support library.
30
31 # TODO: this file is not ready for production yet. If you are working
32 # on C++ exception support for gdb, you can take out the "continue"
33 # statement and try your luck. -- chastain 2004-01-09
34
35 # TODO: this file has many absolute line numbers.
36 # Replace them with gdb_get_line_number.
37
38 set ws "\[\r\n\t \]+"
39 set nl "\[\r\n\]+"
40
41 if $tracelevel then {
42 strace $tracelevel
43 }
44
45 if { [skip_cplus_tests] } { continue }
46
47 # On SPU this test fails because the executable exceeds local storage size.
48 if { [istarget "spu*-*-*"] } {
49 return 0
50 }
51
52 set testfile "exception"
53 set srcfile ${testfile}.cc
54 set binfile ${objdir}/${subdir}/${testfile}
55
56 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
57 untested exception.exp
58 return -1
59 }
60
61 # Start with a fresh gdb
62
63 set prms_id 0
64 set bug_id 0
65
66 gdb_exit
67 gdb_start
68 gdb_reinitialize_dir $srcdir/$subdir
69 gdb_load ${binfile}
70
71 if ![runto_main] then {
72 perror "couldn't run to breakpoint"
73 continue
74 }
75
76 # As I said before, this test script is not ready yet!
77
78 continue
79
80 # Set a catch catchpoint
81
82 gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)"
83
84 # Set a throw catchpoint
85
86 gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \
87 "catch throw (static executable)"
88
89 # The catchpoints should be listed in the list of breakpoints.
90
91 set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
92 set re_1_main "1${ws}breakpoint${ws}keep${ws}y${ws}$hex${ws}in main.*breakpoint already hit.*"
93 set re_2_catch "2${ws}catch catch${ws}keep${ws}y${ws}$hex${ws}exception catch"
94 set re_3_catch "3${ws}catch throw${ws}keep${ws}y${ws}$hex${ws}exception throw"
95 set re_2_bp "2${ws}breakpoint${ws}keep${ws}y${ws}$hex${ws}exception catch"
96 set re_3_bp "3${ws}breakpoint${ws}keep${ws}y${ws}$hex${ws}exception throw"
97
98 set name "info breakpoints"
99 gdb_test_multiple "info breakpoints" $name {
100 -re "$re_head${ws}$re_1_main${ws}$re_2_catch${ws}$re_3_catch\r\n$gdb_prompt $" {
101 pass $name
102 }
103 -re "$re_head${ws}$re_1_main${ws}$re_2_bp${ws}$re_3_bp\r\n$gdb_prompt $" {
104 # TODO: gdb HEAD 2004-01-08 does this. Is this okay?
105 unresolved $name
106 }
107 }
108
109 # Some targets support "info catch".
110 # Some do not.
111
112 set name "info catch"
113 gdb_test_multiple "info catch" $name {
114 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
115 unsupported $name
116 }
117 -re "No catches.\r\n$gdb_prompt $" {
118 # TODO: gdb HEAD 2004-01-08 does this. Is this okay?
119 unresolved $name
120 }
121 }
122
123 # Get the first exception thrown
124
125 set name "continue to first throw"
126 gdb_test_multiple "continue" $name {
127 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
128 pass $name
129 }
130 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\)\r\n.*\r\n$gdb_prompt $" {
131 # TODO: gdb HEAD 2004-01-08 does this. Is this okay?
132 unresolved $name
133 }
134 }
135
136 # Backtrace from the throw point.
137 # This should get to user code.
138
139 set name "backtrace after first throw"
140 gdb_test_multiple "backtrace" $name {
141 -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 $" {
142 pass $name
143 }
144 }
145
146 # Continue to the catch.
147
148 set name "continue to first catch"
149 gdb_test_multiple "continue" $name {
150 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
151 pass $name
152 }
153 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\)\r\n.*\r\n$gdb_prompt $" {
154 # TODO: gdb HEAD 2004-01-08 does this. Is this okay?
155 unresolved $name
156 }
157 }
158
159 # Backtrace from the catch point.
160 # This should get to user code.
161
162 set name "backtrace after first catch"
163 gdb_test_multiple "backtrace" $name {
164 -re ".*#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*$srcfile:50\r\n$gdb_prompt $" {
165 pass $name
166 }
167 }
168
169 # Continue to second throw.
170
171 set name "continue to second throw"
172 gdb_test_multiple "continue" $name {
173 -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 $" {
174 pass $name
175 }
176 -re "Continuing.${ws}Got an except 13${ws}Catchpoint \[0-9\]+ \\(exception thrown\\)\r\n.*\r\n$gdb_prompt $" {
177 # TODO: gdb HEAD 2004-01-08 does this. Is this okay?
178 unresolved $name
179 }
180 }
181
182 # Backtrace from the throw point.
183 # This should get to user code.
184
185 set name "backtrace after second throw"
186 gdb_test_multiple "backtrace" $name {
187 -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 $" {
188 pass $name
189 }
190 }
191
192 # Continue to second catch.
193
194 set name "continue to second catch"
195 gdb_test_multiple "continue" $name {
196 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
197 pass $name
198 }
199 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\)\r\n.*\r\n$gdb_prompt $" {
200 # TODO: gdb HEAD 2004-01-08 does this. Is this okay?
201 unresolved $name
202 }
203 }
204
205 # Backtrace from the catch point.
206 # This should get to user code.
207
208 set name "backtrace after second catch"
209 gdb_test_multiple "backtrace" $name {
210 -re ".*#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*$srcfile:58\r\n$gdb_prompt $" {
211 pass $name
212 }
213 }
214
215 # That is all for now.
216 #
217 # The original code had:
218 #
219 # continue to re-throw ; backtrace
220 # continue to catch ; backtrace
221 # continue to throw out of main
222 #
223 # The problem is that "re-throw" does not show a throw; only a catch.
224 # I do not know if this is because of a bug, or because the generated
225 # code is optimized for a throw into the same function.
226 #
227 # -- chastain 2004-01-09