OSDN Git Service

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