1# Copyright 2008, 2010, 2011 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
16if $tracelevel then {
17	strace $tracelevel
18}
19
20if [target_info exists gdb,noinferiorio] {
21    verbose "Skipping unwindonsignal.exp because of no fileio capabilities."
22    continue
23}
24
25if [target_info exists gdb,nosignals] {
26    verbose "Skipping unwindonsignal.exp because of nosignals."
27    continue
28}
29
30
31set testfile "unwindonsignal"
32set srcfile ${testfile}.c
33set binfile ${objdir}/${subdir}/${testfile}
34
35if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
36     untested unwindonsignal.exp
37     return -1
38}
39
40# Some targets can't do function calls, so don't even bother with this
41# test.
42if [target_info exists gdb,cannot_call_functions] {
43    setup_xfail "*-*-*" 2416
44    fail "This target can not call functions"
45    continue
46}
47
48# Start with a fresh gdb.
49
50gdb_exit
51gdb_start
52gdb_reinitialize_dir $srcdir/$subdir
53gdb_load ${binfile}
54
55if { ![runto_main] } {
56    fail "Can't run to main"
57    return 0
58}
59
60gdb_test "break stop_here" "Breakpoint \[0-9\]* at .*"
61gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, stop_here.*" \
62    "continue to breakpoint at stop_here"
63
64# Turn on unwindonsignal.
65gdb_test_no_output "set unwindonsignal on" \
66	"setting unwindonsignal"
67
68gdb_test "show unwindonsignal" \
69	"Unwinding of stack .* is on." \
70	"showing unwindonsignal"
71
72# Call function (causing the program to get a signal), and see if gdb handles
73# it properly.
74gdb_test_multiple "call gen_signal ()" \
75	"unwindonsignal, inferior function call signaled" {
76    -re "\[\r\n\]*no signal\[\r\n\]+$gdb_prompt $" {
77	unsupported "unwindonsignal, inferior function call signaled"
78	return 0
79    }
80    -re "\[\r\n\]*The program being debugged was signaled.*\[\r\n\]+$gdb_prompt $" {
81	pass "unwindonsignal, inferior function call signaled"
82    }
83}
84
85# Verify the stack got unwound.
86gdb_test "bt" \
87    "#0 *\[x0-9a-f in\]*stop_here \\(.*\\) at .*#1 *\[x0-9a-f in\]*main \\(.*\\) at .*" \
88	"unwindonsignal, stack unwound"
89
90# Verify the dummy frame got removed from dummy_frame_stack.
91gdb_test_multiple "maint print dummy-frames" \
92	"unwindonsignal, dummy frame removed" {
93    -re "\[\r\n\]*.*stack=.*code=.*\[\r\n\]+$gdb_prompt $" {
94	fail "unwindonsignal, dummy frame removed"
95    }
96    -re "\[\r\n\]+$gdb_prompt $" {
97	pass "unwindonsignal, dummy frame removed"
98    }
99}
100
101return 0
102