xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.base/unwindonsignal.exp (revision 7dc3041b3dd6e94fb73609429278b8f58b60359c)
1# Copyright 2008-2024 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
16require {!target_info exists gdb,nosignals}
17
18
19# Some targets can't do function calls, so don't even bother with this
20# test.
21require {!target_info exists gdb,cannot_call_functions}
22
23standard_testfile
24
25if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
26    return -1
27}
28
29if { ![runto_main] } {
30    return 0
31}
32
33gdb_test "break stop_here" "Breakpoint \[0-9\]* at .*"
34gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, stop_here.*" \
35    "continue to breakpoint at stop_here"
36
37# Turn on unwind-on-signal.
38gdb_test_no_output "set unwind-on-signal on" \
39	"setting unwind-on-signal"
40
41gdb_test "show unwind-on-signal" \
42	"Unwinding of stack .* is on." \
43	"showing unwind-on-signal"
44
45# For backward compatibility we maintain a 'unwindonsignal' alias for
46# 'unwind-on-signal', check it now.
47gdb_test "show unwindonsignal" \
48    "Unwinding of stack .* is on\\." \
49    "showing unwindonsignal alias"
50
51gdb_test_no_output "set unwindonsignal off" \
52    "setting unwindonsignal alias to off"
53
54gdb_test "show unwind-on-signal" \
55    "Unwinding of stack .* is off\\." \
56    "showing unwind-on-signal after setting via alias"
57
58gdb_test_no_output "set unwindonsignal on" \
59    "setting unwindonsignal alias to on"
60
61# Call function (causing the program to get a signal), and see if gdb handles
62# it properly.
63if {[gdb_test "call gen_signal ()"  \
64	 [multi_line \
65	      "The program being debugged received signal SIGABRT, Aborted" \
66	      "while in a function called from GDB\\.  GDB has restored the context" \
67	      "to what it was before the call\\.  To change this behavior use" \
68	      "\"set unwind-on-signal off\"\\.  Evaluation of the expression containing" \
69	      "the function \\(gen_signal\\) will be abandoned\\."] \
70	 "unwindonsignal, inferior function call signaled"] != 0} {
71    return 0
72}
73
74# Verify the stack got unwound.
75gdb_test "bt" \
76    "#0 *\[x0-9a-f in\]*stop_here \\(.*\\) at .*#1 *\[x0-9a-f in\]*main \\(.*\\) at .*" \
77	"stack unwound"
78
79# Verify the dummy frame got removed from dummy_frame_stack.
80gdb_test_multiple "maint print dummy-frames" \
81	"unwind-on-signal, dummy frame removed" {
82    -re "\[\r\n\]*.*stack=.*code=.*\[\r\n\]+$gdb_prompt $" {
83	fail $gdb_test_name
84    }
85    -re "\[\r\n\]+$gdb_prompt $" {
86	pass $gdb_test_name
87    }
88}
89