b69408b029137769404721390f38cda77bb32633
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / exception.exp
1 # Copyright 1997-2021 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 # TODO: this file has many absolute line numbers.
31 # Replace them with gdb_get_line_number.
32
33 set ws "\[\r\n\t \]+"
34 set nl "\[\r\n\]+"
35
36 if { [skip_stl_tests] } { continue }
37
38 standard_testfile .cc
39
40 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
41 return -1
42 }
43
44 # Set a catch catchpoint
45
46 gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" \
47 "catch catch (before inferior run)"
48
49 # Set a throw catchpoint
50
51 gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \
52 "catch throw (before inferior run)"
53
54 # Set a rethrow catchpoint
55
56 gdb_test "catch rethrow" "Catchpoint \[0-9\]+ \\(rethrow\\)" \
57 "catch rethrow (before inferior run)"
58
59
60 set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
61 set re_2_bp "1${ws}catchpoint${ws}keep${ws}y${ws}exception catch"
62 set re_3_bp "2${ws}catchpoint${ws}keep${ws}y${ws}exception throw"
63 set re_4_bp "3${ws}catchpoint${ws}keep${ws}y${ws}exception rethrow"
64
65 set name "info breakpoints (before inferior run)"
66 gdb_test_multiple "info breakpoints" $name {
67 -re "$re_head${ws}$re_2_bp${ws}$re_3_bp${ws}$re_4_bp\r\n$gdb_prompt $" {
68 pass $name
69 }
70 -re ".*$gdb_prompt $"
71 {
72 fail $name
73 }
74 }
75
76 gdb_test "tbreak -q main" "Temporary breakpoint 4.*" \
77 "Set temporary breakpoint at main"
78
79 set ok 0
80 gdb_run_cmd
81 gdb_test_multiple "" "run to main" {
82 -re "Temporary breakpoint 4,.*$gdb_prompt $" {
83 pass "run to main"
84 set ok 1
85 }
86 }
87
88 if { !$ok } {
89 continue
90 }
91
92 set name "info breakpoints (after inferior run)"
93 gdb_test_multiple "info breakpoints" $name {
94 -re "$re_head${ws}$re_2_bp${ws}$re_3_bp${ws}$re_4_bp\r\n$gdb_prompt $" {
95 pass $name
96 }
97 -re ".*$gdb_prompt $"
98 {
99 send_user "\n---\n$expect_out(buffer)\n---\n"
100 fail $name
101 }
102 }
103
104 gdb_test "break catcher" "Breakpoint \[0-9\]+ at.*"
105
106 # Get the first exception thrown
107
108 set name "continue to first throw"
109 gdb_test_multiple "continue" $name {
110 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
111 pass $name
112 }
113 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" {
114 pass $name
115 }
116 }
117
118 # Backtrace from the throw point.
119 # This should get to user code.
120
121 set name "backtrace after first throw"
122 gdb_test_multiple "backtrace" $name {
123 -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 $" {
124 # Either __cxxabiv1::__cxa_throw or __cxa_throw can be printed
125 # depending on debug info presence.
126 pass $name
127 }
128 }
129
130 # Continue to the catch.
131
132 set name "continue to first catch"
133 gdb_test_multiple "continue" $name {
134 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
135 pass $name
136 }
137 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" {
138 pass $name
139 }
140 }
141
142 # Backtrace from the catch point.
143 # This should get to user code.
144
145 set name "backtrace after first catch"
146 gdb_test_multiple "backtrace" $name {
147 -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
148 pass $name
149 }
150 }
151
152 # Continue to breakpoint on catcher.
153 gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the first time"
154
155 # Continue to second throw.
156
157 set name "continue to second throw"
158 gdb_test_multiple "continue" $name {
159 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
160 pass $name
161 }
162 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" {
163 pass $name
164 }
165 }
166
167 # Backtrace from the throw point.
168 # This should get to user code.
169
170 set name "backtrace after second throw"
171 gdb_test_multiple "backtrace" $name {
172 -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 $" {
173 pass $name
174 }
175 }
176
177 # Continue to second catch.
178
179 set name "continue to second catch"
180 gdb_test_multiple "continue" $name {
181 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
182 pass $name
183 }
184 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" {
185 pass $name
186 }
187 }
188
189 # Backtrace from the catch point.
190 # This should get to user code.
191
192 set name "backtrace after second catch"
193 gdb_test_multiple "backtrace" $name {
194 -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
195 pass $name
196 }
197 }
198
199 # Continue to breakpoint on catcher.
200 gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the second time"
201
202
203 # Continue to the re-throw.
204
205 gdb_test "continue" "Catchpoint \[0-9\]+.*exception rethrown.*" \
206 "continue to rethrow"
This page took 0.032578 seconds and 3 git commands to generate.