* gdb.base/annota1.exp: Remove extra send_gdb.
[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
59gdb_test "catch exception" \
60 "Catchpoint $any_nb: all Ada exceptions" \
61 "insert catchpoint on all Ada exceptions"
62
63gdb_test "info break" \
64 "$info_break_header$eol.*$catch_exception_info" \
65 "info break, catch all Ada exceptions"
66
67set catchpoint_msg \
68 "Catchpoint $any_nb, CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
69gdb_test "continue" \
70 "Continuing\.$eol$catchpoint_msg$eol.*SPOT1" \
71 "continuing to first exception"
72
73set catchpoint_msg \
74 "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
75gdb_test "continue" \
76 "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
77 "continuing to second exception"
78
79################################################
80# 2. Try catching only some of the exceptions. #
81################################################
82
83# Here is the scenario:
84# - Restart the debugger from scratch, runto_main
85# - We'll catch only "Program_Error"
86# We'll catch assertions
87# We'll catch unhandled exceptions
88# - continue, we should see the first Program_Error exception
89# - continue, we should see the failed assertion
90# - continue, we should see the unhandled Constrait_Error exception
91# - continue, the program exits.
92
93if ![runto_main] then {
94 fail "Cannot run to main, testcase aborted"
95 return 0
96}
97
98gdb_test "catch exception Program_Error" \
99 "Catchpoint $any_nb: \`Program_Error' Ada exception" \
100 "insert catchpoint on Program_Error"
101
102gdb_test "catch assert" \
103 "Catchpoint $any_nb: failed Ada assertions" \
104 "insert catchpoint on failed assertions"
105
106gdb_test "catch exception unhandled" \
107 "Catchpoint $any_nb: unhandled Ada exceptions" \
108 "insert catchpoint on unhandled exceptions"
109
110set catch_exception_entry \
111 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}\`Program_Error' Ada exception"
112set catch_assert_entry \
113 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}failed Ada assertions"
114set catch_unhandled_entry \
115 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}unhandled Ada exceptions"
116
117gdb_test "info break" \
118 "$info_break_header$eol.*$catch_exception_entry$eol$catch_assert_entry$eol$catch_unhandled_entry" \
119 "info break, second run"
120
121set catchpoint_msg \
122 "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
123gdb_test "continue" \
124 "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
125 "continuing to Program_Error exception"
126
127set catchpoint_msg \
128 "Catchpoint $any_nb, failed assertion at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
129gdb_test "continue" \
130 "Continuing\.$eol$catchpoint_msg$eol.*SPOT3" \
131 "continuing to Program_Error exception"
132
133set catchpoint_msg \
134 "Catchpoint $any_nb, unhandled CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
135gdb_test "continue" \
136 "Continuing\.$eol$catchpoint_msg$eol.*SPOT4" \
137 "continuing to Program_Error exception"
138
139gdb_test "continue" \
140 "Continuing\..*Program exited.*" \
141 "continuing to program completion"
142
143
This page took 0.039753 seconds and 4 git commands to generate.