Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.ada / catch_ex.exp
CommitLineData
88b9d363 1# Copyright 2007-2022 Free Software Foundation, Inc.
fd678c65
JB
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
fd678c65
JB
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
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
fd678c65 15
fd678c65
JB
16load_lib "ada.exp"
17
7a82e903
PA
18if { [skip_ada_tests] } { return -1 }
19
8223e12c 20standard_ada_testfile foo
fd678c65 21
fd678c65
JB
22if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
23 return -1
24}
25
09050809 26clean_restart ${testfile}
fd678c65
JB
27
28# Some global variables used to simplify the maintenance of some of
29# the regular expressions below.
30set any_nb "\[0-9\]+"
31set any_addr "0x\[0-9a-zA-Z\]+"
32set eol "\[\r\n\]+"
33set sp "\[ \t\]*"
34
35set info_break_header "Num${sp}Type${sp}Disp${sp}Enb${sp}Address${sp}What"
36set catch_exception_info \
f06f1252 37 "$any_nb${sp}catchpoint${sp}keep${sp}y${sp}all Ada exceptions"
fd678c65
JB
38
39####################################
40# 1. Try catching all exceptions. #
41####################################
42
43if ![runto_main] then {
bc6c7af4 44 fail "cannot run to main, testcase aborted"
fd678c65
JB
45 return 0
46}
47
4741b737
DJ
48set msg "insert catchpoint on all Ada exceptions"
49gdb_test_multiple "catch exception" $msg {
50 -re "Catchpoint $any_nb: all Ada exceptions$eol$gdb_prompt $" {
51 pass $msg
52 }
a6af7abe 53 -re "Your Ada runtime appears to be missing some debugging information.*$eol$gdb_prompt $" {
4741b737
DJ
54 # If the runtime was not built with enough debug information,
55 # or if it was stripped, we can not test exception
56 # catchpoints.
57 unsupported $msg
58 return -1
59 }
60}
fd678c65
JB
61
62gdb_test "info break" \
63 "$info_break_header$eol.*$catch_exception_info" \
64 "info break, catch all Ada exceptions"
65
66set catchpoint_msg \
15f3b077 67 "Catchpoint $any_nb, CONSTRAINT_ERROR (\\\(ignore C_E\\\) )?at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
fd678c65
JB
68gdb_test "continue" \
69 "Continuing\.$eol$catchpoint_msg$eol.*SPOT1" \
70 "continuing to first exception"
71
72set catchpoint_msg \
e547c119 73 "Catchpoint $any_nb, PROGRAM_ERROR (\\\(foo\\.adb:$decimal explicit raise\\\) )?at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
fd678c65
JB
74gdb_test "continue" \
75 "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
76 "continuing to second exception"
77
78################################################
79# 2. Try catching only some of the exceptions. #
80################################################
81
82# Here is the scenario:
83# - Restart the debugger from scratch, runto_main
84# - We'll catch only "Program_Error"
85# We'll catch assertions
86# We'll catch unhandled exceptions
87# - continue, we should see the first Program_Error exception
88# - continue, we should see the failed assertion
89# - continue, we should see the unhandled Constrait_Error exception
90# - continue, the program exits.
91
92if ![runto_main] then {
bc6c7af4 93 fail "cannot run to main, testcase aborted"
fd678c65
JB
94 return 0
95}
96
97gdb_test "catch exception Program_Error" \
98 "Catchpoint $any_nb: \`Program_Error' Ada exception" \
99 "insert catchpoint on Program_Error"
100
101gdb_test "catch assert" \
102 "Catchpoint $any_nb: failed Ada assertions" \
103 "insert catchpoint on failed assertions"
104
105gdb_test "catch exception unhandled" \
106 "Catchpoint $any_nb: unhandled Ada exceptions" \
107 "insert catchpoint on unhandled exceptions"
108
109set catch_exception_entry \
f06f1252 110 "$any_nb${sp}catchpoint${sp}keep${sp}y${sp}\`Program_Error' Ada exception"
fd678c65 111set catch_assert_entry \
f06f1252 112 "$any_nb${sp}catchpoint${sp}keep${sp}y${sp}failed Ada assertions"
fd678c65 113set catch_unhandled_entry \
f06f1252 114 "$any_nb${sp}catchpoint${sp}keep${sp}y${sp}unhandled Ada exceptions"
fd678c65
JB
115
116gdb_test "info break" \
117 "$info_break_header$eol.*$catch_exception_entry$eol$catch_assert_entry$eol$catch_unhandled_entry" \
118 "info break, second run"
119
120set catchpoint_msg \
e547c119 121 "Catchpoint $any_nb, PROGRAM_ERROR (\\\(foo.adb:$decimal explicit raise\\\) )?at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
fd678c65
JB
122gdb_test "continue" \
123 "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
124 "continuing to Program_Error exception"
125
126set catchpoint_msg \
127 "Catchpoint $any_nb, failed assertion at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
128gdb_test "continue" \
129 "Continuing\.$eol$catchpoint_msg$eol.*SPOT3" \
9836f81b 130 "continuing to failed assertion"
fd678c65
JB
131
132set catchpoint_msg \
133 "Catchpoint $any_nb, unhandled CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
134gdb_test "continue" \
135 "Continuing\.$eol$catchpoint_msg$eol.*SPOT4" \
9836f81b 136 "continuing to unhandled exception"
fd678c65 137
5dbdd470
TT
138gdb_test "continue" \
139 "Continuing\..*$inferior_exited_re.*" \
140 "continuing to program completion"
fd678c65 141
00eb2c4a
JB
142#################################
143# 3. Try temporary catchpoints. #
144#################################
145
146# Scenario:
147# - Insert a temporary catchpoint on all exceptions.
148# - Run to that catchpoint
149# - Continue; we should reach the program's exit, not stopping
150# at any of the other exceptions that are being raised inside
151# the program.
152
153if ![runto_main] then {
bc6c7af4 154 fail "cannot run to main, testcase aborted"
00eb2c4a
JB
155 return 0
156}
157
158gdb_test "tcatch exception" \
159 "Temporary catchpoint $any_nb: all Ada exceptions"
160
161set temp_catchpoint_msg \
e547c119 162 "Temporary catchpoint $any_nb, CONSTRAINT_ERROR (\\\(.*\\\) )?at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
00eb2c4a
JB
163gdb_test "continue" \
164 "Continuing\.$eol$temp_catchpoint_msg$eol.*SPOT1" \
165 "continuing to temporary catchpoint"
166
dbb0ab10
TV
167with_test_prefix "temporary catchpoint" {
168 gdb_test "continue" \
169 "Continuing\..*$inferior_exited_re.*" \
170 "continuing to program completion"
171}
00eb2c4a 172
fd678c65 173
This page took 1.8187 seconds and 4 git commands to generate.