gdb: Remove a non-const reference parameter
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-catch-cpp-exceptions.exp
1 # Copyright 2019 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 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
30 # Grab some line numbers we'll need.
31 set catch_1_lineno [gdb_get_line_number "Catch 1"]
32 set catch_2_lineno [gdb_get_line_number "Catch 2"]
33 set throw_1_lineno [gdb_get_line_number "Throw 1"]
34 set throw_2_lineno [gdb_get_line_number "Throw 2"]
35 set main_lineno [gdb_get_line_number "Stop here"]
36
37 # Restart this test, load the test binary and set a breakpoint in
38 # main.
39 proc restart_for_test {} {
40 global srcdir subdir binfile srcfile
41 global main_lineno
42
43 if {[mi_gdb_start]} {
44 continue
45 }
46
47 mi_delete_breakpoints
48 mi_gdb_reinitialize_dir $srcdir/$subdir
49 mi_gdb_load ${binfile}
50
51 mi_runto main
52
53 mi_create_breakpoint \
54 "$srcfile:${main_lineno}" "break before exiting program" \
55 -disp keep -func "main.*" \
56 -file ".*mi-catch-cpp-exceptions.cc" -line ${main_lineno}
57 }
58
59 # Issue an -exec-continue then wait for GDB to catch a C++ exception
60 # event in FUNC on LINE. Use TESTNAME to make tests unique.
61 proc continue_to_next_exception { func line testname } {
62 global hex
63
64 mi_send_resuming_command "exec-continue" \
65 "exec-continue"
66 mi_expect_stop "exception-caught" ".*" ".*" ".*" ".*" \
67 {} "run until an exception is caught: $testname"
68 mi_gdb_test "-stack-list-frames 1 1" \
69 "\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"${func}\",.*,line=\"${line}\".*\}\\\]" \
70 "check previous frame: $testname"
71 }
72
73 # Issue an -exec-continue and stop at the breakpoint in main.
74 proc continue_to_breakpoint_in_main {} {
75 global main_lineno
76
77 mi_send_resuming_command "exec-continue" "exec-continue to main"
78 mi_expect_stop "breakpoint-hit" "main" ".*" ".*" "${main_lineno}" \
79 {.* disp="keep"} "run until breakpoint in main"
80 }
81
82 # TYPE is one of throw, rethrow, or catch. This proc creates a catch
83 # point using -catch-TYPE. The optional string EXTRA is any extra
84 # arguments to pass when setting up the catchpoint.
85 proc setup_catchpoint {type {extra ""}} {
86 global decimal
87 mi_gdb_test "-catch-${type} ${extra}" \
88 "\\^done,bkpt=\{number=\"$decimal\",type=\"catchpoint\".*what=\"exception ${type}\",catch-type=\"${type}\".*\}" \
89 "Setup -catch-${type}"
90 }
91
92 # Ensure that -catch-throw will catch only throws and nothing else.
93 with_test_prefix "-catch-throw" {
94 restart_for_test
95 setup_catchpoint "throw"
96 continue_to_next_exception "bar" "${throw_1_lineno}" "throw 1"
97 continue_to_next_exception "bar" "${throw_1_lineno}" "throw 2"
98 continue_to_next_exception "bar" "${throw_1_lineno}" "throw 3"
99 continue_to_next_exception "bar" "${throw_1_lineno}" "throw 4"
100 continue_to_breakpoint_in_main
101 }
102
103 # Ensure that -catch-rethrow catches only rethrows and nothing else.
104 with_test_prefix "-catch-rethrow" {
105 restart_for_test
106 setup_catchpoint "rethrow"
107 continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 1"
108 continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 2"
109 continue_to_breakpoint_in_main
110 }
111
112 # Ensure that -catch-catch catches only catch points, and nothing
113 # else.
114 with_test_prefix "-catch-catch" {
115 restart_for_test
116 setup_catchpoint "catch"
117 continue_to_next_exception "foo" "${catch_1_lineno}" "catch 1"
118 continue_to_next_exception "foo" "${catch_1_lineno}" "catch 2"
119 continue_to_next_exception "main" "${catch_2_lineno}" "catch 3"
120 continue_to_next_exception "foo" "${catch_1_lineno}" "catch 4"
121 continue_to_next_exception "foo" "${catch_1_lineno}" "catch 5"
122 continue_to_next_exception "main" "${catch_2_lineno}" "catch 6"
123 continue_to_breakpoint_in_main
124 }
125
126 # Now check that all of the command with a regexp that doesn't match,
127 # don't trigger.
128 with_test_prefix "all with invalid regexp" {
129 restart_for_test
130 setup_catchpoint "throw" "-r blahblah"
131 setup_catchpoint "rethrow" "-r woofwoof"
132 setup_catchpoint "catch" "-r miowmiow"
133 continue_to_breakpoint_in_main
134 }
135
136 # Now check that all of the commands with a regexp that does match,
137 # still trigger.
138 with_test_prefix "all with valid regexp" {
139 restart_for_test
140 setup_catchpoint "throw" "-r my_ex"
141 setup_catchpoint "rethrow" "-r _except"
142 setup_catchpoint "catch" "-r my_exception"
143 continue_to_next_exception "bar" "${throw_1_lineno}" "throw 1"
144 continue_to_next_exception "foo" "${catch_1_lineno}" "catch 1"
145 continue_to_next_exception "bar" "${throw_1_lineno}" "throw 2"
146 continue_to_next_exception "foo" "${catch_1_lineno}" "catch 2"
147 continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 1"
148 continue_to_next_exception "main" "${catch_2_lineno}" "catch 3"
149 continue_to_next_exception "bar" "${throw_1_lineno}" "throw 3"
150 continue_to_next_exception "foo" "${catch_1_lineno}" "catch 4"
151 continue_to_next_exception "bar" "${throw_1_lineno}" "throw 4"
152 continue_to_next_exception "foo" "${catch_1_lineno}" "catch 5"
153 continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 2"
154 continue_to_next_exception "main" "${catch_2_lineno}" "catch 6"
155 continue_to_breakpoint_in_main
156 }
157
158 # Check that the temporary switch works on its own.
159 with_test_prefix "all with -t" {
160 restart_for_test
161 setup_catchpoint "throw" "-t"
162 setup_catchpoint "rethrow" "-t"
163 setup_catchpoint "catch" "-t"
164 continue_to_next_exception "bar" "${throw_1_lineno}" "throw 1"
165 continue_to_next_exception "foo" "${catch_1_lineno}" "catch 1"
166 continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 1"
167 continue_to_breakpoint_in_main
168 }
169
170 # Check that the temporary switch works when used with a regexp.
171 restart_for_test
172 with_test_prefix "all with -t and regexp" {
173 setup_catchpoint "throw" "-t -r my_ex"
174 setup_catchpoint "rethrow" "-t -r _except"
175 setup_catchpoint "catch" "-t -r my_exception"
176 continue_to_next_exception "bar" "${throw_1_lineno}" "throw 1"
177 continue_to_next_exception "foo" "${catch_1_lineno}" "catch 1"
178 continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 1"
179 continue_to_breakpoint_in_main
180 }
This page took 0.034186 seconds and 4 git commands to generate.