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