Remove path name from test case
[binutils-gdb.git] / gdb / testsuite / gdb.cp / exception.exp
1 # Copyright 1997-2023 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 # This file is part of the gdb testsuite.
17 # tests for exception-handling support
18 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
19 # Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-08
20
21 # This file used to have two copies of the tests with different
22 # compiler flags for hp-ux. Instead, the user should set CXXOPTS
23 # or run runtest with --target_board unix/gdb:debug_flags="..."
24 # to choose the compiler flags.
25 #
26 # The interesting compiler flags are: "aCC +A -Wl,-a,-archive" .
27 # Static-linked executables use a different mechanism to get the
28 # address of the notification hook in the C++ support library.
29
30 set ws "\[\r\n\t \]+"
31 set nl "\[\r\n\]+"
32
33 require allow_stl_tests
34
35 standard_testfile .cc
36
37 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
38 return -1
39 }
40
41 # Set a catch catchpoint
42
43 gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" \
44 "catch catch (before inferior run)"
45
46 # Set a throw catchpoint
47
48 gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \
49 "catch throw (before inferior run)"
50
51 # Set a rethrow catchpoint
52
53 gdb_test "catch rethrow" "Catchpoint \[0-9\]+ \\(rethrow\\)" \
54 "catch rethrow (before inferior run)"
55
56
57 set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
58 set re_2_bp "1${ws}catchpoint${ws}keep${ws}y${ws}exception catch"
59 set re_3_bp "2${ws}catchpoint${ws}keep${ws}y${ws}exception throw"
60 set re_4_bp "3${ws}catchpoint${ws}keep${ws}y${ws}exception rethrow"
61
62 set name "info breakpoints (before inferior run)"
63 gdb_test_multiple "info breakpoints" $name {
64 -re "$re_head${ws}$re_2_bp${ws}$re_3_bp${ws}$re_4_bp\r\n$gdb_prompt $" {
65 pass $name
66 }
67 -re ".*$gdb_prompt $"
68 {
69 fail $name
70 }
71 }
72
73 gdb_test "tbreak -q main" "Temporary breakpoint 4.*" \
74 "Set temporary breakpoint at main"
75
76 set ok 0
77 gdb_run_cmd
78 gdb_test_multiple "" "run to main" {
79 -re "Temporary breakpoint 4,.*$gdb_prompt $" {
80 pass "run to main"
81 set ok 1
82 }
83 }
84
85 if { !$ok } {
86 return
87 }
88
89 set name "info breakpoints (after inferior run)"
90 gdb_test_multiple "info breakpoints" $name {
91 -re "$re_head${ws}$re_2_bp${ws}$re_3_bp${ws}$re_4_bp\r\n$gdb_prompt $" {
92 pass $name
93 }
94 -re ".*$gdb_prompt $"
95 {
96 send_user "\n---\n$expect_out(buffer)\n---\n"
97 fail $name
98 }
99 }
100
101 gdb_test "break catcher" "Breakpoint \[0-9\]+ at.*"
102
103 # Get the first exception thrown
104
105 gdb_test "continue" \
106 "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*" \
107 "continue to first throw"
108
109 # Backtrace from the throw point.
110 # This should get to user code.
111
112 set name "backtrace after first throw"
113 gdb_test_multiple "backtrace" $name {
114 -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_throw\[\[:>:\]\].*#\[0-9\]+${ws}$hex in foo \\(i=20\\) at .*${srcfile}:\[0-9\]+\r\n#\[0-9\]+${ws}$hex in main \\(.*\\) at .*${srcfile}:\[0-9\]+\r\n$gdb_prompt $" {
115 # Either __cxxabiv1::__cxa_throw or __cxa_throw can be printed
116 # depending on debug info presence.
117 pass $name
118 }
119 }
120
121 # Continue to the catch.
122
123 gdb_test "continue" \
124 "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*" \
125 "continue to first catch"
126
127 # Backtrace from the catch point.
128 # This should get to user code.
129
130 set name "backtrace after first catch"
131 gdb_test_multiple "backtrace" $name {
132 -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
133 pass $name
134 }
135 }
136
137 # Continue to breakpoint on catcher.
138 gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the first time"
139
140 # Continue to second throw.
141
142 gdb_test "continue" \
143 "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*" \
144 "continue to second throw"
145
146 # Backtrace from the throw point.
147 # This should get to user code.
148
149 set name "backtrace after second throw"
150 gdb_test_multiple "backtrace" $name {
151 -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_throw\[\[:>:\]\].*#\[0-9\]+${ws}$hex in foo \\(i=20\\) at .*${srcfile}:\[0-9\]+\r\n#\[0-9\]+${ws}$hex in main \\(.*\\) at .*${srcfile}:\[0-9\]+\r\n$gdb_prompt $" {
152 pass $name
153 }
154 }
155
156 # Continue to second catch.
157
158 gdb_test "continue" \
159 "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*" \
160 "continue to second catch"
161
162 # Backtrace from the catch point.
163 # This should get to user code.
164
165 set name "backtrace after second catch"
166 gdb_test_multiple "backtrace" $name {
167 -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
168 pass $name
169 }
170 }
171
172 # Continue to breakpoint on catcher.
173 gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the second time"
174
175
176 # Continue to the re-throw.
177
178 gdb_test "continue" "Catchpoint \[0-9\]+.*exception rethrown.*" \
179 "continue to rethrow"