gdb/testsuite: make gdb.ada/mi_prot.exp stop at expected location
[binutils-gdb.git] / gdb / testsuite / gdb.ada / excep_handle.exp
1 # Copyright 2018-2022 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 load_lib "ada.exp"
17
18 if { [skip_ada_tests] } { return -1 }
19
20 standard_ada_testfile foo
21
22 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
23 return -1
24 }
25
26 clean_restart ${testfile}
27
28 # Some global variables used to simplify the maintenance of some of
29 # the regular expressions below.
30 set eol "\[\r\n\]+"
31 set sp "\[ \t\]*"
32
33 set when "when"
34 set catchpoint_constraint_error_msg \
35 "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Constraint_Error =>"
36
37 set catchpoint_program_error_msg \
38 "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Program_Error =>"
39
40 set catchpoint_storage_error_msg \
41 "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Storage_Error =>"
42
43 ############################################
44 # Check that runtime supports catchpoint. #
45 ############################################
46
47 if ![runto_main] then {
48 return 0
49 }
50
51 set msg "insert catchpoint on all Ada exceptions handlers"
52 gdb_test_multiple "catch handlers" $msg {
53 -re "Catchpoint $decimal: all Ada exceptions handlers$eol$gdb_prompt $" {
54 pass $msg
55 }
56 -re "Your Ada runtime appears to be missing some debugging information.*$eol$gdb_prompt $" {
57 # If the runtime was not built with enough debug information,
58 # or if it was stripped, we can not test exception handlers
59 # catchpoints.
60 unsupported $msg
61 return -1
62 }
63 }
64
65 ############################################
66 # 1. Try catching all exceptions handlers. #
67 ############################################
68
69 # Continue. The program should stop at first exception handling.
70
71 gdb_test "continue" \
72 "Continuing\.$eol$catchpoint_constraint_error_msg$eol.*" \
73 "continuing to first Constraint_Error exception handlers"
74
75 # Resume the program's exception.
76 #
77 # The program will first go through a block of code which has an
78 # exception handler, but since no exception is raised, we should
79 # not stop there. Instead, we expect to stop in the handler of
80 # the next exception being raised.
81
82 gdb_test "continue" \
83 "Continuing\.$eol$catchpoint_storage_error_msg$eol.*" \
84 "continuing and stopping in Storage_Error exception handlers"
85
86 gdb_test_no_output "delete 2" \
87 "delete catchpoint on all Ada exceptions handlers"
88
89 ##################################################
90 # 2. Try catching some named exception handlers. #
91 ##################################################
92
93 # Insert a catchpoint on Program_Error Ada exception handlers.
94
95 gdb_test "catch handlers Program_Error" \
96 "Catchpoint $decimal: `Program_Error' Ada exception handlers" \
97 "insert catchpoint on Program_Error Ada exception handlers"
98
99 # Continue, we should not stop at ABORT_SIGNAL but at Program_Error one.
100
101 gdb_test "continue" \
102 "Continuing\.$eol$catchpoint_program_error_msg$eol.*" \
103 "continuing without stopping to Program_Error exception handlers"
104
105 gdb_test_no_output \
106 "delete 3" \
107 "delete catchpoint on all Program_Error Ada exception handlers"
108
109 # Insert a catchpoint on Storage_Error Ada exception handlers.
110
111 gdb_test "catch handlers Storage_Error" \
112 "Catchpoint $decimal: `Storage_Error' Ada exception handlers" \
113 "insert catchpoint on Storage_Error Ada exception handlers"
114
115 # Continue, we should stop at Storage_Error handlers.
116
117 gdb_test "continue" \
118 "Continuing\.$eol$catchpoint_storage_error_msg$eol.*" \
119 "continuing without stopping to Storage_Error exception handlers"
120
121 gdb_test_no_output \
122 "delete 4" \
123 "delete catchpoint on all Storage_Error Ada exception handlers"
124
125 ########################################################################
126 # 3. Try catching with condition and without named exception handlers. #
127 ########################################################################
128
129 # Insert a catchpoint on all Ada exceptions handlers with condition.
130
131 gdb_test "catch handlers if Global_Var = 2" \
132 "Catchpoint $decimal: all Ada exceptions handlers" \
133 "insert catchpoint on all Ada exception handlers with condition"
134
135 # Check that condition is stored and properly displayed.
136
137 gdb_test "info breakpoint" "stop only if Global_Var = 2" \
138 "Check catch handlers with condition"
139
140 # Continue, we should not stop at ABORT_SIGNAL but at Program_Error one.
141
142 gdb_test "continue" \
143 "Continuing\.$eol$catchpoint_constraint_error_msg$eol.*" \
144 "continuing to second Constraint_Error exception handlers"
145
146 gdb_test_no_output \
147 "delete 5" \
148 "delete catchpoint on all all Ada exceptions handlers with condition"
149
150 ################################################################
151 # 4. Try catching with condition and named exception handlers. #
152 ################################################################
153
154 # Insert a catchpoint on Program_Error Ada exception handlers with
155 # condition.
156
157 gdb_test "catch handlers Program_Error if Global_Var = 4" \
158 "Catchpoint $decimal: `Program_Error' Ada exception handlers" \
159 "insert catchpoint on Program_Error Ada exception handlers with condition"
160
161 # Continue, we should not stop at first Program_Error handlers but at
162 # the second one.
163
164 gdb_test "continue" \
165 "Continuing\.$eol$catchpoint_program_error_msg$eol.*" \
166 "continuing to Program_Error exception handlers"
167
168 # Continue, the program should exit properly.
169
170 gdb_test "continue" \
171 "Continuing\..*$inferior_exited_re.*" \
172 "continuing to program completion"