OSDN Git Service

2012-01-16 Pedro Alves <palves@redhat.com>
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.cp / exception.exp
1 # Copyright 1997-1998, 2004-2005, 2007-2012 Free Software Foundation,
2 # Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # This file is part of the gdb testsuite.
18 # tests for exception-handling support
19 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
20 # Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-08
21
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 #
27 # The interesting compiler flags are: "aCC +A -Wl,-a,-archive" .
28 # Static-linked executables use a different mechanism to get the
29 # address of the notification hook in the C++ support library.
30
31 # TODO: this file has many absolute line numbers.
32 # Replace them with gdb_get_line_number.
33
34 set ws  "\[\r\n\t \]+"
35 set nl  "\[\r\n\]+"
36
37 if { [skip_stl_tests] } { continue }
38
39 # On SPU this test fails because the executable exceeds local storage size.
40 if { [istarget "spu*-*-*"] } {
41         return 0
42 }
43
44 set testfile "exception"
45 set srcfile ${testfile}.cc
46 set binfile ${objdir}/${subdir}/${testfile}
47  
48 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
49      untested exception.exp
50      return -1
51 }
52
53 # Start with a fresh gdb
54
55
56 gdb_exit
57 gdb_start
58 gdb_reinitialize_dir $srcdir/$subdir
59 gdb_load ${binfile}
60
61 # Set a catch catchpoint
62
63 gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" \
64     "catch catch (before inferior run)"
65
66 # Set a throw catchpoint
67
68 gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \
69     "catch throw (before inferior run)"
70
71
72 # The catchpoints should be listed in the list of breakpoints.
73 # In case of a statically linked test, we won't have a pending breakpoint.
74 # Hence we allow for both an address or "<PENDING>". If we ever become able
75 # to tell whether the target is linked statically or not, we can be more
76 # precise and require exact output.
77 set addr "\(<PENDING>|$hex\)"
78 set re_head     "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
79 set re_2_bp     "1${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception catch"
80 set re_3_bp     "2${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception throw"
81
82 set name "info breakpoints (before inferior run)"
83 gdb_test_multiple "info breakpoints" $name {
84     -re "$re_head${ws}$re_2_bp${ws}$re_3_bp\r\n$gdb_prompt $" {
85         pass $name
86     }
87     -re ".*$gdb_prompt $"
88       {
89         fail $name
90       }
91 }
92
93 gdb_test "tbreak main" "Temporary breakpoint 3.*" \
94     "Set temporary breakpoint at main"
95
96 set ok 0
97 gdb_run_cmd
98 gdb_test_multiple "" "Run to main" {
99     -re "Temporary breakpoint 3,.*$gdb_prompt $" {
100         pass "Run to main"
101         set ok 1
102     }
103 }
104
105 if { !$ok } {
106     continue
107 }
108
109 set addr "$hex"
110 set re_head     "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
111 set re_2_bp     "1${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception catch"
112 set re_3_bp     "2${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception throw"
113
114 set name "info breakpoints (after inferior run)"
115 gdb_test_multiple "info breakpoints" $name {
116     -re "$re_head${ws}$re_2_bp${ws}$re_3_bp\r\n$gdb_prompt $" {
117         pass $name
118     }
119     -re ".*$gdb_prompt $"
120       {
121         send_user "\n---\n$expect_out(buffer)\n---\n"
122         fail $name
123       }
124 }
125
126 gdb_test "break catcher" "Breakpoint \[0-9\]+ at.*"
127
128 # Get the first exception thrown
129        
130 set name "continue to first throw"
131 gdb_test_multiple "continue" $name {
132     -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
133         pass $name
134     }
135     -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" {
136         pass $name
137     }
138 }
139
140 # Backtrace from the throw point.
141 # This should get to user code.
142
143 set name "backtrace after first throw"
144 gdb_test_multiple "backtrace" $name {
145     -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 $" {
146         # Either __cxxabiv1::__cxa_throw or __cxa_throw can be printed
147         # depending on debug info presence.
148         pass $name
149     }
150 }
151
152 # Continue to the catch.
153
154 set name "continue to first catch"
155 gdb_test_multiple "continue" $name {
156     -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
157         pass $name
158     }
159     -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" {
160         pass $name
161     }
162 }
163
164 # Backtrace from the catch point.
165 # This should get to user code.
166
167 set name "backtrace after first catch"
168 gdb_test_multiple "backtrace" $name {
169     -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
170         pass $name
171     }
172 }
173
174 # Continue to breakpoint on catcher.
175 gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the first time"
176
177 # Continue to second throw.
178
179 set name "continue to second throw"
180 gdb_test_multiple "continue" $name {
181     -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
182         pass $name
183     }
184     -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" {
185         pass $name
186     }
187 }
188
189 # Backtrace from the throw point.
190 # This should get to user code.
191
192 set name "backtrace after second throw"
193 gdb_test_multiple "backtrace" $name {
194     -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 $" {
195         pass $name
196     }
197 }
198
199 # Continue to second catch.
200
201 set name "continue to second catch"
202 gdb_test_multiple "continue" $name {
203     -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
204         pass $name
205     }
206     -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" {
207         pass $name
208     }
209 }
210
211 # Backtrace from the catch point.
212 # This should get to user code.
213
214 set name "backtrace after second catch"
215 gdb_test_multiple "backtrace" $name {
216     -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
217         pass $name
218     }
219 }
220
221 # Continue to breakpoint on catcher.
222 gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the second time"
223
224 # That is all for now.
225
226 # The original code had:
227 #
228 #    continue to re-throw ; backtrace
229 #    continue to catch    ; backtrace
230 #    continue to throw out of main
231 #
232 # The problem is that "re-throw" does not show a throw; only a catch.
233 # I do not know if this is because of a bug, or because the generated
234 # code is optimized for a throw into the same function.
235 #
236 # -- chastain 2004-01-09