]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/gdb2495.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / gdb2495.exp
CommitLineData
3666a048 1# Copyright 2009-2021 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.
02e7ea18
JB
29#
30# PR c++/9600.
7cd1089b
PM
31
32# This test is largely based of gdb.base/callfuncs.exp.
33
7cd1089b
PM
34if { [skip_cplus_tests] } { continue }
35
28f24826
DJ
36if [target_info exists gdb,nosignals] {
37 verbose "Skipping gdb2495.exp because of nosignals."
38 continue
39}
40
f5f3a911 41standard_testfile .cc
7cd1089b
PM
42
43# Create and source the file that provides information about the compiler
44# used to compile the test case.
4c93b1db 45if [get_compiler_info "c++"] {
7cd1089b
PM
46 return -1
47}
48
7cd1089b
PM
49# Some targets can't do function calls, so don't even bother with this
50# test.
51if [target_info exists gdb,cannot_call_functions] {
bc6c7af4 52 unsupported "this target can not call functions"
7cd1089b
PM
53 continue
54}
55
5b362f04 56if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
f5f3a911
TT
57 return -1
58}
7cd1089b
PM
59
60if ![runto_main] then {
61 perror "couldn't run to main"
62 continue
63}
64
65# See http://sourceware.org/gdb/bugs/2495
66
67# Test normal baseline behaviour. Call a function that
68# does not raise an exception.
69gdb_test "p exceptions.no_throw_function()" " = 1"
70# And one that does but handles it in-frame.
71gdb_test "p exceptions.throw_function_with_handler()" " = 2"
72# Both should return normally.
73
74# Test basic unwind. Call a function that raises an exception but
75# does not handle it. It should be rewound.
76gdb_test "p exceptions.throw_function()" \
77 "The program being debugged entered a std::terminate call, .*" \
bb95117e 78 "call a function that raises an exception without a handler."
7cd1089b
PM
79
80# Make sure that after rewinding we are back at the call parent.
81gdb_test "bt" \
82 "#0 main.*" \
83 "bt after returning from a popped frame"
84
85# Make sure the only breakpoint is the one set via the runto_main
86# call and that the std::terminate breakpoint has evaporated and
87# cleaned-up.
88gdb_test "info breakpoints" \
0344e878 89 "gdb2495\.cc.*"
7cd1089b
PM
90
91# Turn off this new behaviour.
fb9feb35 92gdb_test_no_output "set unwind-on-terminating-exception off"
7cd1089b
PM
93
94# Check that it is turned off.
95gdb_test "show unwind-on-terminating-exception" \
96 "exception is unhandled while in a call dummy is off.*" \
bb95117e 97 "turn off unwind on terminating exception flag"
7cd1089b
PM
98
99# Check that the old behaviour is restored.
100gdb_test "p exceptions.throw_function()" \
101 "The program being debugged was signaled while in a function called .*" \
bb95117e 102 "call a function that raises an exception with unwinding off.."
7cd1089b
PM
103
104# Restart the inferior back at main.
105if ![runto_main] then {
106 perror "couldn't run to main"
107 continue
108}
109
110
111# Check to see if the new behaviour alters the unwind signal
112# behaviour; it should not. Test both on and off states.
113
114# Turn on unwind on signal behaviour.
018572b8 115gdb_test_no_output "set unwindonsignal on"
7cd1089b
PM
116
117# Check that it is turned on.
118gdb_test "show unwindonsignal" \
119 "signal is received while in a call dummy is on.*" \
bb95117e 120 "turn on unwind on signal"
7cd1089b
PM
121
122# Check to see if new behaviour interferes with
123# normal signal handling in inferior function calls.
124gdb_test "p exceptions.raise_signal(1)" \
125 "To change this behavior use \"set unwindonsignal off\".*"
126
127# And reverse - turn off again.
018572b8 128gdb_test_no_output "set unwindonsignal off"
7cd1089b
PM
129
130# Check that it is actually turned off.
131gdb_test "show unwindonsignal" \
132 "signal is received while in a call dummy is off.*" \
bb95117e 133 "turn off unwind on signal"
7cd1089b
PM
134
135# Check to see if new behaviour interferes with
136# normal signal handling in inferior function calls.
137gdb_test "p exceptions.raise_signal(1)" \
138 "To change this behavior use \"set unwindonsignal on\".*"