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