]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.ada/catch_ex.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.ada / catch_ex.exp
1 # Copyright 2007-2024 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 require allow_ada_tests gnat_runtime_has_debug_info
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 any_nb "\[0-9\]+"
31 set any_addr "0x\[0-9a-zA-Z\]+"
32 set eol "\r\n"
33 set sp "\[ \t\]*"
34
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"
38
39 ####################################
40 # 1. Try catching all exceptions. #
41 ####################################
42
43 if {![runto_main]} {
44 return 0
45 }
46
47 gdb_test "catch exception" \
48 "Catchpoint $any_nb: all Ada exceptions" \
49 "insert catchpoint on all Ada exceptions"
50
51 gdb_test "info break" \
52 "$info_break_header$eol.*$catch_exception_info" \
53 "info break, catch all Ada exceptions"
54
55 set catchpoint_msg \
56 "Catchpoint $any_nb, CONSTRAINT_ERROR (\\\(ignore C_E\\\) )?at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
57 gdb_test "continue" \
58 "Continuing\.$eol$eol$catchpoint_msg$eol.*SPOT1" \
59 "continuing to first exception"
60
61 set catchpoint_msg \
62 "Catchpoint $any_nb, PROGRAM_ERROR (\\\(foo\\.adb:$decimal explicit raise\\\) )?at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
63 gdb_test "continue" \
64 "Continuing\.$eol$eol$catchpoint_msg$eol.*SPOT2" \
65 "continuing to second exception"
66
67 ################################################
68 # 2. Try catching only some of the exceptions. #
69 ################################################
70
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.
80
81 if {![runto_main]} {
82 return 0
83 }
84
85 gdb_test "catch exception Program_Error" \
86 "Catchpoint $any_nb: \`Program_Error' Ada exception" \
87 "insert catchpoint on Program_Error"
88
89 gdb_test "catch assert" \
90 "Catchpoint $any_nb: failed Ada assertions" \
91 "insert catchpoint on failed assertions"
92
93 gdb_test "catch exception unhandled" \
94 "Catchpoint $any_nb: unhandled Ada exceptions" \
95 "insert catchpoint on unhandled exceptions"
96
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"
103
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"
107
108 set catchpoint_msg \
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"
113
114 set catchpoint_msg \
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"
119
120 set catchpoint_msg \
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"
125
126 gdb_test "continue" \
127 "Continuing\..*$inferior_exited_re.*" \
128 "continuing to program completion"
129
130 #################################
131 # 3. Try temporary catchpoints. #
132 #################################
133
134 # Scenario:
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
139 # the program.
140
141 if {![runto_main]} {
142 return 0
143 }
144
145 gdb_test "tcatch exception" \
146 "Temporary catchpoint $any_nb: all Ada exceptions"
147
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"
153
154 with_test_prefix "temporary catchpoint" {
155 gdb_test "continue" \
156 "Continuing\..*$inferior_exited_re.*" \
157 "continuing to program completion"
158 }
159
160