]>
Commit | Line | Data |
---|---|---|
4a94e368 | 1 | # Copyright 2019-2022 Free Software Foundation, Inc. |
30056ea0 AB |
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 3 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, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | # Test the -catch-throw, -catch-rethrow, and -catch-catch MI commands. | |
17 | ||
18 | if { [skip_cplus_tests] } { continue } | |
19 | ||
20 | load_lib mi-support.exp | |
21 | set MIFLAGS "-i=mi" | |
22 | ||
23 | standard_testfile .cc | |
24 | ||
25 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { | |
26 | untested "failed to compile" | |
27 | return -1 | |
28 | } | |
29 | ||
b75d55d4 PA |
30 | mi_clean_restart $binfile |
31 | if {[mi_runto_main] < 0} { | |
297989a1 TV |
32 | return -1 |
33 | } | |
b694989f | 34 | set libstdcxx_probe_tests_supported [expr ![mi_skip_libstdcxx_probe_tests]] |
297989a1 | 35 | |
30056ea0 AB |
36 | # Grab some line numbers we'll need. |
37 | set catch_1_lineno [gdb_get_line_number "Catch 1"] | |
38 | set catch_2_lineno [gdb_get_line_number "Catch 2"] | |
39 | set throw_1_lineno [gdb_get_line_number "Throw 1"] | |
40 | set throw_2_lineno [gdb_get_line_number "Throw 2"] | |
41 | set main_lineno [gdb_get_line_number "Stop here"] | |
42 | ||
43 | # Restart this test, load the test binary and set a breakpoint in | |
44 | # main. | |
45 | proc restart_for_test {} { | |
46 | global srcdir subdir binfile srcfile | |
47 | global main_lineno | |
48 | ||
49 | if {[mi_gdb_start]} { | |
50 | continue | |
51 | } | |
52 | ||
53 | mi_delete_breakpoints | |
54 | mi_gdb_reinitialize_dir $srcdir/$subdir | |
55 | mi_gdb_load ${binfile} | |
56 | ||
f71e6719 | 57 | mi_runto_main |
30056ea0 AB |
58 | |
59 | mi_create_breakpoint \ | |
60 | "$srcfile:${main_lineno}" "break before exiting program" \ | |
61 | -disp keep -func "main.*" \ | |
62 | -file ".*mi-catch-cpp-exceptions.cc" -line ${main_lineno} | |
63 | } | |
64 | ||
65 | # Issue an -exec-continue then wait for GDB to catch a C++ exception | |
66 | # event in FUNC on LINE. Use TESTNAME to make tests unique. | |
67 | proc continue_to_next_exception { func line testname } { | |
68 | global hex | |
69 | ||
70 | mi_send_resuming_command "exec-continue" \ | |
71 | "exec-continue" | |
72 | mi_expect_stop "exception-caught" ".*" ".*" ".*" ".*" \ | |
73 | {} "run until an exception is caught: $testname" | |
74 | mi_gdb_test "-stack-list-frames 1 1" \ | |
75 | "\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"${func}\",.*,line=\"${line}\".*\}\\\]" \ | |
76 | "check previous frame: $testname" | |
77 | } | |
78 | ||
79 | # Issue an -exec-continue and stop at the breakpoint in main. | |
80 | proc continue_to_breakpoint_in_main {} { | |
81 | global main_lineno | |
82 | ||
83 | mi_send_resuming_command "exec-continue" "exec-continue to main" | |
84 | mi_expect_stop "breakpoint-hit" "main" ".*" ".*" "${main_lineno}" \ | |
85 | {.* disp="keep"} "run until breakpoint in main" | |
86 | } | |
87 | ||
88 | # TYPE is one of throw, rethrow, or catch. This proc creates a catch | |
89 | # point using -catch-TYPE. The optional string EXTRA is any extra | |
90 | # arguments to pass when setting up the catchpoint. | |
91 | proc setup_catchpoint {type {extra ""}} { | |
92 | global decimal | |
93 | mi_gdb_test "-catch-${type} ${extra}" \ | |
cb1e4e32 | 94 | "\\^done,bkpt=\{number=\"$decimal\",type=\"catchpoint\".*what=\"exception ${type}\",catch-type=\"${type}\".*\}" \ |
30056ea0 AB |
95 | "Setup -catch-${type}" |
96 | } | |
97 | ||
98 | # Ensure that -catch-throw will catch only throws and nothing else. | |
99 | with_test_prefix "-catch-throw" { | |
100 | restart_for_test | |
101 | setup_catchpoint "throw" | |
102 | continue_to_next_exception "bar" "${throw_1_lineno}" "throw 1" | |
103 | continue_to_next_exception "bar" "${throw_1_lineno}" "throw 2" | |
104 | continue_to_next_exception "bar" "${throw_1_lineno}" "throw 3" | |
105 | continue_to_next_exception "bar" "${throw_1_lineno}" "throw 4" | |
106 | continue_to_breakpoint_in_main | |
107 | } | |
108 | ||
109 | # Ensure that -catch-rethrow catches only rethrows and nothing else. | |
110 | with_test_prefix "-catch-rethrow" { | |
111 | restart_for_test | |
112 | setup_catchpoint "rethrow" | |
113 | continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 1" | |
114 | continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 2" | |
115 | continue_to_breakpoint_in_main | |
116 | } | |
117 | ||
118 | # Ensure that -catch-catch catches only catch points, and nothing | |
119 | # else. | |
120 | with_test_prefix "-catch-catch" { | |
121 | restart_for_test | |
122 | setup_catchpoint "catch" | |
123 | continue_to_next_exception "foo" "${catch_1_lineno}" "catch 1" | |
124 | continue_to_next_exception "foo" "${catch_1_lineno}" "catch 2" | |
125 | continue_to_next_exception "main" "${catch_2_lineno}" "catch 3" | |
126 | continue_to_next_exception "foo" "${catch_1_lineno}" "catch 4" | |
127 | continue_to_next_exception "foo" "${catch_1_lineno}" "catch 5" | |
128 | continue_to_next_exception "main" "${catch_2_lineno}" "catch 6" | |
129 | continue_to_breakpoint_in_main | |
130 | } | |
131 | ||
297989a1 TV |
132 | if { $libstdcxx_probe_tests_supported == 1 } { |
133 | # Now check that all of the command with a regexp that doesn't match, | |
134 | # don't trigger. | |
135 | with_test_prefix "all with invalid regexp" { | |
136 | restart_for_test | |
137 | setup_catchpoint "throw" "-r blahblah" | |
138 | setup_catchpoint "rethrow" "-r woofwoof" | |
139 | setup_catchpoint "catch" "-r miowmiow" | |
140 | continue_to_breakpoint_in_main | |
141 | } | |
142 | } else { | |
143 | unsupported "all with invalid regexp" | |
30056ea0 AB |
144 | } |
145 | ||
297989a1 TV |
146 | if { $libstdcxx_probe_tests_supported == 1 } { |
147 | # Now check that all of the commands with a regexp that does match, | |
148 | # still trigger. | |
149 | with_test_prefix "all with valid regexp" { | |
150 | restart_for_test | |
151 | setup_catchpoint "throw" "-r my_ex" | |
152 | setup_catchpoint "rethrow" "-r _except" | |
153 | setup_catchpoint "catch" "-r my_exception" | |
154 | continue_to_next_exception "bar" "${throw_1_lineno}" "throw 1" | |
155 | continue_to_next_exception "foo" "${catch_1_lineno}" "catch 1" | |
156 | continue_to_next_exception "bar" "${throw_1_lineno}" "throw 2" | |
157 | continue_to_next_exception "foo" "${catch_1_lineno}" "catch 2" | |
158 | continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 1" | |
159 | continue_to_next_exception "main" "${catch_2_lineno}" "catch 3" | |
160 | continue_to_next_exception "bar" "${throw_1_lineno}" "throw 3" | |
161 | continue_to_next_exception "foo" "${catch_1_lineno}" "catch 4" | |
162 | continue_to_next_exception "bar" "${throw_1_lineno}" "throw 4" | |
163 | continue_to_next_exception "foo" "${catch_1_lineno}" "catch 5" | |
164 | continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 2" | |
165 | continue_to_next_exception "main" "${catch_2_lineno}" "catch 6" | |
166 | continue_to_breakpoint_in_main | |
167 | } | |
168 | } else { | |
169 | unsupported "all with valid regexp" | |
30056ea0 AB |
170 | } |
171 | ||
172 | # Check that the temporary switch works on its own. | |
173 | with_test_prefix "all with -t" { | |
174 | restart_for_test | |
175 | setup_catchpoint "throw" "-t" | |
176 | setup_catchpoint "rethrow" "-t" | |
177 | setup_catchpoint "catch" "-t" | |
178 | continue_to_next_exception "bar" "${throw_1_lineno}" "throw 1" | |
179 | continue_to_next_exception "foo" "${catch_1_lineno}" "catch 1" | |
180 | continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 1" | |
181 | continue_to_breakpoint_in_main | |
182 | } | |
183 | ||
297989a1 TV |
184 | if { $libstdcxx_probe_tests_supported == 1 } { |
185 | # Check that the temporary switch works when used with a regexp. | |
186 | restart_for_test | |
187 | with_test_prefix "all with -t and regexp" { | |
188 | setup_catchpoint "throw" "-t -r my_ex" | |
189 | setup_catchpoint "rethrow" "-t -r _except" | |
190 | setup_catchpoint "catch" "-t -r my_exception" | |
191 | continue_to_next_exception "bar" "${throw_1_lineno}" "throw 1" | |
192 | continue_to_next_exception "foo" "${catch_1_lineno}" "catch 1" | |
193 | continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 1" | |
194 | continue_to_breakpoint_in_main | |
195 | } | |
196 | } else { | |
197 | unsupported "all with -t and regexp" | |
30056ea0 | 198 | } |