xref: /openbsd-src/gnu/usr.bin/binutils/gdb/testsuite/gdb.cp/exception.exp (revision b725ae7711052a2233e31a66fefb8a752c388d7a)
1*b725ae77Skettenis# Copyright 1997, 1998, 2004 Free Software Foundation, Inc.
2*b725ae77Skettenis
3*b725ae77Skettenis# This program is free software; you can redistribute it and/or modify
4*b725ae77Skettenis# it under the terms of the GNU General Public License as published by
5*b725ae77Skettenis# the Free Software Foundation; either version 2 of the License, or
6*b725ae77Skettenis# (at your option) any later version.
7*b725ae77Skettenis#
8*b725ae77Skettenis# This program is distributed in the hope that it will be useful,
9*b725ae77Skettenis# but WITHOUT ANY WARRANTY; without even the implied warranty of
10*b725ae77Skettenis# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11*b725ae77Skettenis# GNU General Public License for more details.
12*b725ae77Skettenis#
13*b725ae77Skettenis# You should have received a copy of the GNU General Public License
14*b725ae77Skettenis# along with this program; if not, write to the Free Software
15*b725ae77Skettenis# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16*b725ae77Skettenis
17*b725ae77Skettenis# This file is part of the gdb testsuite.
18*b725ae77Skettenis# tests for exception-handling support
19*b725ae77Skettenis# Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
20*b725ae77Skettenis# Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-08
21*b725ae77Skettenis
22*b725ae77Skettenis# This file used to have two copies of the tests with different
23*b725ae77Skettenis# compiler flags for hp-ux.  Instead, the user should set CXXOPTS
24*b725ae77Skettenis# or run runtest with --target_board unix/gdb:debug_flags="..."
25*b725ae77Skettenis# to choose the compiler flags.
26*b725ae77Skettenis#
27*b725ae77Skettenis# The interesting compiler flags are: "aCC +A -Wl,-a,-archive" .
28*b725ae77Skettenis# Static-linked executables use a different mechanism to get the
29*b725ae77Skettenis# address of the notification hook in the C++ support library.
30*b725ae77Skettenis
31*b725ae77Skettenis# TODO: this file is not ready for production yet.  If you are working
32*b725ae77Skettenis# on C++ exception support for gdb, you can take out the "continue"
33*b725ae77Skettenis# statement and try your luck.  -- chastain 2004-01-09
34*b725ae77Skettenis
35*b725ae77Skettenis# TODO: this file has many absolute line numbers.
36*b725ae77Skettenis# Replace them with gdb_get_line_number.
37*b725ae77Skettenis
38*b725ae77Skettenisset ws	"\[\r\n\t \]+"
39*b725ae77Skettenisset nl	"\[\r\n\]+"
40*b725ae77Skettenis
41*b725ae77Skettenisif $tracelevel then {
42*b725ae77Skettenis    strace $tracelevel
43*b725ae77Skettenis}
44*b725ae77Skettenis
45*b725ae77Skettenisset testfile "exception"
46*b725ae77Skettenisset srcfile ${testfile}.cc
47*b725ae77Skettenisset binfile ${objdir}/${subdir}/${testfile}
48*b725ae77Skettenis
49*b725ae77Skettenisif { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
50*b725ae77Skettenis     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
51*b725ae77Skettenis}
52*b725ae77Skettenis
53*b725ae77Skettenis# Start with a fresh gdb
54*b725ae77Skettenis
55*b725ae77Skettenisset prms_id 0
56*b725ae77Skettenisset bug_id 0
57*b725ae77Skettenis
58*b725ae77Skettenisgdb_exit
59*b725ae77Skettenisgdb_start
60*b725ae77Skettenisgdb_reinitialize_dir $srcdir/$subdir
61*b725ae77Skettenisgdb_load ${binfile}
62*b725ae77Skettenis
63*b725ae77Skettenisif ![runto_main] then {
64*b725ae77Skettenis    perror "couldn't run to breakpoint"
65*b725ae77Skettenis    continue
66*b725ae77Skettenis}
67*b725ae77Skettenis
68*b725ae77Skettenis# As I said before, this test script is not ready yet!
69*b725ae77Skettenis
70*b725ae77Sketteniscontinue
71*b725ae77Skettenis
72*b725ae77Skettenis# Set a catch catchpoint
73*b725ae77Skettenis
74*b725ae77Skettenisgdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)"
75*b725ae77Skettenis
76*b725ae77Skettenis# Set a throw catchpoint
77*b725ae77Skettenis
78*b725ae77Skettenisgdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \
79*b725ae77Skettenis    "catch throw (static executable)"
80*b725ae77Skettenis
81*b725ae77Skettenis# The catchpoints should be listed in the list of breakpoints.
82*b725ae77Skettenis
83*b725ae77Skettenisset re_head	"Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
84*b725ae77Skettenisset re_1_main   "1${ws}breakpoint${ws}keep${ws}y${ws}$hex${ws}in main.*breakpoint already hit.*"
85*b725ae77Skettenisset re_2_catch	"2${ws}catch catch${ws}keep${ws}y${ws}$hex${ws}exception catch"
86*b725ae77Skettenisset re_3_catch	"3${ws}catch throw${ws}keep${ws}y${ws}$hex${ws}exception throw"
87*b725ae77Skettenisset re_2_bp	"2${ws}breakpoint${ws}keep${ws}y${ws}$hex${ws}exception catch"
88*b725ae77Skettenisset re_3_bp	"3${ws}breakpoint${ws}keep${ws}y${ws}$hex${ws}exception throw"
89*b725ae77Skettenis
90*b725ae77Skettenisset name "info breakpoints"
91*b725ae77Skettenisgdb_test_multiple "info breakpoints" $name {
92*b725ae77Skettenis    -re "$re_head${ws}$re_1_main${ws}$re_2_catch${ws}$re_3_catch\r\n$gdb_prompt $" {
93*b725ae77Skettenis	pass $name
94*b725ae77Skettenis    }
95*b725ae77Skettenis    -re "$re_head${ws}$re_1_main${ws}$re_2_bp${ws}$re_3_bp\r\n$gdb_prompt $" {
96*b725ae77Skettenis	# TODO: gdb HEAD 2004-01-08 does this.  Is this okay?
97*b725ae77Skettenis	unresolved $name
98*b725ae77Skettenis    }
99*b725ae77Skettenis}
100*b725ae77Skettenis
101*b725ae77Skettenis# Some targets support "info catch".
102*b725ae77Skettenis# Some do not.
103*b725ae77Skettenis
104*b725ae77Skettenisset name "info catch"
105*b725ae77Skettenisgdb_test_multiple "info catch" $name {
106*b725ae77Skettenis    -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" {
107*b725ae77Skettenis	unsupported $name
108*b725ae77Skettenis    }
109*b725ae77Skettenis    -re "No catches.\r\n$gdb_prompt $" {
110*b725ae77Skettenis	# TODO: gdb HEAD 2004-01-08 does this.  Is this okay?
111*b725ae77Skettenis	unresolved $name
112*b725ae77Skettenis    }
113*b725ae77Skettenis}
114*b725ae77Skettenis
115*b725ae77Skettenis# Get the first exception thrown
116*b725ae77Skettenis
117*b725ae77Skettenisset name "continue to first throw"
118*b725ae77Skettenisgdb_test_multiple "continue" $name {
119*b725ae77Skettenis    -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
120*b725ae77Skettenis	pass $name
121*b725ae77Skettenis    }
122*b725ae77Skettenis    -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\)\r\n.*\r\n$gdb_prompt $" {
123*b725ae77Skettenis	# TODO: gdb HEAD 2004-01-08 does this.  Is this okay?
124*b725ae77Skettenis	unresolved $name
125*b725ae77Skettenis    }
126*b725ae77Skettenis}
127*b725ae77Skettenis
128*b725ae77Skettenis# Backtrace from the throw point.
129*b725ae77Skettenis# This should get to user code.
130*b725ae77Skettenis
131*b725ae77Skettenisset name "backtrace after first throw"
132*b725ae77Skettenisgdb_test_multiple "backtrace" $name {
133*b725ae77Skettenis    -re ".*#\[0-9\]+${ws}$hex in foo \\(i=20\\) at .*${srcfile}:30\r\n#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*${srcfile}:48\r\n$gdb_prompt $" {
134*b725ae77Skettenis	pass $name
135*b725ae77Skettenis    }
136*b725ae77Skettenis}
137*b725ae77Skettenis
138*b725ae77Skettenis# Continue to the catch.
139*b725ae77Skettenis
140*b725ae77Skettenisset name "continue to first catch"
141*b725ae77Skettenisgdb_test_multiple "continue" $name {
142*b725ae77Skettenis    -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
143*b725ae77Skettenis	pass $name
144*b725ae77Skettenis    }
145*b725ae77Skettenis    -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\)\r\n.*\r\n$gdb_prompt $" {
146*b725ae77Skettenis	# TODO: gdb HEAD 2004-01-08 does this.  Is this okay?
147*b725ae77Skettenis	unresolved $name
148*b725ae77Skettenis    }
149*b725ae77Skettenis}
150*b725ae77Skettenis
151*b725ae77Skettenis# Backtrace from the catch point.
152*b725ae77Skettenis# This should get to user code.
153*b725ae77Skettenis
154*b725ae77Skettenisset name "backtrace after first catch"
155*b725ae77Skettenisgdb_test_multiple "backtrace" $name {
156*b725ae77Skettenis    -re ".*#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*$srcfile:50\r\n$gdb_prompt $" {
157*b725ae77Skettenis	pass $name
158*b725ae77Skettenis    }
159*b725ae77Skettenis}
160*b725ae77Skettenis
161*b725ae77Skettenis# Continue to second throw.
162*b725ae77Skettenis
163*b725ae77Skettenisset name "continue to second throw"
164*b725ae77Skettenisgdb_test_multiple "continue" $name {
165*b725ae77Skettenis    -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 $" {
166*b725ae77Skettenis	pass $name
167*b725ae77Skettenis    }
168*b725ae77Skettenis    -re "Continuing.${ws}Got an except 13${ws}Catchpoint \[0-9\]+ \\(exception thrown\\)\r\n.*\r\n$gdb_prompt $" {
169*b725ae77Skettenis	# TODO: gdb HEAD 2004-01-08 does this.  Is this okay?
170*b725ae77Skettenis	unresolved $name
171*b725ae77Skettenis    }
172*b725ae77Skettenis}
173*b725ae77Skettenis
174*b725ae77Skettenis# Backtrace from the throw point.
175*b725ae77Skettenis# This should get to user code.
176*b725ae77Skettenis
177*b725ae77Skettenisset name "backtrace after second throw"
178*b725ae77Skettenisgdb_test_multiple "backtrace" $name {
179*b725ae77Skettenis    -re ".*#\[0-9\]+${ws}$hex in foo \\(i=20\\) at .*${srcfile}:30\r\n#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*${srcfile}:56\r\n$gdb_prompt $" {
180*b725ae77Skettenis	pass $name
181*b725ae77Skettenis    }
182*b725ae77Skettenis}
183*b725ae77Skettenis
184*b725ae77Skettenis# Continue to second catch.
185*b725ae77Skettenis
186*b725ae77Skettenisset name "continue to second catch"
187*b725ae77Skettenisgdb_test_multiple "continue" $name {
188*b725ae77Skettenis    -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
189*b725ae77Skettenis	pass $name
190*b725ae77Skettenis    }
191*b725ae77Skettenis    -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\)\r\n.*\r\n$gdb_prompt $" {
192*b725ae77Skettenis	# TODO: gdb HEAD 2004-01-08 does this.  Is this okay?
193*b725ae77Skettenis	unresolved $name
194*b725ae77Skettenis    }
195*b725ae77Skettenis}
196*b725ae77Skettenis
197*b725ae77Skettenis# Backtrace from the catch point.
198*b725ae77Skettenis# This should get to user code.
199*b725ae77Skettenis
200*b725ae77Skettenisset name "backtrace after second catch"
201*b725ae77Skettenisgdb_test_multiple "backtrace" $name {
202*b725ae77Skettenis    -re ".*#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*$srcfile:58\r\n$gdb_prompt $" {
203*b725ae77Skettenis	pass $name
204*b725ae77Skettenis    }
205*b725ae77Skettenis}
206*b725ae77Skettenis
207*b725ae77Skettenis# That is all for now.
208*b725ae77Skettenis#
209*b725ae77Skettenis# The original code had:
210*b725ae77Skettenis#
211*b725ae77Skettenis#    continue to re-throw ; backtrace
212*b725ae77Skettenis#    continue to catch    ; backtrace
213*b725ae77Skettenis#    continue to throw out of main
214*b725ae77Skettenis#
215*b725ae77Skettenis# The problem is that "re-throw" does not show a throw; only a catch.
216*b725ae77Skettenis# I do not know if this is because of a bug, or because the generated
217*b725ae77Skettenis# code is optimized for a throw into the same function.
218*b725ae77Skettenis#
219*b725ae77Skettenis# -- chastain 2004-01-09
220