1 # Copyright 2007 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 2 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, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 set testdir "catch_ex"
25 set testfile "${testdir}/foo"
26 set srcfile ${srcdir}/${subdir}/${testfile}.adb
27 set binfile ${objdir}/${subdir}/${testfile}
29 file mkdir ${objdir}/${subdir}/${testdir}
30 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
36 gdb_reinitialize_dir $srcdir/$subdir
39 # Some global variables used to simplify the maintenance of some of
40 # the regular expressions below.
42 set any_addr "0x\[0-9a-zA-Z\]+"
46 set info_break_header "Num${sp}Type${sp}Disp${sp}Enb${sp}Address${sp}What"
47 set catch_exception_info \
48 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}all Ada exceptions"
50 ####################################
51 # 1. Try catching all exceptions. #
52 ####################################
54 if ![runto_main] then {
55 fail "Cannot run to main, testcase aborted"
59 set msg "insert catchpoint on all Ada exceptions"
60 gdb_test_multiple "catch exception" $msg {
61 -re "Catchpoint $any_nb: all Ada exceptions$eol$gdb_prompt $" {
64 -re "Cannot break on __gnat_raise_nodefer_with_msg in this configuration\.$eol$gdb_prompt $" {
65 # If the runtime was not built with enough debug information,
66 # or if it was stripped, we can not test exception
73 gdb_test "info break" \
74 "$info_break_header$eol.*$catch_exception_info" \
75 "info break, catch all Ada exceptions"
78 "Catchpoint $any_nb, CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
80 "Continuing\.$eol$catchpoint_msg$eol.*SPOT1" \
81 "continuing to first exception"
84 "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
86 "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
87 "continuing to second exception"
89 ################################################
90 # 2. Try catching only some of the exceptions. #
91 ################################################
93 # Here is the scenario:
94 # - Restart the debugger from scratch, runto_main
95 # - We'll catch only "Program_Error"
96 # We'll catch assertions
97 # We'll catch unhandled exceptions
98 # - continue, we should see the first Program_Error exception
99 # - continue, we should see the failed assertion
100 # - continue, we should see the unhandled Constrait_Error exception
101 # - continue, the program exits.
103 if ![runto_main] then {
104 fail "Cannot run to main, testcase aborted"
108 gdb_test "catch exception Program_Error" \
109 "Catchpoint $any_nb: \`Program_Error' Ada exception" \
110 "insert catchpoint on Program_Error"
112 gdb_test "catch assert" \
113 "Catchpoint $any_nb: failed Ada assertions" \
114 "insert catchpoint on failed assertions"
116 gdb_test "catch exception unhandled" \
117 "Catchpoint $any_nb: unhandled Ada exceptions" \
118 "insert catchpoint on unhandled exceptions"
120 set catch_exception_entry \
121 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}\`Program_Error' Ada exception"
122 set catch_assert_entry \
123 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}failed Ada assertions"
124 set catch_unhandled_entry \
125 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}unhandled Ada exceptions"
127 gdb_test "info break" \
128 "$info_break_header$eol.*$catch_exception_entry$eol$catch_assert_entry$eol$catch_unhandled_entry" \
129 "info break, second run"
132 "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
133 gdb_test "continue" \
134 "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
135 "continuing to Program_Error exception"
138 "Catchpoint $any_nb, failed assertion at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
139 gdb_test "continue" \
140 "Continuing\.$eol$catchpoint_msg$eol.*SPOT3" \
141 "continuing to Program_Error exception"
144 "Catchpoint $any_nb, unhandled CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
145 gdb_test "continue" \
146 "Continuing\.$eol$catchpoint_msg$eol.*SPOT4" \
147 "continuing to Program_Error exception"
149 gdb_test "continue" \
150 "Continuing\..*Program exited.*" \
151 "continuing to program completion"