]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/exception.exp
This commit was manufactured by cvs2svn to create branch
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / exception.exp
CommitLineData
9b254dd1 1# Copyright 1997, 1998, 2004, 2005, 2007, 2008 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
041ab88c
MC
36if $tracelevel then {
37 strace $tracelevel
38}
7be570e7 39
5f579bc5
NS
40if { [skip_cplus_tests] } { continue }
41
c1d88655
UW
42# On SPU this test fails because the executable exceeds local storage size.
43if { [istarget "spu*-*-*"] } {
44 return 0
45}
46
7be570e7
JM
47set testfile "exception"
48set srcfile ${testfile}.cc
49set binfile ${objdir}/${subdir}/${testfile}
50
041ab88c 51if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
52 untested exception.exp
53 return -1
7be570e7 54}
7be570e7
JM
55
56# Start with a fresh gdb
57
58set prms_id 0
59set bug_id 0
60
61gdb_exit
62gdb_start
63gdb_reinitialize_dir $srcdir/$subdir
64gdb_load ${binfile}
65
7be570e7
JM
66# Set a catch catchpoint
67
8a34ac3f
AR
68gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" \
69 "catch catch (before inferior run)"
7be570e7
JM
70
71# Set a throw catchpoint
72
041ab88c 73gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \
8a34ac3f 74 "catch throw (before inferior run)"
7be570e7 75
7be570e7 76
8a34ac3f
AR
77# The catchpoints should be listed in the list of breakpoints.
78# In case of a statically linked test, we won't have a pending breakpoint.
79# Hence we allow for both an address or "<PENDING>". If we ever become able
80# to tell whether the target is linked statically or not, we can be more
81# precise and require exact output.
82set addr "\(<PENDING>|$hex\)"
041ab88c 83set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
8a34ac3f
AR
84set re_2_bp "1${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception catch"
85set re_3_bp "2${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception throw"
041ab88c 86
8a34ac3f 87set name "info breakpoints (before inferior run)"
041ab88c 88gdb_test_multiple "info breakpoints" $name {
8a34ac3f 89 -re "$re_head${ws}$re_2_bp${ws}$re_3_bp\r\n$gdb_prompt $" {
041ab88c
MC
90 pass $name
91 }
8a34ac3f
AR
92 -re ".*$gdb_prompt $"
93 {
94 fail $name
95 }
041ab88c
MC
96}
97
8a34ac3f
AR
98gdb_test "tbreak main" "Temporary breakpoint 3.*" \
99 "Set temporary breakpoint at main"
041ab88c 100
8a34ac3f
AR
101set ok 0
102gdb_run_cmd
103gdb_test_multiple "" "Run to main" {
104 -re "Temporary breakpoint 3,.*$gdb_prompt $" {
105 pass "Run to main"
106 set ok 1
041ab88c 107 }
8a34ac3f
AR
108}
109
110if { !$ok } {
111 continue
112}
113
114set addr "$hex"
115set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
116set re_2_bp "1${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception catch"
117set re_3_bp "2${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception throw"
118
119set name "info breakpoints (after inferior run)"
120gdb_test_multiple "info breakpoints" $name {
121 -re "$re_head${ws}$re_2_bp${ws}$re_3_bp\r\n$gdb_prompt $" {
122 pass $name
041ab88c 123 }
8a34ac3f
AR
124 -re ".*$gdb_prompt $"
125 {
126 send_user "\n---\n$expect_out(buffer)\n---\n"
127 fail $name
128 }
7be570e7
JM
129}
130
131# Get the first exception thrown
132
041ab88c
MC
133set name "continue to first throw"
134gdb_test_multiple "continue" $name {
135 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
136 pass $name
137 }
8a34ac3f
AR
138 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" {
139 pass $name
041ab88c 140 }
7be570e7
JM
141}
142
041ab88c
MC
143# Backtrace from the throw point.
144# This should get to user code.
7be570e7 145
041ab88c
MC
146set name "backtrace after first throw"
147gdb_test_multiple "backtrace" $name {
8a34ac3f 148 -re ".*#\[0-9\]+${ws}$hex in __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
149 pass $name
150 }
7be570e7
JM
151}
152
041ab88c 153# Continue to the catch.
7be570e7 154
041ab88c
MC
155set name "continue to first catch"
156gdb_test_multiple "continue" $name {
157 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
158 pass $name
159 }
8a34ac3f
AR
160 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" {
161 pass $name
041ab88c 162 }
7be570e7
JM
163}
164
041ab88c
MC
165# Backtrace from the catch point.
166# This should get to user code.
7be570e7 167
041ab88c
MC
168set name "backtrace after first catch"
169gdb_test_multiple "backtrace" $name {
8a34ac3f 170 -re ".*#\[0-9\]+${ws}$hex in __cxa_begin_catch.*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
041ab88c
MC
171 pass $name
172 }
7be570e7
JM
173}
174
041ab88c 175# Continue to second throw.
7be570e7 176
041ab88c
MC
177set name "continue to second throw"
178gdb_test_multiple "continue" $name {
179 -re "Continuing.${ws}Got an except 13${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
180 pass $name
181 }
8a34ac3f
AR
182 -re "Continuing.${ws}Got an except 13${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" {
183 pass $name
041ab88c 184 }
7be570e7
JM
185}
186
041ab88c
MC
187# Backtrace from the throw point.
188# This should get to user code.
7be570e7 189
041ab88c
MC
190set name "backtrace after second throw"
191gdb_test_multiple "backtrace" $name {
8a34ac3f 192 -re ".*#\[0-9\]+${ws}$hex in __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
193 pass $name
194 }
7be570e7
JM
195}
196
041ab88c 197# Continue to second catch.
7be570e7 198
041ab88c
MC
199set name "continue to second catch"
200gdb_test_multiple "continue" $name {
201 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
202 pass $name
203 }
8a34ac3f
AR
204 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" {
205 pass $name
041ab88c 206 }
7be570e7
JM
207}
208
041ab88c
MC
209# Backtrace from the catch point.
210# This should get to user code.
7be570e7 211
041ab88c
MC
212set name "backtrace after second catch"
213gdb_test_multiple "backtrace" $name {
8a34ac3f 214 -re ".*#\[0-9\]+${ws}$hex in __cxa_begin_catch.*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
041ab88c
MC
215 pass $name
216 }
7be570e7
JM
217}
218
041ab88c
MC
219# That is all for now.
220#
221# The original code had:
222#
223# continue to re-throw ; backtrace
224# continue to catch ; backtrace
225# continue to throw out of main
226#
227# The problem is that "re-throw" does not show a throw; only a catch.
228# I do not know if this is because of a bug, or because the generated
229# code is optimized for a throw into the same function.
230#
231# -- chastain 2004-01-09