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