1 # Copyright 2007, 2008, 2009 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/>.
22 set testdir "catch_ex"
23 set testfile "${testdir}/foo"
24 set srcfile ${srcdir}/${subdir}/${testfile}.adb
25 set binfile ${objdir}/${subdir}/${testfile}
27 file mkdir ${objdir}/${subdir}/${testdir}
28 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
34 gdb_reinitialize_dir $srcdir/$subdir
37 # Some global variables used to simplify the maintenance of some of
38 # the regular expressions below.
40 set any_addr "0x\[0-9a-zA-Z\]+"
44 set info_break_header "Num${sp}Type${sp}Disp${sp}Enb${sp}Address${sp}What"
45 set catch_exception_info \
46 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}all Ada exceptions"
48 ####################################
49 # 1. Try catching all exceptions. #
50 ####################################
52 if ![runto_main] then {
53 fail "Cannot run to main, testcase aborted"
57 set msg "insert catchpoint on all Ada exceptions"
58 gdb_test_multiple "catch exception" $msg {
59 -re "Catchpoint $any_nb: all Ada exceptions$eol$gdb_prompt $" {
62 -re "Cannot break on __gnat_raise_nodefer_with_msg in this configuration\.$eol$gdb_prompt $" {
63 # If the runtime was not built with enough debug information,
64 # or if it was stripped, we can not test exception
71 gdb_test "info break" \
72 "$info_break_header$eol.*$catch_exception_info" \
73 "info break, catch all Ada exceptions"
76 "Catchpoint $any_nb, CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
78 "Continuing\.$eol$catchpoint_msg$eol.*SPOT1" \
79 "continuing to first exception"
82 "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
84 "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
85 "continuing to second exception"
87 ################################################
88 # 2. Try catching only some of the exceptions. #
89 ################################################
91 # Here is the scenario:
92 # - Restart the debugger from scratch, runto_main
93 # - We'll catch only "Program_Error"
94 # We'll catch assertions
95 # We'll catch unhandled exceptions
96 # - continue, we should see the first Program_Error exception
97 # - continue, we should see the failed assertion
98 # - continue, we should see the unhandled Constrait_Error exception
99 # - continue, the program exits.
101 if ![runto_main] then {
102 fail "Cannot run to main, testcase aborted"
106 gdb_test "catch exception Program_Error" \
107 "Catchpoint $any_nb: \`Program_Error' Ada exception" \
108 "insert catchpoint on Program_Error"
110 gdb_test "catch assert" \
111 "Catchpoint $any_nb: failed Ada assertions" \
112 "insert catchpoint on failed assertions"
114 gdb_test "catch exception unhandled" \
115 "Catchpoint $any_nb: unhandled Ada exceptions" \
116 "insert catchpoint on unhandled exceptions"
118 set catch_exception_entry \
119 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}\`Program_Error' Ada exception"
120 set catch_assert_entry \
121 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}failed Ada assertions"
122 set catch_unhandled_entry \
123 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}unhandled Ada exceptions"
125 gdb_test "info break" \
126 "$info_break_header$eol.*$catch_exception_entry$eol$catch_assert_entry$eol$catch_unhandled_entry" \
127 "info break, second run"
130 "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
131 gdb_test "continue" \
132 "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
133 "continuing to Program_Error exception"
136 "Catchpoint $any_nb, failed assertion at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
137 gdb_test "continue" \
138 "Continuing\.$eol$catchpoint_msg$eol.*SPOT3" \
139 "continuing to failed assertion"
142 "Catchpoint $any_nb, unhandled CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
143 gdb_test "continue" \
144 "Continuing\.$eol$catchpoint_msg$eol.*SPOT4" \
145 "continuing to unhandled exception"
147 gdb_test "continue" \
148 "Continuing\..*Program exited.*" \
149 "continuing to program completion"