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