OSDN Git Service

Update copyright year in most headers.
[pf3gnuchains/pf3gnuchains4x.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 # This test is largely based of gdb.base/callfuncs.exp.
31
32 if $tracelevel then {
33     strace $tracelevel
34 }
35
36 if { [skip_cplus_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 set prms_id 2495
44 set bug_id 0
45
46 set testfile "gdb2495"
47 set srcfile ${testfile}.cc
48 set binfile $objdir/$subdir/$testfile
49
50 # Create and source the file that provides information about the compiler
51 # used to compile the test case.
52 if [get_compiler_info ${binfile} "c++"] {
53     return -1
54 }
55
56 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
57      untested gdb2495.exp
58      return -1
59 }
60
61 # Some targets can't do function calls, so don't even bother with this
62 # test.
63 if [target_info exists gdb,cannot_call_functions] {
64     setup_xfail "*-*-*" 2416
65     fail "This target can not call functions"
66     continue
67 }
68
69 gdb_exit
70 gdb_start
71 gdb_reinitialize_dir $srcdir/$subdir
72 gdb_load ${binfile}
73
74 if ![runto_main] then {
75     perror "couldn't run to main"
76     continue
77 }
78
79 # See http://sourceware.org/gdb/bugs/2495
80
81 # Test normal baseline behaviour. Call a function that
82 # does not raise an exception.
83 gdb_test "p exceptions.no_throw_function()" " = 1"
84 # And one that does but handles it in-frame.
85 gdb_test "p exceptions.throw_function_with_handler()" " = 2"
86 # Both should return normally.
87
88 # Test basic unwind.  Call a function that raises an exception but
89 # does not handle it.  It should be rewound.
90 gdb_test "p exceptions.throw_function()" \
91     "The program being debugged entered a std::terminate call, .*" \
92     "Call a function that raises an exception without a handler."
93
94 # Make sure that after rewinding we are back at the call parent.
95 gdb_test "bt" \
96     "#0  main.*" \
97     "bt after returning from a popped frame"
98
99 # Make sure the only breakpoint is the one set via the runto_main
100 # call and that the std::terminate breakpoint has evaporated and
101 # cleaned-up.
102 gdb_test "info breakpoints" \
103     "gdb.cp/gdb2495\.cc.*"
104
105 # Turn off this new behaviour.
106 gdb_test_multiple "set unwind-on-terminating-exception off" \
107     "Turn unwind-on-terminating-exception off" {
108     -re "$gdb_prompt $" {pass "set unwinn-on-terminating-exception off"}
109     timeout {fail "(timeout) set unwind-on-terminating-exception off"}
110 }
111
112 # Check that it is turned off.
113 gdb_test "show unwind-on-terminating-exception" \
114     "exception is unhandled while in a call dummy is off.*" \
115     "Turn off unwind on terminating exception flag"
116
117 # Check that the old behaviour is restored.
118 gdb_test "p exceptions.throw_function()" \
119     "The program being debugged was signaled while in a function called .*" \
120     "Call a function that raises an exception with unwinding off.."
121
122 # Restart the inferior back at main.
123 if ![runto_main] then {
124     perror "couldn't run to main"
125     continue
126 }
127
128
129 # Check to see if the new behaviour alters the unwind signal
130 # behaviour; it should not.  Test both on and off states.
131
132 # Turn on unwind on signal behaviour.
133 gdb_test_multiple "set unwindonsignal on" "Turn unwindonsignal on" {
134     -re "$gdb_prompt $" {pass "set unwindonsignal on"}
135     timeout {fail "(timeout) set unwindonsignal on"}
136 }
137
138 # Check that it is turned on.
139 gdb_test "show unwindonsignal" \
140     "signal is received while in a call dummy is on.*" \
141     "Turn on unwind on signal"
142
143 # Check to see if new behaviour interferes with
144 # normal signal handling in inferior function calls.
145 gdb_test "p exceptions.raise_signal(1)" \
146     "To change this behavior use \"set unwindonsignal off\".*"
147
148 # And reverse - turn off again.
149 gdb_test_multiple "set unwindonsignal off" "Turn unwindonsignal off" {
150     -re "$gdb_prompt $" {pass "set unwindonsignal off"}
151     timeout {fail "(timeout) set unwindonsignal off"}
152 }
153
154 # Check that it is actually turned off.
155 gdb_test "show unwindonsignal" \
156     "signal is received while in a call dummy is off.*" \
157     "Turn off unwind on signal"
158
159 # Check to see if new behaviour interferes with
160 # normal signal handling in inferior function calls.
161 gdb_test "p exceptions.raise_signal(1)" \
162     "To change this behavior use \"set unwindonsignal on\".*"