| 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 | gdb_test "catch exception" \ |
| 60 | "Catchpoint $any_nb: all Ada exceptions" \ |
| 61 | "insert catchpoint on all Ada exceptions" |
| 62 | |
| 63 | gdb_test "info break" \ |
| 64 | "$info_break_header$eol.*$catch_exception_info" \ |
| 65 | "info break, catch all Ada exceptions" |
| 66 | |
| 67 | set catchpoint_msg \ |
| 68 | "Catchpoint $any_nb, CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb" |
| 69 | gdb_test "continue" \ |
| 70 | "Continuing\.$eol$catchpoint_msg$eol.*SPOT1" \ |
| 71 | "continuing to first exception" |
| 72 | |
| 73 | set catchpoint_msg \ |
| 74 | "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb" |
| 75 | gdb_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 | |
| 93 | if ![runto_main] then { |
| 94 | fail "Cannot run to main, testcase aborted" |
| 95 | return 0 |
| 96 | } |
| 97 | |
| 98 | gdb_test "catch exception Program_Error" \ |
| 99 | "Catchpoint $any_nb: \`Program_Error' Ada exception" \ |
| 100 | "insert catchpoint on Program_Error" |
| 101 | |
| 102 | gdb_test "catch assert" \ |
| 103 | "Catchpoint $any_nb: failed Ada assertions" \ |
| 104 | "insert catchpoint on failed assertions" |
| 105 | |
| 106 | gdb_test "catch exception unhandled" \ |
| 107 | "Catchpoint $any_nb: unhandled Ada exceptions" \ |
| 108 | "insert catchpoint on unhandled exceptions" |
| 109 | |
| 110 | set catch_exception_entry \ |
| 111 | "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}\`Program_Error' Ada exception" |
| 112 | set catch_assert_entry \ |
| 113 | "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}failed Ada assertions" |
| 114 | set catch_unhandled_entry \ |
| 115 | "$any_nb${sp}breakpoint${sp}keep${sp}y${sp}$any_addr${sp}unhandled Ada exceptions" |
| 116 | |
| 117 | gdb_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 | |
| 121 | set catchpoint_msg \ |
| 122 | "Catchpoint $any_nb, PROGRAM_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb" |
| 123 | gdb_test "continue" \ |
| 124 | "Continuing\.$eol$catchpoint_msg$eol.*SPOT2" \ |
| 125 | "continuing to Program_Error exception" |
| 126 | |
| 127 | set catchpoint_msg \ |
| 128 | "Catchpoint $any_nb, failed assertion at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb" |
| 129 | gdb_test "continue" \ |
| 130 | "Continuing\.$eol$catchpoint_msg$eol.*SPOT3" \ |
| 131 | "continuing to Program_Error exception" |
| 132 | |
| 133 | set catchpoint_msg \ |
| 134 | "Catchpoint $any_nb, unhandled CONSTRAINT_ERROR at $any_addr in foo \\\(\\\).*at .*foo.adb:$any_nb" |
| 135 | gdb_test "continue" \ |
| 136 | "Continuing\.$eol$catchpoint_msg$eol.*SPOT4" \ |
| 137 | "continuing to Program_Error exception" |
| 138 | |
| 139 | gdb_test "continue" \ |
| 140 | "Continuing\..*Program exited.*" \ |
| 141 | "continuing to program completion" |
| 142 | |
| 143 | |