1# Copyright 2018-2020 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 16load_lib "ada.exp" 17 18if { [skip_ada_tests] } { return -1 } 19 20standard_ada_testfile foo 21 22if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } { 23 return -1 24} 25 26clean_restart ${testfile} 27 28# Some global variables used to simplify the maintenance of some of 29# the regular expressions below. 30set eol "\[\r\n\]+" 31set sp "\[ \t\]*" 32 33set when "when" 34set catchpoint_constraint_error_msg \ 35 "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Constraint_Error =>" 36 37set catchpoint_program_error_msg \ 38 "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Program_Error =>" 39 40set catchpoint_storage_error_msg \ 41 "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Storage_Error =>" 42 43############################################ 44# Check that runtime supports catchpoint. # 45############################################ 46 47if ![runto_main] then { 48 fail "cannot run to main, testcase aborted" 49 return 0 50} 51 52set msg "insert catchpoint on all Ada exceptions handlers" 53gdb_test_multiple "catch handlers" $msg { 54 -re "Catchpoint $decimal: all Ada exceptions handlers$eol$gdb_prompt $" { 55 pass $msg 56 } 57 -re "Your Ada runtime appears to be missing some debugging information.*$eol$gdb_prompt $" { 58 # If the runtime was not built with enough debug information, 59 # or if it was stripped, we can not test exception handlers 60 # catchpoints. 61 unsupported $msg 62 return -1 63 } 64} 65 66############################################ 67# 1. Try catching all exceptions handlers. # 68############################################ 69 70# Continue. The program should stop at first exception handling. 71 72gdb_test "continue" \ 73 "Continuing\.$eol$catchpoint_constraint_error_msg$eol.*" \ 74 "continuing to first Constraint_Error exception handlers" 75 76# Resume the program's exception. 77# 78# The program will first go through a block of code which has an 79# exception handler, but since no exception is raised, we should 80# not stop there. Instead, we expect to stop in the handler of 81# the next exception being raised. 82 83gdb_test "continue" \ 84 "Continuing\.$eol$catchpoint_storage_error_msg$eol.*" \ 85 "continuing and stopping in Storage_Error exception handlers" 86 87gdb_test_no_output "delete 2" \ 88 "delete catchpoint on all Ada exceptions handlers" 89 90################################################## 91# 2. Try catching some named exception handlers. # 92################################################## 93 94# Insert a catchpoint on Program_Error Ada exception handlers. 95 96gdb_test "catch handlers Program_Error" \ 97 "Catchpoint $decimal: `Program_Error' Ada exception handlers" \ 98 "insert catchpoint on Program_Error Ada exception handlers" 99 100# Continue, we should not stop at ABORT_SIGNAL but at Program_Error one. 101 102gdb_test "continue" \ 103 "Continuing\.$eol$catchpoint_program_error_msg$eol.*" \ 104 "continuing without stopping to Program_Error exception handlers" 105 106gdb_test_no_output \ 107 "delete 3" \ 108 "delete catchpoint on all Program_Error Ada exception handlers" 109 110# Insert a catchpoint on Storage_Error Ada exception handlers. 111 112gdb_test "catch handlers Storage_Error" \ 113 "Catchpoint $decimal: `Storage_Error' Ada exception handlers" \ 114 "insert catchpoint on Storage_Error Ada exception handlers" 115 116# Continue, we should stop at Storage_Error handlers. 117 118gdb_test "continue" \ 119 "Continuing\.$eol$catchpoint_storage_error_msg$eol.*" \ 120 "continuing without stopping to Storage_Error exception handlers" 121 122gdb_test_no_output \ 123 "delete 4" \ 124 "delete catchpoint on all Storage_Error Ada exception handlers" 125 126######################################################################## 127# 3. Try catching with condition and without named exception handlers. # 128######################################################################## 129 130# Insert a catchpoint on all Ada exceptions handlers with condition. 131 132gdb_test "catch handlers if Global_Var = 2" \ 133 "Catchpoint $decimal: all Ada exceptions handlers" \ 134 "insert catchpoint on all Ada exception handlers with condition" 135 136# Check that condition is stored and properly displayed. 137 138gdb_test "info breakpoint" "stop only if Global_Var = 2" \ 139 "Check catch handlers with condition" 140 141# Continue, we should not stop at ABORT_SIGNAL but at Program_Error one. 142 143gdb_test "continue" \ 144 "Continuing\.$eol$catchpoint_constraint_error_msg$eol.*" \ 145 "continuing to second Constraint_Error exception handlers" 146 147gdb_test_no_output \ 148 "delete 5" \ 149 "delete catchpoint on all all Ada exceptions handlers with condition" 150 151################################################################ 152# 4. Try catching with condition and named exception handlers. # 153################################################################ 154 155# Insert a catchpoint on Program_Error Ada exception handlers with 156# condition. 157 158gdb_test "catch handlers Program_Error if Global_Var = 4" \ 159 "Catchpoint $decimal: `Program_Error' Ada exception handlers" \ 160 "insert catchpoint on Program_Error Ada exception handlers with condition" 161 162# Continue, we should not stop at first Program_Error handlers but at 163# the second one. 164 165gdb_test "continue" \ 166 "Continuing\.$eol$catchpoint_program_error_msg$eol.*" \ 167 "continuing to Program_Error exception handlers" 168 169# Continue, the program should exit properly. 170 171gdb_test "continue" \ 172 "Continuing\..*$inferior_exited_re.*" \ 173 "continuing to program completion" 174