1 # Copyright 2011-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 # A global variable used to simplify the maintenance of some of
27 # the regular expressions below.
30 load_lib mi-support.exp
33 mi_clean_restart $binfile
35 ####################################
36 # 1. Try catching all exceptions. #
37 ####################################
39 with_test_prefix "scenario 1" {
40 if {[mi_runto_main] < 0} {
45 mi_gdb_test "-catch-exception" \
46 "\\^done,bkptno=\"$decimal\",bkpt={.*disp=\"keep\",enabled=\"y\",what=\"all Ada exceptions\",.*}" \
47 "catch all exceptions"
49 # Continue to caught exception.
51 proc continue_to_exception { exception_name exception_message test } {
54 mi_send_resuming_command "exec-continue" "$test"
56 # Match console stream output.
58 -re " $exception_name\( \\($exception_message\\)\)? at $hex in foo " {
61 fail "$test (timeout)"
66 # Now MI stream output.
68 "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"$exception_name\(\",exception-message=\"$exception_message\)?\"" \
74 continue_to_exception \
75 "CONSTRAINT_ERROR" "foo\\.adb:$decimal explicit raise" \
76 "continue until CE caught by all-exceptions catchpoint"
78 continue_to_exception \
79 "PROGRAM_ERROR" "foo\\.adb:$decimal explicit raise" \
80 "continue until PE caught by all-exceptions catchpoint"
82 ################################################
83 # 2. Try catching only some of the exceptions. #
84 ################################################
86 # Here is the scenario:
87 # - Restart the debugger from scratch, runto_main
88 # - We'll catch only "Program_Error"
89 # We'll catch assertions
90 # We'll catch unhandled exceptions
91 # - continue, we should see the first Program_Error exception
92 # - continue, we should see the failed assertion
93 # - continue, we should see the unhandled Constrait_Error exception
94 # - continue, the program exits.
96 with_test_prefix "scenario 2" {
98 if {[mi_runto_main] < 0} {
103 mi_gdb_test "-catch-exception -e Program_Error" \
104 "\\^done,bkptno=\"$decimal\",bkpt={.*disp=\"keep\",enabled=\"y\",what=\"`Program_Error' Ada exception\",.*}" \
105 "catch Program_Error"
107 mi_gdb_test "-catch-assert" \
108 "\\^done,bkptno=\"$decimal\",bkpt={.*disp=\"keep\",enabled=\"y\",what=\"failed Ada assertions\",.*}" \
109 "catch assert failures"
111 mi_gdb_test "-catch-exception -u" \
112 "\\^done,bkptno=\"$decimal\",bkpt={.*disp=\"keep\",enabled=\"y\",what=\"unhandled Ada exceptions\",.*}" \
113 "catch unhandled exceptions"
115 mi_execute_to "exec-continue" \
116 "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"PROGRAM_ERROR(\",exception-message=\"foo\\.adb:$decimal explicit raise)?\"" \
119 "continue to exception catchpoint hit"
121 mi_execute_to "exec-continue" \
122 "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\"" \
125 "continue to assert failure catchpoint hit"
127 mi_execute_to "exec-continue" \
128 "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"CONSTRAINT_ERROR\"" \
131 "continue to unhandled exception catchpoint hit"