]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.ada/mi_catch_ex.exp
x86: Add -z isa-level-report=[none|all|needed|used]
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.ada / mi_catch_ex.exp
1 # Copyright 2011-2024 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
16 load_lib "ada.exp"
17
18 require allow_ada_tests gnat_runtime_has_debug_info
19
20 standard_ada_testfile foo
21
22 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
23 return -1
24 }
25
26 # A global variable used to simplify the maintenance of some of
27 # the regular expressions below.
28 set any_nb "\[0-9\]+"
29
30 load_lib mi-support.exp
31 set MIFLAGS "-i=mi"
32
33 mi_clean_restart $binfile
34
35 ####################################
36 # 1. Try catching all exceptions. #
37 ####################################
38
39 with_test_prefix "scenario 1" {
40 if {[mi_runto_main] < 0} {
41 return 0
42 }
43 }
44
45 mi_gdb_test "-catch-exception" \
46 "\\^done,bkptno=\"$decimal\",bkpt={.*disp=\"keep\",enabled=\"y\",what=\"all Ada exceptions\",.*}" \
47 "catch all exceptions"
48
49 # Continue to caught exception.
50
51 proc continue_to_exception { exception_name exception_message test } {
52 global hex any_nb
53
54 mi_send_resuming_command "exec-continue" "$test"
55
56 # Match console stream output.
57 gdb_expect {
58 -re " $exception_name\( \\($exception_message\\)\)? at $hex in foo " {
59 }
60 timeout {
61 fail "$test (timeout)"
62 return -1
63 }
64 }
65
66 # Now MI stream output.
67 mi_expect_stop \
68 "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"$exception_name\(\",exception-message=\"$exception_message\)?\"" \
69 "foo" "" ".*" ".*" \
70 ".*" \
71 $test
72 }
73
74 continue_to_exception \
75 "CONSTRAINT_ERROR" "foo\\.adb:$decimal explicit raise" \
76 "continue until CE caught by all-exceptions catchpoint"
77
78 continue_to_exception \
79 "PROGRAM_ERROR" "foo\\.adb:$decimal explicit raise" \
80 "continue until PE caught by all-exceptions catchpoint"
81
82 ################################################
83 # 2. Try catching only some of the exceptions. #
84 ################################################
85
86 # Here is the scenario:
87 # - Restart the debugger from scratch, runto_main
88 # - We'll catch only "Program_Error"
89 # We'll catch assertions
90 # We'll catch unhandled exceptions
91 # - continue, we should see the first Program_Error exception
92 # - continue, we should see the failed assertion
93 # - continue, we should see the unhandled Constrait_Error exception
94 # - continue, the program exits.
95
96 with_test_prefix "scenario 2" {
97 mi_delete_breakpoints
98 if {[mi_runto_main] < 0} {
99 return 0
100 }
101 }
102
103 mi_gdb_test "-catch-exception -e Program_Error" \
104 "\\^done,bkptno=\"$decimal\",bkpt={.*disp=\"keep\",enabled=\"y\",what=\"`Program_Error' Ada exception\",.*}" \
105 "catch Program_Error"
106
107 mi_gdb_test "-catch-assert" \
108 "\\^done,bkptno=\"$decimal\",bkpt={.*disp=\"keep\",enabled=\"y\",what=\"failed Ada assertions\",.*}" \
109 "catch assert failures"
110
111 mi_gdb_test "-catch-exception -u" \
112 "\\^done,bkptno=\"$decimal\",bkpt={.*disp=\"keep\",enabled=\"y\",what=\"unhandled Ada exceptions\",.*}" \
113 "catch unhandled exceptions"
114
115 mi_execute_to "exec-continue" \
116 "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"PROGRAM_ERROR(\",exception-message=\"foo\\.adb:$decimal explicit raise)?\"" \
117 "foo" "" ".*" ".*" \
118 ".*" \
119 "continue to exception catchpoint hit"
120
121 mi_execute_to "exec-continue" \
122 "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\"" \
123 "foo" "" ".*" ".*" \
124 ".*" \
125 "continue to assert failure catchpoint hit"
126
127 mi_execute_to "exec-continue" \
128 "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"CONSTRAINT_ERROR\"" \
129 "foo" "" ".*" ".*" \
130 ".*" \
131 "continue to unhandled exception catchpoint hit"
132