* gdb.ada/catch_ex.exp: Call unsupported and stop if the runtime
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.ada / catch_ex.exp
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
18 if $tracelevel then {
19 strace $tracelevel
20 }
21
22 load_lib "ada.exp"
23
24 set testdir "catch_ex"
25 set testfile "${testdir}/foo"
26 set srcfile ${srcdir}/${subdir}/${testfile}.adb
27 set binfile ${objdir}/${subdir}/${testfile}
28
29 file mkdir ${objdir}/${subdir}/${testdir}
30 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
31 return -1
32 }
33
34 gdb_exit
35 gdb_start
36 gdb_reinitialize_dir $srcdir/$subdir
37 gdb_load ${binfile}
38
39 # Some global variables used to simplify the maintenance of some of
40 # the regular expressions below.
41 set any_nb "\[0-9\]+"
42 set any_addr "0x\[0-9a-zA-Z\]+"
43 set eol "\[\r\n\]+"
44 set sp "\[ \t\]*"
45
46 set info_break_header "Num${sp}Type${sp}Disp${sp}Enb${sp}Address${sp}What"
47 set 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
54 if ![runto_main] then {
55 fail "Cannot run to main, testcase aborted"
56 return 0
57 }
58
59 set msg "insert catchpoint on all Ada exceptions"
60 gdb_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 }
72
73 gdb_test "info break" \
74 "$info_break_header$eol.*$catch_exception_info" \
75 "info break, catch all Ada exceptions"
76
77 set catchpoint_msg \
78 "Catchpoint $any_nb, CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
79 gdb_test "continue" \
80 "Continuing\.$eol$catchpoint_msg$eol.*SPOT1" \
81 "continuing to first exception"
82
83 set catchpoint_msg \
84 "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
85 gdb_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
103 if ![runto_main] then {
104 fail "Cannot run to main, testcase aborted"
105 return 0
106 }
107
108 gdb_test "catch exception Program_Error" \
109 "Catchpoint $any_nb: \`Program_Error' Ada exception" \
110 "insert catchpoint on Program_Error"
111
112 gdb_test "catch assert" \
113 "Catchpoint $any_nb: failed Ada assertions" \
114 "insert catchpoint on failed assertions"
115
116 gdb_test "catch exception unhandled" \
117 "Catchpoint $any_nb: unhandled Ada exceptions" \
118 "insert catchpoint on unhandled exceptions"
119
120 set catch_exception_entry \
121 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}\`Program_Error' Ada exception"
122 set catch_assert_entry \
123 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}failed Ada assertions"
124 set catch_unhandled_entry \
125 "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}unhandled Ada exceptions"
126
127 gdb_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
131 set catchpoint_msg \
132 "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
133 gdb_test "continue" \
134 "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \
135 "continuing to Program_Error exception"
136
137 set catchpoint_msg \
138 "Catchpoint $any_nb, failed assertion at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
139 gdb_test "continue" \
140 "Continuing\.$eol$catchpoint_msg$eol.*SPOT3" \
141 "continuing to Program_Error exception"
142
143 set catchpoint_msg \
144 "Catchpoint $any_nb, unhandled CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb"
145 gdb_test "continue" \
146 "Continuing\.$eol$catchpoint_msg$eol.*SPOT4" \
147 "continuing to Program_Error exception"
148
149 gdb_test "continue" \
150 "Continuing\..*Program exited.*" \
151 "continuing to program completion"
152
153
This page took 0.033123 seconds and 4 git commands to generate.