Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / exception.exp
CommitLineData
88b9d363 1# Copyright 1997-2022 Free Software Foundation, Inc.
7be570e7
JM
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
7be570e7 6# (at your option) any later version.
e22f8b7c 7#
7be570e7
JM
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.
e22f8b7c 12#
7be570e7 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
7be570e7 15
041ab88c 16# This file is part of the gdb testsuite.
7be570e7
JM
17# tests for exception-handling support
18# Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
041ab88c 19# Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-08
7be570e7 20
041ab88c
MC
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#
6fa9022e 26# The interesting compiler flags are: "aCC +A -Wl,-a,-archive" .
041ab88c
MC
27# Static-linked executables use a different mechanism to get the
28# address of the notification hook in the C++ support library.
7be570e7 29
041ab88c
MC
30# TODO: this file has many absolute line numbers.
31# Replace them with gdb_get_line_number.
7be570e7 32
041ab88c
MC
33set ws "\[\r\n\t \]+"
34set nl "\[\r\n\]+"
7be570e7 35
759f0f0b 36if { [skip_stl_tests] } { continue }
5f579bc5 37
f5f3a911 38standard_testfile .cc
7be570e7 39
5b362f04 40if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
f5f3a911 41 return -1
7be570e7 42}
7be570e7 43
7be570e7
JM
44# Set a catch catchpoint
45
8a34ac3f
AR
46gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" \
47 "catch catch (before inferior run)"
7be570e7
JM
48
49# Set a throw catchpoint
50
041ab88c 51gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \
8a34ac3f 52 "catch throw (before inferior run)"
7be570e7 53
591f19e8
TT
54# Set a rethrow catchpoint
55
56gdb_test "catch rethrow" "Catchpoint \[0-9\]+ \\(rethrow\\)" \
57 "catch rethrow (before inferior run)"
58
7be570e7 59
041ab88c 60set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
cb1e4e32
PA
61set re_2_bp "1${ws}catchpoint${ws}keep${ws}y${ws}exception catch"
62set re_3_bp "2${ws}catchpoint${ws}keep${ws}y${ws}exception throw"
63set re_4_bp "3${ws}catchpoint${ws}keep${ws}y${ws}exception rethrow"
041ab88c 64
8a34ac3f 65set name "info breakpoints (before inferior run)"
041ab88c 66gdb_test_multiple "info breakpoints" $name {
591f19e8 67 -re "$re_head${ws}$re_2_bp${ws}$re_3_bp${ws}$re_4_bp\r\n$gdb_prompt $" {
041ab88c
MC
68 pass $name
69 }
8a34ac3f
AR
70 -re ".*$gdb_prompt $"
71 {
72 fail $name
73 }
041ab88c
MC
74}
75
e777225b 76gdb_test "tbreak -q main" "Temporary breakpoint 4.*" \
8a34ac3f 77 "Set temporary breakpoint at main"
041ab88c 78
8a34ac3f
AR
79set ok 0
80gdb_run_cmd
de97fdd4 81gdb_test_multiple "" "run to main" {
591f19e8 82 -re "Temporary breakpoint 4,.*$gdb_prompt $" {
bc6c7af4 83 pass "run to main"
8a34ac3f 84 set ok 1
041ab88c 85 }
8a34ac3f
AR
86}
87
88if { !$ok } {
89 continue
90}
91
8a34ac3f
AR
92set name "info breakpoints (after inferior run)"
93gdb_test_multiple "info breakpoints" $name {
591f19e8 94 -re "$re_head${ws}$re_2_bp${ws}$re_3_bp${ws}$re_4_bp\r\n$gdb_prompt $" {
8a34ac3f 95 pass $name
041ab88c 96 }
8a34ac3f
AR
97 -re ".*$gdb_prompt $"
98 {
99 send_user "\n---\n$expect_out(buffer)\n---\n"
100 fail $name
101 }
7be570e7
JM
102}
103
af69a5ce
YQ
104gdb_test "break catcher" "Breakpoint \[0-9\]+ at.*"
105
7be570e7
JM
106# Get the first exception thrown
107
041ab88c
MC
108set name "continue to first throw"
109gdb_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 }
8a34ac3f
AR
113 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" {
114 pass $name
041ab88c 115 }
7be570e7
JM
116}
117
041ab88c
MC
118# Backtrace from the throw point.
119# This should get to user code.
7be570e7 120
041ab88c
MC
121set name "backtrace after first throw"
122gdb_test_multiple "backtrace" $name {
cec808ec
KS
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.
041ab88c
MC
126 pass $name
127 }
7be570e7
JM
128}
129
041ab88c 130# Continue to the catch.
7be570e7 131
041ab88c
MC
132set name "continue to first catch"
133gdb_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 }
8a34ac3f
AR
137 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" {
138 pass $name
041ab88c 139 }
7be570e7
JM
140}
141
041ab88c
MC
142# Backtrace from the catch point.
143# This should get to user code.
7be570e7 144
041ab88c
MC
145set name "backtrace after first catch"
146gdb_test_multiple "backtrace" $name {
cec808ec 147 -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
041ab88c
MC
148 pass $name
149 }
7be570e7
JM
150}
151
af69a5ce
YQ
152# Continue to breakpoint on catcher.
153gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the first time"
154
041ab88c 155# Continue to second throw.
7be570e7 156
041ab88c
MC
157set name "continue to second throw"
158gdb_test_multiple "continue" $name {
af69a5ce 159 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
041ab88c
MC
160 pass $name
161 }
af69a5ce 162 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" {
8a34ac3f 163 pass $name
041ab88c 164 }
7be570e7
JM
165}
166
041ab88c
MC
167# Backtrace from the throw point.
168# This should get to user code.
7be570e7 169
041ab88c
MC
170set name "backtrace after second throw"
171gdb_test_multiple "backtrace" $name {
cec808ec 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 $" {
041ab88c
MC
173 pass $name
174 }
7be570e7
JM
175}
176
041ab88c 177# Continue to second catch.
7be570e7 178
041ab88c
MC
179set name "continue to second catch"
180gdb_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 }
8a34ac3f
AR
184 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" {
185 pass $name
041ab88c 186 }
7be570e7
JM
187}
188
041ab88c
MC
189# Backtrace from the catch point.
190# This should get to user code.
7be570e7 191
041ab88c
MC
192set name "backtrace after second catch"
193gdb_test_multiple "backtrace" $name {
cec808ec 194 -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
041ab88c
MC
195 pass $name
196 }
7be570e7
JM
197}
198
af69a5ce
YQ
199# Continue to breakpoint on catcher.
200gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the second time"
201
591f19e8
TT
202
203# Continue to the re-throw.
204
205gdb_test "continue" "Catchpoint \[0-9\]+.*exception rethrown.*" \
206 "continue to rethrow"
This page took 2.470554 seconds and 4 git commands to generate.