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