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