1#   Copyright 1995, 1996, 1997, 1999, 2007, 2008, 2009, 2010, 2011
2#   Free Software Foundation, Inc.
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17if [target_info exists gdb,nosignals] {
18    verbose "Skipping sigall.exp because of nosignals."
19    continue
20}
21
22if $tracelevel then {
23	strace $tracelevel
24}
25
26
27gdb_exit
28gdb_start
29gdb_reinitialize_dir $srcdir/$subdir
30
31set testfile sigall
32set srcfile ${testfile}.c
33set binfile ${objdir}/${subdir}/${testfile}
34if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
35     untested sigall.exp
36     return -1
37}
38
39# Make the first signal SIGABRT because it is always supported.
40set sig_supported 1
41set thissig "ABRT"
42
43proc test_one_sig {nextsig} {
44    global sig_supported
45    global gdb_prompt
46    global thissig
47
48    set this_sig_supported $sig_supported
49    gdb_test "handle SIG$thissig stop print" \
50	"SIG$thissig\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Yes.*"
51    gdb_test "b handle_$thissig" "Breakpoint \[0-9\]+ .*"
52    gdb_test "b gen_$nextsig" "Breakpoint \[0-9\]+ .*"
53
54    set need_another_continue 1
55    set missed_handler 0
56    if $this_sig_supported then {
57	if { $thissig == "IO" } {
58	    setup_xfail "i*86-pc-linuxoldld-gnu" "i*86-pc-linuxaout-gnu"
59	}
60	gdb_test "continue" \
61	    "Continuing.*Program received signal SIG$thissig.*" \
62	    "get signal $thissig"
63    }
64    if [ istarget "alpha-dec-osf3*" ] then {
65	# OSF/1-3.x is unable to continue with a job control stop signal.
66	# The inferior remains stopped without an event of interest
67	# and GDB waits forever for the inferior to stop on an event
68	# of interest. Work around the kernel bug.
69	if { $thissig == "TSTP" || $thissig == "TTIN" || $thissig == "TTOU" } {
70	    setup_xfail "alpha-dec-osf3*"
71	    fail "cannot continue from signal $thissig"
72	    set need_another_continue 0
73	}
74    }
75
76    if $need_another_continue then {
77	if { $thissig == "URG" } {
78	    setup_xfail "i*86-pc-linuxoldld-gnu" "i*86-pc-linuxaout-gnu"
79	}
80        # Either Lynx or GDB screws up on SIGPRIO
81	if { $thissig == "PRIO" } {
82	    setup_xfail "*-*-*lynx*"
83	}
84	gdb_test_multiple "continue" "send signal $thissig" {
85	    -re "Breakpoint.*handle_$thissig.*$gdb_prompt $" {
86		pass "send signal $thissig"
87	    }
88	    -re "Breakpoint.*gen_$nextsig.*kill.*$gdb_prompt $" {
89		fail "missed breakpoint at handle_$thissig"
90		set missed_handler 1
91	    }
92	}
93    }
94
95    if { $missed_handler == "0" } then {
96	gdb_test_multiple "signal 0" "advance to $nextsig" {
97	    -re "Breakpoint.*gen_$nextsig.*\r\n\[0-9\]+\[ \t\]+kill \\(.*\r\n$gdb_prompt $" {
98	        pass "advance to $nextsig"
99	        set sig_supported 1
100	    }
101	    -re "Breakpoint.*gen_$nextsig.*\r\n\[0-9\]+\[ \t\]+handle_.*\r\n$gdb_prompt $" {
102	        pass "advance to $nextsig"
103	        set sig_supported 0
104	    }
105        }
106    }
107    set thissig $nextsig
108}
109
110gdb_load $binfile
111
112runto gen_ABRT
113test_one_sig HUP
114test_one_sig QUIT
115test_one_sig ILL
116test_one_sig EMT
117test_one_sig FPE
118test_one_sig BUS
119test_one_sig SEGV
120test_one_sig SYS
121test_one_sig PIPE
122test_one_sig ALRM
123test_one_sig URG
124test_one_sig TSTP
125test_one_sig CONT
126test_one_sig CHLD
127test_one_sig TTIN
128test_one_sig TTOU
129test_one_sig IO
130test_one_sig XCPU
131test_one_sig XFSZ
132test_one_sig VTALRM
133test_one_sig PROF
134test_one_sig WINCH
135test_one_sig LOST
136test_one_sig USR1
137test_one_sig USR2
138test_one_sig PWR
139test_one_sig POLL
140test_one_sig WIND
141test_one_sig PHONE
142test_one_sig WAITING
143test_one_sig LWP
144test_one_sig DANGER
145test_one_sig GRANT
146test_one_sig RETRACT
147test_one_sig MSG
148test_one_sig SOUND
149test_one_sig SAK
150test_one_sig PRIO
151test_one_sig 33
152test_one_sig 34
153test_one_sig 35
154test_one_sig 36
155test_one_sig 37
156test_one_sig 38
157test_one_sig 39
158test_one_sig 40
159test_one_sig 41
160test_one_sig 42
161test_one_sig 43
162test_one_sig 44
163test_one_sig 45
164test_one_sig 46
165test_one_sig 47
166test_one_sig 48
167test_one_sig 49
168test_one_sig 50
169test_one_sig 51
170test_one_sig 52
171test_one_sig 53
172test_one_sig 54
173test_one_sig 55
174test_one_sig 56
175test_one_sig 57
176test_one_sig 58
177test_one_sig 59
178test_one_sig 60
179test_one_sig 61
180test_one_sig 62
181test_one_sig 63
182test_one_sig TERM
183
184# The last signal (SIGTERM) gets handled slightly differently because
185# we are not setting up for another test.
186gdb_test "handle SIGTERM stop print" \
187    "SIGTERM\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Yes.*"
188gdb_test "b handle_TERM" "Breakpoint \[0-9\]+ .*"
189gdb_test "continue" \
190    "Continuing.*Program received signal SIGTERM.*" \
191    "get signal TERM"
192gdb_test "continue" "Breakpoint.*handle_TERM.*" "send signal TERM"
193gdb_continue_to_end "continue to sigall exit"
194
195return 0
196