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