1 # Copyright 2007-2024 Free Software Foundation, Inc.
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.
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.
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/>.
18 require allow_ada_tests gnat_runtime_has_debug_info
20 standard_ada_testfile foo
22 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
26 clean_restart ${testfile}
28 # Some global variables used to simplify the maintenance of some of
29 # the regular expressions below.
31 set any_addr "0x\[0-9a-zA-Z\]+"
35 set info_break_header "Num${sp}Type${sp}Disp${sp}Enb${sp}Address${sp}What"
36 set catch_exception_info \
37 "$any_nb${sp}catchpoint${sp}keep${sp}y${sp}all Ada exceptions"
39 ####################################
40 # 1. Try catching all exceptions. #
41 ####################################
47 gdb_test "catch exception" \
48 "Catchpoint $any_nb: all Ada exceptions" \
49 "insert catchpoint on all Ada exceptions"
51 gdb_test "info break" \
52 "$info_break_header$eol.*$catch_exception_info" \
53 "info break, catch all Ada exceptions"
56 "Catchpoint $any_nb, CONSTRAINT_ERROR (\\\(ignore C_E\\\) )?at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
58 "Continuing\\.$eol$eol$catchpoint_msg$eol.*SPOT1" \
59 "continuing to first exception"
62 "Catchpoint $any_nb, PROGRAM_ERROR (\\\(foo\\.adb:$decimal explicit raise\\\) )?at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
64 "Continuing\\.$eol$eol$catchpoint_msg$eol.*SPOT2" \
65 "continuing to second exception"
67 ################################################
68 # 2. Try catching only some of the exceptions. #
69 ################################################
71 # Here is the scenario:
72 # - Restart the debugger from scratch, runto_main
73 # - We'll catch only "Program_Error"
74 # We'll catch assertions
75 # We'll catch unhandled exceptions
76 # - continue, we should see the first Program_Error exception
77 # - continue, we should see the failed assertion
78 # - continue, we should see the unhandled Constrait_Error exception
79 # - continue, the program exits.
85 gdb_test "catch exception Program_Error" \
86 "Catchpoint $any_nb: \`Program_Error' Ada exception" \
87 "insert catchpoint on Program_Error"
89 gdb_test "catch assert" \
90 "Catchpoint $any_nb: failed Ada assertions" \
91 "insert catchpoint on failed assertions"
93 gdb_test "catch exception unhandled" \
94 "Catchpoint $any_nb: unhandled Ada exceptions" \
95 "insert catchpoint on unhandled exceptions"
97 set catch_exception_entry \
98 "$any_nb${sp}catchpoint${sp}keep${sp}y${sp}\`Program_Error' Ada exception"
99 set catch_assert_entry \
100 "$any_nb${sp}catchpoint${sp}keep${sp}y${sp}failed Ada assertions"
101 set catch_unhandled_entry \
102 "$any_nb${sp}catchpoint${sp}keep${sp}y${sp}unhandled Ada exceptions"
104 gdb_test "info break" \
105 "$info_break_header$eol.*$catch_exception_entry$eol$catch_assert_entry$eol$catch_unhandled_entry" \
106 "info break, second run"
109 "Catchpoint $any_nb, PROGRAM_ERROR (\\\(foo.adb:$decimal explicit raise\\\) )?at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
110 gdb_test "continue" \
111 "Continuing\\.$eol$eol$catchpoint_msg$eol.*SPOT2" \
112 "continuing to Program_Error exception"
115 "Catchpoint $any_nb, failed assertion at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
116 gdb_test "continue" \
117 "Continuing\\.$eol$eol$catchpoint_msg$eol.*SPOT3" \
118 "continuing to failed assertion"
121 "Catchpoint $any_nb, unhandled CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
122 gdb_test "continue" \
123 "Continuing\\.$eol$eol$catchpoint_msg$eol.*SPOT4" \
124 "continuing to unhandled exception"
126 gdb_test "continue" \
127 "Continuing\\..*$inferior_exited_re.*" \
128 "continuing to program completion"
130 #################################
131 # 3. Try temporary catchpoints. #
132 #################################
135 # - Insert a temporary catchpoint on all exceptions.
136 # - Run to that catchpoint
137 # - Continue; we should reach the program's exit, not stopping
138 # at any of the other exceptions that are being raised inside
145 gdb_test "tcatch exception" \
146 "Temporary catchpoint $any_nb: all Ada exceptions"
148 set temp_catchpoint_msg \
149 "Temporary catchpoint $any_nb, CONSTRAINT_ERROR (\\\(.*\\\) )?at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
150 gdb_test "continue" \
151 "Continuing\\.$eol$eol$temp_catchpoint_msg$eol.*SPOT1" \
152 "continuing to temporary catchpoint"
154 with_test_prefix "temporary catchpoint" {
155 gdb_test "continue" \
156 "Continuing\\..*$inferior_exited_re.*" \
157 "continuing to program completion"