Imported Upstream version 7.5
[platform/upstream/gdb.git] / gdb / testsuite / gdb.ada / catch_ex.exp
1 # Copyright 2007-2012 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 set testdir "catch_ex"
19 set testfile "${testdir}/foo"
20 set srcfile ${srcdir}/${subdir}/${testfile}.adb
21 set binfile ${objdir}/${subdir}/${testfile}
22
23 file mkdir ${objdir}/${subdir}/${testdir}
24 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
25   return -1
26 }
27
28 clean_restart ${testfile}
29
30 # Some global variables used to simplify the maintenance of some of
31 # the regular expressions below.
32 set any_nb "\[0-9\]+"
33 set any_addr "0x\[0-9a-zA-Z\]+"
34 set eol "\[\r\n\]+"
35 set sp "\[ \t\]*"
36
37 set info_break_header "Num${sp}Type${sp}Disp${sp}Enb${sp}Address${sp}What"
38 set catch_exception_info \
39   "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}all Ada exceptions"
40
41 ####################################
42 # 1. Try catching all exceptions.  #
43 ####################################
44
45 if ![runto_main] then {
46    fail "Cannot run to main, testcase aborted"
47    return 0
48 }
49
50 set msg "insert catchpoint on all Ada exceptions"
51 gdb_test_multiple "catch exception" $msg {
52     -re "Catchpoint $any_nb: all Ada exceptions$eol$gdb_prompt $" {
53         pass $msg
54     }
55     -re "Your Ada runtime appears to be missing some debugging information.*$eol$gdb_prompt $" {
56         # If the runtime was not built with enough debug information,
57         # or if it was stripped, we can not test exception
58         # catchpoints.
59         unsupported $msg
60         return -1
61     }
62 }
63
64 gdb_test "info break" \
65          "$info_break_header$eol.*$catch_exception_info" \
66          "info break, catch all Ada exceptions"
67
68 set catchpoint_msg \
69   "Catchpoint $any_nb, CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
70 gdb_test "continue" \
71          "Continuing\.$eol$catchpoint_msg$eol.*SPOT1" \
72          "continuing to first exception"
73
74 set catchpoint_msg \
75   "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
76 gdb_test "continue" \
77          "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
78          "continuing to second exception"
79
80 ################################################
81 # 2. Try catching only some of the exceptions. #
82 ################################################
83
84 # Here is the scenario:
85 #  - Restart the debugger from scratch, runto_main
86 #  - We'll catch only "Program_Error"
87 #    We'll catch assertions
88 #    We'll catch unhandled exceptions
89 #  - continue, we should see the first Program_Error exception
90 #  - continue, we should see the failed assertion
91 #  - continue, we should see the unhandled Constrait_Error exception
92 #  - continue, the program exits.
93
94 if ![runto_main] then {
95    fail "Cannot run to main, testcase aborted"
96    return 0
97 }
98
99 gdb_test "catch exception Program_Error" \
100          "Catchpoint $any_nb: \`Program_Error' Ada exception" \
101          "insert catchpoint on Program_Error"
102
103 gdb_test "catch assert" \
104          "Catchpoint $any_nb: failed Ada assertions" \
105          "insert catchpoint on failed assertions"
106
107 gdb_test "catch exception unhandled" \
108          "Catchpoint $any_nb: unhandled Ada exceptions" \
109          "insert catchpoint on unhandled exceptions"
110
111 set catch_exception_entry \
112   "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}\`Program_Error' Ada exception"
113 set catch_assert_entry \
114   "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}failed Ada assertions"
115 set catch_unhandled_entry \
116   "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}unhandled Ada exceptions"
117
118 gdb_test "info break" \
119          "$info_break_header$eol.*$catch_exception_entry$eol$catch_assert_entry$eol$catch_unhandled_entry" \
120          "info break, second run"
121
122 set catchpoint_msg \
123   "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
124 gdb_test "continue" \
125          "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
126          "continuing to Program_Error exception"
127
128 set catchpoint_msg \
129   "Catchpoint $any_nb, failed assertion at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
130 gdb_test "continue" \
131          "Continuing\.$eol$catchpoint_msg$eol.*SPOT3" \
132          "continuing to failed assertion"
133
134 set catchpoint_msg \
135   "Catchpoint $any_nb, unhandled CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
136 gdb_test "continue" \
137          "Continuing\.$eol$catchpoint_msg$eol.*SPOT4" \
138          "continuing to unhandled exception"
139
140 gdb_test "continue" \
141          "Continuing\..*$inferior_exited_re.*" \
142          "continuing to program completion"
143
144 #################################
145 # 3. Try temporary catchpoints. #
146 #################################
147
148 # Scenario:
149 #   - Insert a temporary catchpoint on all exceptions.
150 #   - Run to that catchpoint
151 #   - Continue; we should reach the program's exit, not stopping
152 #     at any of the other exceptions that are being raised inside
153 #     the program.
154
155 if ![runto_main] then {
156    fail "Cannot run to main, testcase aborted"
157    return 0
158 }
159
160 gdb_test "tcatch exception" \
161          "Temporary catchpoint $any_nb: all Ada exceptions"
162
163 set temp_catchpoint_msg \
164   "Temporary catchpoint $any_nb, CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
165 gdb_test "continue" \
166          "Continuing\.$eol$temp_catchpoint_msg$eol.*SPOT1" \
167          "continuing to temporary catchpoint"
168
169 gdb_test "continue" \
170          "Continuing\..*$inferior_exited_re.*" \
171          "continuing to program completion"
172
173
174