Updated copyright notices for most files.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.ada / catch_ex.exp
CommitLineData
0fb0cc75 1# Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
fd678c65
JB
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
fd678c65
JB
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
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
fd678c65
JB
15
16if $tracelevel then {
17 strace $tracelevel
18}
19
20load_lib "ada.exp"
21
22set testdir "catch_ex"
23set testfile "${testdir}/foo"
24set srcfile ${srcdir}/${subdir}/${testfile}.adb
25set binfile ${objdir}/${subdir}/${testfile}
26
27file mkdir ${objdir}/${subdir}/${testdir}
28if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
29 return -1
30}
31
32gdb_exit
33gdb_start
34gdb_reinitialize_dir $srcdir/$subdir
35gdb_load ${binfile}
36
37# Some global variables used to simplify the maintenance of some of
38# the regular expressions below.
39set any_nb "\[0-9\]+"
40set any_addr "0x\[0-9a-zA-Z\]+"
41set eol "\[\r\n\]+"
42set sp "\[ \t\]*"
43
44set info_break_header "Num${sp}Type${sp}Disp${sp}Enb${sp}Address${sp}What"
45set catch_exception_info \
46 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}all Ada exceptions"
47
48####################################
49# 1. Try catching all exceptions. #
50####################################
51
52if ![runto_main] then {
53 fail "Cannot run to main, testcase aborted"
54 return 0
55}
56
4741b737
DJ
57set msg "insert catchpoint on all Ada exceptions"
58gdb_test_multiple "catch exception" $msg {
59 -re "Catchpoint $any_nb: all Ada exceptions$eol$gdb_prompt $" {
60 pass $msg
61 }
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
65 # catchpoints.
66 unsupported $msg
67 return -1
68 }
69}
fd678c65
JB
70
71gdb_test "info break" \
72 "$info_break_header$eol.*$catch_exception_info" \
73 "info break, catch all Ada exceptions"
74
75set catchpoint_msg \
76 "Catchpoint $any_nb, CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
77gdb_test "continue" \
78 "Continuing\.$eol$catchpoint_msg$eol.*SPOT1" \
79 "continuing to first exception"
80
81set catchpoint_msg \
82 "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
83gdb_test "continue" \
84 "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
85 "continuing to second exception"
86
87################################################
88# 2. Try catching only some of the exceptions. #
89################################################
90
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.
100
101if ![runto_main] then {
102 fail "Cannot run to main, testcase aborted"
103 return 0
104}
105
106gdb_test "catch exception Program_Error" \
107 "Catchpoint $any_nb: \`Program_Error' Ada exception" \
108 "insert catchpoint on Program_Error"
109
110gdb_test "catch assert" \
111 "Catchpoint $any_nb: failed Ada assertions" \
112 "insert catchpoint on failed assertions"
113
114gdb_test "catch exception unhandled" \
115 "Catchpoint $any_nb: unhandled Ada exceptions" \
116 "insert catchpoint on unhandled exceptions"
117
118set catch_exception_entry \
119 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}\`Program_Error' Ada exception"
120set catch_assert_entry \
121 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}failed Ada assertions"
122set catch_unhandled_entry \
123 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}unhandled Ada exceptions"
124
125gdb_test "info break" \
126 "$info_break_header$eol.*$catch_exception_entry$eol$catch_assert_entry$eol$catch_unhandled_entry" \
127 "info break, second run"
128
129set catchpoint_msg \
130 "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
131gdb_test "continue" \
132 "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
133 "continuing to Program_Error exception"
134
135set catchpoint_msg \
136 "Catchpoint $any_nb, failed assertion at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
137gdb_test "continue" \
138 "Continuing\.$eol$catchpoint_msg$eol.*SPOT3" \
9836f81b 139 "continuing to failed assertion"
fd678c65
JB
140
141set catchpoint_msg \
142 "Catchpoint $any_nb, unhandled CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
143gdb_test "continue" \
144 "Continuing\.$eol$catchpoint_msg$eol.*SPOT4" \
9836f81b 145 "continuing to unhandled exception"
fd678c65
JB
146
147gdb_test "continue" \
148 "Continuing\..*Program exited.*" \
149 "continuing to program completion"
150
151
This page took 0.215035 seconds and 4 git commands to generate.