Automatic date update in version.in
[binutils-gdb.git] / gdb / testsuite / gdb.cp / gdb2495.exp
blob86ee7f92723f47d2a494162ead01f4f95079af71
1 # Copyright 2009-2024 Free Software Foundation, Inc.
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.
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.
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/>.
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 behavior gating this
28 # functionality.
30 # PR c++/9600.
32 # This test is largely based of gdb.base/callfuncs.exp.
34 require allow_cplus_tests
36 require {!target_info exists gdb,nosignals}
38 standard_testfile .cc
40 # Some targets can't do function calls, so don't even bother with this
41 # test.
42 require {!target_info exists gdb,cannot_call_functions}
44 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
45     return -1
48 if {![runto_main]} {
49     return
52 # See http://sourceware.org/gdb/bugs/2495
54 # Test normal baseline behavior. Call a function that
55 # does not raise an exception.
56 gdb_test "p exceptions.no_throw_function()" " = 1"
57 # And one that does but handles it in-frame.
58 gdb_test "p exceptions.throw_function_with_handler()" " = 2"
59 # Both should return normally.
61 # Test basic unwind.  Call a function that raises an exception but
62 # does not handle it.  It should be rewound.
63 gdb_test "p exceptions.throw_function()" \
64     "The program being debugged entered a std::terminate call, .*" \
65     "call a function that raises an exception without a handler."
67 # Make sure that after rewinding we are back at the call parent.
68 gdb_test "bt" \
69     "#0  main.*" \
70     "bt after returning from a popped frame"
72 # Make sure the only breakpoint is the one set via the runto_main
73 # call and that the std::terminate breakpoint has evaporated and
74 # cleaned-up.
75 gdb_test "info breakpoints" \
76     "gdb2495\.cc.*"
78 # Turn off this new behavior.
79 gdb_test_no_output "set unwind-on-terminating-exception off"
81 # Check that it is turned off.
82 gdb_test "show unwind-on-terminating-exception" \
83     "exception is unhandled while in a call dummy is off.*" \
84     "turn off unwind on terminating exception flag"
86 # Check that the old behavior is restored.
87 gdb_test "p exceptions.throw_function()" \
88     "The program being debugged was signaled while in a function called .*" \
89     "call a function that raises an exception with unwinding off.."
91 # Restart the inferior back at main.
92 if {![runto_main]} {
93     return
97 # Check to see if the new behavior alters the unwind signal
98 # behaviour; it should not.  Test both on and off states.
100 # Turn on unwind on signal behavior.
101 gdb_test_no_output "set unwind-on-signal on"
103 # Check that it is turned on.
104 gdb_test "show unwind-on-signal" \
105     "signal is received while in a call dummy is on.*" \
106     "turn on unwind on signal"
108 # Check to see if new behavior interferes with
109 # normal signal handling in inferior function calls.
110 gdb_test "p exceptions.raise_signal(1)" \
111     [multi_line \
112          "The program being debugged received signal SIGABRT, Aborted" \
113          "while in a function called from GDB\\.  GDB has restored the context" \
114          "to what it was before the call\\.  To change this behavior use" \
115          "\"set unwind-on-signal off\"\\.  Evaluation of the expression containing" \
116          "the function \\(SimpleException::raise_signal\\(int\\)\\) will be abandoned\\."]\
117     "check for unwind-on-signal off message"
119 # And reverse - turn off again.
120 gdb_test_no_output "set unwind-on-signal off"
122 # Check that it is actually turned off.
123 gdb_test "show unwind-on-signal" \
124     "signal is received while in a call dummy is off.*" \
125     "turn off unwind on signal"
127 # Check to see if new behavior interferes with
128 # normal signal handling in inferior function calls.
129 gdb_test "p exceptions.raise_signal(1)" \
130     "To change this behavior use \"set unwind-on-signal on\".*" \
131     "check for unwind-on-signal on message"