]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/gdb2495.exp
* configure.ac: Move comment to remove extra space in last argument
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / gdb2495.exp
1 # Copyright 2009, 2010 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
17 # In gdb inferior function calls, if a C++ exception is raised in the
18 # dummy-frame, and the exception handler is (normally, and expected to
19 # be) out-of-frame, the default C++ handler will (wrongly) be called
20 # in an inferior function call.
21 # This is incorrect as an exception can normally and legally be handled
22 # out-of-frame. The confines of the dummy frame prevent the unwinder
23 # from finding the correct handler (or any handler, unless it is
24 # in-frame). The default handler calls std::terminate. This will kill
25 # the inferior. Assert that terminate should never be called in an
26 # inferior function call. These tests test the functionality around
27 # unwinding that sequence and also tests the flag behaviour gating this
28 # functionality.
29 #
30 # PR c++/9600.
31
32 # This test is largely based of gdb.base/callfuncs.exp.
33
34 if $tracelevel then {
35 strace $tracelevel
36 }
37
38 if { [skip_cplus_tests] } { continue }
39
40 if [target_info exists gdb,nosignals] {
41 verbose "Skipping gdb2495.exp because of nosignals."
42 continue
43 }
44
45 # On SPU this test fails because the executable exceeds local storage size.
46 if { [istarget "spu*-*-*"] } {
47 return 0
48 }
49
50 set testfile "gdb2495"
51 set srcfile ${testfile}.cc
52 set binfile $objdir/$subdir/$testfile
53
54 # Create and source the file that provides information about the compiler
55 # used to compile the test case.
56 if [get_compiler_info ${binfile} "c++"] {
57 return -1
58 }
59
60 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
61 untested gdb2495.exp
62 return -1
63 }
64
65 # Some targets can't do function calls, so don't even bother with this
66 # test.
67 if [target_info exists gdb,cannot_call_functions] {
68 setup_xfail "*-*-*" 2416
69 fail "This target can not call functions"
70 continue
71 }
72
73 gdb_exit
74 gdb_start
75 gdb_reinitialize_dir $srcdir/$subdir
76 gdb_load ${binfile}
77
78 if ![runto_main] then {
79 perror "couldn't run to main"
80 continue
81 }
82
83 # See http://sourceware.org/gdb/bugs/2495
84
85 # Test normal baseline behaviour. Call a function that
86 # does not raise an exception.
87 gdb_test "p exceptions.no_throw_function()" " = 1"
88 # And one that does but handles it in-frame.
89 gdb_test "p exceptions.throw_function_with_handler()" " = 2"
90 # Both should return normally.
91
92 # Test basic unwind. Call a function that raises an exception but
93 # does not handle it. It should be rewound.
94 gdb_test "p exceptions.throw_function()" \
95 "The program being debugged entered a std::terminate call, .*" \
96 "Call a function that raises an exception without a handler."
97
98 # Make sure that after rewinding we are back at the call parent.
99 gdb_test "bt" \
100 "#0 main.*" \
101 "bt after returning from a popped frame"
102
103 # Make sure the only breakpoint is the one set via the runto_main
104 # call and that the std::terminate breakpoint has evaporated and
105 # cleaned-up.
106 gdb_test "info breakpoints" \
107 "gdb.cp/gdb2495\.cc.*"
108
109 # Turn off this new behaviour.
110 gdb_test_multiple "set unwind-on-terminating-exception off" \
111 "Turn unwind-on-terminating-exception off" {
112 -re "$gdb_prompt $" {pass "set unwinn-on-terminating-exception off"}
113 timeout {fail "(timeout) set unwind-on-terminating-exception off"}
114 }
115
116 # Check that it is turned off.
117 gdb_test "show unwind-on-terminating-exception" \
118 "exception is unhandled while in a call dummy is off.*" \
119 "Turn off unwind on terminating exception flag"
120
121 # Check that the old behaviour is restored.
122 gdb_test "p exceptions.throw_function()" \
123 "The program being debugged was signaled while in a function called .*" \
124 "Call a function that raises an exception with unwinding off.."
125
126 # Restart the inferior back at main.
127 if ![runto_main] then {
128 perror "couldn't run to main"
129 continue
130 }
131
132
133 # Check to see if the new behaviour alters the unwind signal
134 # behaviour; it should not. Test both on and off states.
135
136 # Turn on unwind on signal behaviour.
137 gdb_test_multiple "set unwindonsignal on" "Turn unwindonsignal on" {
138 -re "$gdb_prompt $" {pass "set unwindonsignal on"}
139 timeout {fail "(timeout) set unwindonsignal on"}
140 }
141
142 # Check that it is turned on.
143 gdb_test "show unwindonsignal" \
144 "signal is received while in a call dummy is on.*" \
145 "Turn on unwind on signal"
146
147 # Check to see if new behaviour interferes with
148 # normal signal handling in inferior function calls.
149 gdb_test "p exceptions.raise_signal(1)" \
150 "To change this behavior use \"set unwindonsignal off\".*"
151
152 # And reverse - turn off again.
153 gdb_test_multiple "set unwindonsignal off" "Turn unwindonsignal off" {
154 -re "$gdb_prompt $" {pass "set unwindonsignal off"}
155 timeout {fail "(timeout) set unwindonsignal off"}
156 }
157
158 # Check that it is actually turned off.
159 gdb_test "show unwindonsignal" \
160 "signal is received while in a call dummy is off.*" \
161 "Turn off unwind on signal"
162
163 # Check to see if new behaviour interferes with
164 # normal signal handling in inferior function calls.
165 gdb_test "p exceptions.raise_signal(1)" \
166 "To change this behavior use \"set unwindonsignal on\".*"