]>
Commit | Line | Data |
---|---|---|
9b254dd1 | 1 | # Copyright 1997, 1998, 2004, 2005, 2007, 2008 Free Software Foundation, Inc. |
7be570e7 JM |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
7be570e7 | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
7be570e7 JM |
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. | |
e22f8b7c | 12 | # |
7be570e7 | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
7be570e7 | 15 | |
041ab88c | 16 | # This file is part of the gdb testsuite. |
7be570e7 JM |
17 | # tests for exception-handling support |
18 | # Written by Satish Pai <pai@apollo.hp.com> 1997-07-23 | |
041ab88c | 19 | # Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-08 |
7be570e7 | 20 | |
041ab88c MC |
21 | # This file used to have two copies of the tests with different |
22 | # compiler flags for hp-ux. Instead, the user should set CXXOPTS | |
23 | # or run runtest with --target_board unix/gdb:debug_flags="..." | |
24 | # to choose the compiler flags. | |
25 | # | |
6fa9022e | 26 | # The interesting compiler flags are: "aCC +A -Wl,-a,-archive" . |
041ab88c MC |
27 | # Static-linked executables use a different mechanism to get the |
28 | # address of the notification hook in the C++ support library. | |
7be570e7 | 29 | |
041ab88c MC |
30 | # TODO: this file has many absolute line numbers. |
31 | # Replace them with gdb_get_line_number. | |
7be570e7 | 32 | |
041ab88c MC |
33 | set ws "\[\r\n\t \]+" |
34 | set nl "\[\r\n\]+" | |
7be570e7 | 35 | |
041ab88c MC |
36 | if $tracelevel then { |
37 | strace $tracelevel | |
38 | } | |
7be570e7 | 39 | |
5f579bc5 NS |
40 | if { [skip_cplus_tests] } { continue } |
41 | ||
c1d88655 UW |
42 | # On SPU this test fails because the executable exceeds local storage size. |
43 | if { [istarget "spu*-*-*"] } { | |
44 | return 0 | |
45 | } | |
46 | ||
7be570e7 JM |
47 | set testfile "exception" |
48 | set srcfile ${testfile}.cc | |
49 | set binfile ${objdir}/${subdir}/${testfile} | |
50 | ||
041ab88c | 51 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { |
b60f0898 JB |
52 | untested exception.exp |
53 | return -1 | |
7be570e7 | 54 | } |
7be570e7 JM |
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 | ||
7be570e7 JM |
66 | # Set a catch catchpoint |
67 | ||
8a34ac3f AR |
68 | gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" \ |
69 | "catch catch (before inferior run)" | |
7be570e7 JM |
70 | |
71 | # Set a throw catchpoint | |
72 | ||
041ab88c | 73 | gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \ |
8a34ac3f | 74 | "catch throw (before inferior run)" |
7be570e7 | 75 | |
7be570e7 | 76 | |
8a34ac3f AR |
77 | # The catchpoints should be listed in the list of breakpoints. |
78 | # In case of a statically linked test, we won't have a pending breakpoint. | |
79 | # Hence we allow for both an address or "<PENDING>". If we ever become able | |
80 | # to tell whether the target is linked statically or not, we can be more | |
81 | # precise and require exact output. | |
82 | set addr "\(<PENDING>|$hex\)" | |
041ab88c | 83 | set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What" |
8a34ac3f AR |
84 | set re_2_bp "1${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception catch" |
85 | set re_3_bp "2${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception throw" | |
041ab88c | 86 | |
8a34ac3f | 87 | set name "info breakpoints (before inferior run)" |
041ab88c | 88 | gdb_test_multiple "info breakpoints" $name { |
8a34ac3f | 89 | -re "$re_head${ws}$re_2_bp${ws}$re_3_bp\r\n$gdb_prompt $" { |
041ab88c MC |
90 | pass $name |
91 | } | |
8a34ac3f AR |
92 | -re ".*$gdb_prompt $" |
93 | { | |
94 | fail $name | |
95 | } | |
041ab88c MC |
96 | } |
97 | ||
8a34ac3f AR |
98 | gdb_test "tbreak main" "Temporary breakpoint 3.*" \ |
99 | "Set temporary breakpoint at main" | |
041ab88c | 100 | |
8a34ac3f AR |
101 | set ok 0 |
102 | gdb_run_cmd | |
103 | gdb_test_multiple "" "Run to main" { | |
104 | -re "Temporary breakpoint 3,.*$gdb_prompt $" { | |
105 | pass "Run to main" | |
106 | set ok 1 | |
041ab88c | 107 | } |
8a34ac3f AR |
108 | } |
109 | ||
110 | if { !$ok } { | |
111 | continue | |
112 | } | |
113 | ||
114 | set addr "$hex" | |
115 | set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What" | |
116 | set re_2_bp "1${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception catch" | |
117 | set re_3_bp "2${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception throw" | |
118 | ||
119 | set name "info breakpoints (after inferior run)" | |
120 | gdb_test_multiple "info breakpoints" $name { | |
121 | -re "$re_head${ws}$re_2_bp${ws}$re_3_bp\r\n$gdb_prompt $" { | |
122 | pass $name | |
041ab88c | 123 | } |
8a34ac3f AR |
124 | -re ".*$gdb_prompt $" |
125 | { | |
126 | send_user "\n---\n$expect_out(buffer)\n---\n" | |
127 | fail $name | |
128 | } | |
7be570e7 JM |
129 | } |
130 | ||
131 | # Get the first exception thrown | |
132 | ||
041ab88c MC |
133 | set name "continue to first throw" |
134 | gdb_test_multiple "continue" $name { | |
135 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" { | |
136 | pass $name | |
137 | } | |
8a34ac3f AR |
138 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" { |
139 | pass $name | |
041ab88c | 140 | } |
7be570e7 JM |
141 | } |
142 | ||
041ab88c MC |
143 | # Backtrace from the throw point. |
144 | # This should get to user code. | |
7be570e7 | 145 | |
041ab88c MC |
146 | set name "backtrace after first throw" |
147 | gdb_test_multiple "backtrace" $name { | |
8a34ac3f | 148 | -re ".*#\[0-9\]+${ws}$hex in __cxa_throw.*#\[0-9\]+${ws}$hex in foo \\(i=20\\) at .*${srcfile}:\[0-9\]+\r\n#\[0-9\]+${ws}$hex in main \\(.*\\) at .*${srcfile}:\[0-9\]+\r\n$gdb_prompt $" { |
041ab88c MC |
149 | pass $name |
150 | } | |
7be570e7 JM |
151 | } |
152 | ||
041ab88c | 153 | # Continue to the catch. |
7be570e7 | 154 | |
041ab88c MC |
155 | set name "continue to first catch" |
156 | gdb_test_multiple "continue" $name { | |
157 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" { | |
158 | pass $name | |
159 | } | |
8a34ac3f AR |
160 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" { |
161 | pass $name | |
041ab88c | 162 | } |
7be570e7 JM |
163 | } |
164 | ||
041ab88c MC |
165 | # Backtrace from the catch point. |
166 | # This should get to user code. | |
7be570e7 | 167 | |
041ab88c MC |
168 | set name "backtrace after first catch" |
169 | gdb_test_multiple "backtrace" $name { | |
8a34ac3f | 170 | -re ".*#\[0-9\]+${ws}$hex in __cxa_begin_catch.*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" { |
041ab88c MC |
171 | pass $name |
172 | } | |
7be570e7 JM |
173 | } |
174 | ||
041ab88c | 175 | # Continue to second throw. |
7be570e7 | 176 | |
041ab88c MC |
177 | set name "continue to second throw" |
178 | gdb_test_multiple "continue" $name { | |
179 | -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 $" { | |
180 | pass $name | |
181 | } | |
8a34ac3f AR |
182 | -re "Continuing.${ws}Got an except 13${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" { |
183 | pass $name | |
041ab88c | 184 | } |
7be570e7 JM |
185 | } |
186 | ||
041ab88c MC |
187 | # Backtrace from the throw point. |
188 | # This should get to user code. | |
7be570e7 | 189 | |
041ab88c MC |
190 | set name "backtrace after second throw" |
191 | gdb_test_multiple "backtrace" $name { | |
8a34ac3f | 192 | -re ".*#\[0-9\]+${ws}$hex in __cxa_throw.*#\[0-9\]+${ws}$hex in foo \\(i=20\\) at .*${srcfile}:\[0-9\]+\r\n#\[0-9\]+${ws}$hex in main \\(.*\\) at .*${srcfile}:\[0-9\]+\r\n$gdb_prompt $" { |
041ab88c MC |
193 | pass $name |
194 | } | |
7be570e7 JM |
195 | } |
196 | ||
041ab88c | 197 | # Continue to second catch. |
7be570e7 | 198 | |
041ab88c MC |
199 | set name "continue to second catch" |
200 | gdb_test_multiple "continue" $name { | |
201 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" { | |
202 | pass $name | |
203 | } | |
8a34ac3f AR |
204 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" { |
205 | pass $name | |
041ab88c | 206 | } |
7be570e7 JM |
207 | } |
208 | ||
041ab88c MC |
209 | # Backtrace from the catch point. |
210 | # This should get to user code. | |
7be570e7 | 211 | |
041ab88c MC |
212 | set name "backtrace after second catch" |
213 | gdb_test_multiple "backtrace" $name { | |
8a34ac3f | 214 | -re ".*#\[0-9\]+${ws}$hex in __cxa_begin_catch.*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" { |
041ab88c MC |
215 | pass $name |
216 | } | |
7be570e7 JM |
217 | } |
218 | ||
041ab88c MC |
219 | # That is all for now. |
220 | # | |
221 | # The original code had: | |
222 | # | |
223 | # continue to re-throw ; backtrace | |
224 | # continue to catch ; backtrace | |
225 | # continue to throw out of main | |
226 | # | |
227 | # The problem is that "re-throw" does not show a throw; only a catch. | |
228 | # I do not know if this is because of a bug, or because the generated | |
229 | # code is optimized for a throw into the same function. | |
230 | # | |
231 | # -- chastain 2004-01-09 |