Commit | Line | Data |
---|---|---|
e2882c85 | 1 | # Copyright 1997-2018 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 | |
759f0f0b | 36 | if { [skip_stl_tests] } { continue } |
5f579bc5 | 37 | |
c1d88655 UW |
38 | # On SPU this test fails because the executable exceeds local storage size. |
39 | if { [istarget "spu*-*-*"] } { | |
40 | return 0 | |
41 | } | |
42 | ||
f5f3a911 | 43 | standard_testfile .cc |
7be570e7 | 44 | |
5b362f04 | 45 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { |
f5f3a911 | 46 | return -1 |
7be570e7 | 47 | } |
7be570e7 | 48 | |
7be570e7 JM |
49 | # Set a catch catchpoint |
50 | ||
8a34ac3f AR |
51 | gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" \ |
52 | "catch catch (before inferior run)" | |
7be570e7 JM |
53 | |
54 | # Set a throw catchpoint | |
55 | ||
041ab88c | 56 | gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \ |
8a34ac3f | 57 | "catch throw (before inferior run)" |
7be570e7 | 58 | |
591f19e8 TT |
59 | # Set a rethrow catchpoint |
60 | ||
61 | gdb_test "catch rethrow" "Catchpoint \[0-9\]+ \\(rethrow\\)" \ | |
62 | "catch rethrow (before inferior run)" | |
63 | ||
7be570e7 | 64 | |
8a34ac3f AR |
65 | # The catchpoints should be listed in the list of breakpoints. |
66 | # In case of a statically linked test, we won't have a pending breakpoint. | |
67 | # Hence we allow for both an address or "<PENDING>". If we ever become able | |
68 | # to tell whether the target is linked statically or not, we can be more | |
69 | # precise and require exact output. | |
70 | set addr "\(<PENDING>|$hex\)" | |
041ab88c | 71 | set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What" |
8a34ac3f AR |
72 | set re_2_bp "1${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception catch" |
73 | set re_3_bp "2${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception throw" | |
591f19e8 | 74 | set re_4_bp "3${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception rethrow" |
041ab88c | 75 | |
8a34ac3f | 76 | set name "info breakpoints (before inferior run)" |
041ab88c | 77 | gdb_test_multiple "info breakpoints" $name { |
591f19e8 | 78 | -re "$re_head${ws}$re_2_bp${ws}$re_3_bp${ws}$re_4_bp\r\n$gdb_prompt $" { |
041ab88c MC |
79 | pass $name |
80 | } | |
8a34ac3f AR |
81 | -re ".*$gdb_prompt $" |
82 | { | |
83 | fail $name | |
84 | } | |
041ab88c MC |
85 | } |
86 | ||
591f19e8 | 87 | gdb_test "tbreak main" "Temporary breakpoint 4.*" \ |
8a34ac3f | 88 | "Set temporary breakpoint at main" |
041ab88c | 89 | |
8a34ac3f AR |
90 | set ok 0 |
91 | gdb_run_cmd | |
de97fdd4 | 92 | gdb_test_multiple "" "run to main" { |
591f19e8 | 93 | -re "Temporary breakpoint 4,.*$gdb_prompt $" { |
bc6c7af4 | 94 | pass "run to main" |
8a34ac3f | 95 | set ok 1 |
041ab88c | 96 | } |
8a34ac3f AR |
97 | } |
98 | ||
99 | if { !$ok } { | |
100 | continue | |
101 | } | |
102 | ||
103 | set addr "$hex" | |
104 | set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What" | |
105 | set re_2_bp "1${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception catch" | |
106 | set re_3_bp "2${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception throw" | |
591f19e8 | 107 | set re_4_bp "3${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception rethrow" |
8a34ac3f AR |
108 | |
109 | set name "info breakpoints (after inferior run)" | |
110 | gdb_test_multiple "info breakpoints" $name { | |
591f19e8 | 111 | -re "$re_head${ws}$re_2_bp${ws}$re_3_bp${ws}$re_4_bp\r\n$gdb_prompt $" { |
8a34ac3f | 112 | pass $name |
041ab88c | 113 | } |
8a34ac3f AR |
114 | -re ".*$gdb_prompt $" |
115 | { | |
116 | send_user "\n---\n$expect_out(buffer)\n---\n" | |
117 | fail $name | |
118 | } | |
7be570e7 JM |
119 | } |
120 | ||
af69a5ce YQ |
121 | gdb_test "break catcher" "Breakpoint \[0-9\]+ at.*" |
122 | ||
7be570e7 JM |
123 | # Get the first exception thrown |
124 | ||
041ab88c MC |
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 | } | |
8a34ac3f AR |
130 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" { |
131 | pass $name | |
041ab88c | 132 | } |
7be570e7 JM |
133 | } |
134 | ||
041ab88c MC |
135 | # Backtrace from the throw point. |
136 | # This should get to user code. | |
7be570e7 | 137 | |
041ab88c MC |
138 | set name "backtrace after first throw" |
139 | gdb_test_multiple "backtrace" $name { | |
cec808ec KS |
140 | -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 $" { |
141 | # Either __cxxabiv1::__cxa_throw or __cxa_throw can be printed | |
142 | # depending on debug info presence. | |
041ab88c MC |
143 | pass $name |
144 | } | |
7be570e7 JM |
145 | } |
146 | ||
041ab88c | 147 | # Continue to the catch. |
7be570e7 | 148 | |
041ab88c MC |
149 | set name "continue to first catch" |
150 | gdb_test_multiple "continue" $name { | |
151 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" { | |
152 | pass $name | |
153 | } | |
8a34ac3f AR |
154 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" { |
155 | pass $name | |
041ab88c | 156 | } |
7be570e7 JM |
157 | } |
158 | ||
041ab88c MC |
159 | # Backtrace from the catch point. |
160 | # This should get to user code. | |
7be570e7 | 161 | |
041ab88c MC |
162 | set name "backtrace after first catch" |
163 | gdb_test_multiple "backtrace" $name { | |
cec808ec | 164 | -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" { |
041ab88c MC |
165 | pass $name |
166 | } | |
7be570e7 JM |
167 | } |
168 | ||
af69a5ce YQ |
169 | # Continue to breakpoint on catcher. |
170 | gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the first time" | |
171 | ||
041ab88c | 172 | # Continue to second throw. |
7be570e7 | 173 | |
041ab88c MC |
174 | set name "continue to second throw" |
175 | gdb_test_multiple "continue" $name { | |
af69a5ce | 176 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" { |
041ab88c MC |
177 | pass $name |
178 | } | |
af69a5ce | 179 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" { |
8a34ac3f | 180 | pass $name |
041ab88c | 181 | } |
7be570e7 JM |
182 | } |
183 | ||
041ab88c MC |
184 | # Backtrace from the throw point. |
185 | # This should get to user code. | |
7be570e7 | 186 | |
041ab88c MC |
187 | set name "backtrace after second throw" |
188 | gdb_test_multiple "backtrace" $name { | |
cec808ec | 189 | -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 |
190 | pass $name |
191 | } | |
7be570e7 JM |
192 | } |
193 | ||
041ab88c | 194 | # Continue to second catch. |
7be570e7 | 195 | |
041ab88c MC |
196 | set name "continue to second catch" |
197 | gdb_test_multiple "continue" $name { | |
198 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" { | |
199 | pass $name | |
200 | } | |
8a34ac3f AR |
201 | -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" { |
202 | pass $name | |
041ab88c | 203 | } |
7be570e7 JM |
204 | } |
205 | ||
041ab88c MC |
206 | # Backtrace from the catch point. |
207 | # This should get to user code. | |
7be570e7 | 208 | |
041ab88c MC |
209 | set name "backtrace after second catch" |
210 | gdb_test_multiple "backtrace" $name { | |
cec808ec | 211 | -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" { |
041ab88c MC |
212 | pass $name |
213 | } | |
7be570e7 JM |
214 | } |
215 | ||
af69a5ce YQ |
216 | # Continue to breakpoint on catcher. |
217 | gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the second time" | |
218 | ||
591f19e8 TT |
219 | |
220 | # Continue to the re-throw. | |
221 | ||
222 | gdb_test "continue" "Catchpoint \[0-9\]+.*exception rethrown.*" \ | |
223 | "continue to rethrow" |