* TODO: Add note about "handle all nostop".
[external/binutils.git] / gdb / testsuite / gdb.base / sigall.exp
1 #   Copyright (C) 1995 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 2 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, write to the Free Software
15 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
16
17 if $tracelevel then {
18         strace $tracelevel
19 }
20
21 set prms_id 0
22 set bug_id 0
23
24 gdb_reinitialize_dir $srcdir/$subdir
25 set binfile $objdir/$subdir/sigall
26
27 if ![file exists $binfile] then {
28     perror "$binfile does not exist."
29     return 0
30 }
31
32 # Make the first signal SIGABRT because it is always supported.
33 set sig_supported 1
34 set thissig "ABRT"
35
36 proc test_one_sig {nextsig} {
37     global sig_supported
38     global prompt
39     global thissig
40
41     set this_sig_supported $sig_supported
42     gdb_test "handle SIG$thissig stop print" \
43         "SIG$thissig\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Yes"
44     gdb_test "b handle_$thissig" "Breakpoint \[0-9\]"
45     gdb_test "b gen_$nextsig" "Breakpoint \[0-9\]"
46     if $this_sig_supported then {
47         if {"$thissig" == "POLL"} then {
48             # If SIGIO and SIGPOLL are the same signal it gets reported
49             # as SIGIO; it is a feature for GDB to always use the "preferred"
50             # name (the POSIX name if there is one, etc.); I suspect that is
51             # SIGIO in this case but I'm not sure.
52             set pattern "(POLL|IO)"
53         } else {
54             set pattern $thissig
55         }
56         gdb_test "continue" \
57             "Continuing.*Program received signal SIG$pattern" \
58             "get signal $thissig"
59     }
60     if {"$thissig" == "IO"} then {
61         # SIGIO and SIGPOLL might be the same signal.
62         # If so we end up at handle_POLL because we
63         # establish the handler for SIGPOLL after SIGIO.
64         set pattern "Breakpoint.*handle_(POLL|IO)"
65     } else {
66         set pattern "Breakpoint.*handle_$thissig" 
67     }
68     gdb_test "continue" $pattern "send signal $thissig"
69     send "continue\n"
70     expect {
71         -re "Breakpoint.*gen_$nextsig.*kill.*$prompt $" {
72             pass "advance to $nextsig"
73             set sig_supported 1
74         }
75         -re "Breakpoint.*gen_$nextsig.*handle.*$prompt $" {
76             pass "advance to $nextsig"
77             set sig_supported 0
78         }
79         -re ".*$prompt $" { fail "advance to $nextsig" }
80         default { fail "advance to $nextsig (eof or timeout)" }
81     }
82     set thissig $nextsig
83 }
84
85 gdb_load $binfile
86
87 runto gen_ABRT
88 test_one_sig HUP
89 test_one_sig QUIT
90 test_one_sig ILL
91 test_one_sig EMT
92 test_one_sig FPE
93 test_one_sig BUS
94 test_one_sig SEGV
95 test_one_sig SYS
96 test_one_sig PIPE
97 test_one_sig ALRM
98 test_one_sig URG
99 test_one_sig TSTP
100 test_one_sig CONT
101 test_one_sig CHLD
102 test_one_sig TTIN
103 test_one_sig TTOU
104 test_one_sig IO
105
106 # Set an extra breakpoint at handle_POLL, to deal with the fact that
107 # SIGIO and SIGPOLL might be the same signal.
108
109 gdb_test "b handle_POLL" "Breakpoint \[0-9\]" \
110     "set extra handle_POLL breakpoint"
111
112 test_one_sig XCPU
113 test_one_sig XFSZ
114 test_one_sig VTALRM
115 test_one_sig PROF
116 test_one_sig WINCH
117 test_one_sig LOST
118 test_one_sig USR1
119 test_one_sig USR2
120 test_one_sig PWR
121 test_one_sig POLL
122 test_one_sig WIND
123 test_one_sig PHONE
124 test_one_sig WAITING
125 test_one_sig LWP
126 test_one_sig DANGER
127 test_one_sig GRANT
128 test_one_sig RETRACT
129 test_one_sig MSG
130 test_one_sig SOUND
131 test_one_sig SAK
132 test_one_sig PRIO
133 test_one_sig 33
134 test_one_sig 34
135 test_one_sig 35
136 test_one_sig 36
137 test_one_sig 37
138 test_one_sig 38
139 test_one_sig 39
140 test_one_sig 40
141 test_one_sig 41
142 test_one_sig 42
143 test_one_sig 43
144 test_one_sig 44
145 test_one_sig 45
146 test_one_sig 46
147 test_one_sig 47
148 test_one_sig 48
149 test_one_sig 49
150 test_one_sig 50
151 test_one_sig 51
152 test_one_sig 52
153 test_one_sig 53
154 test_one_sig 54
155 test_one_sig 55
156 test_one_sig 56
157 test_one_sig 57
158 test_one_sig 58
159 test_one_sig 59
160 test_one_sig 60
161 test_one_sig 61
162 test_one_sig 62
163 test_one_sig 63
164 test_one_sig TERM
165
166 # The last signal (SIGTERM) gets handled slightly differently because
167 # we are not setting up for another test.
168 gdb_test "handle SIGTERM stop print" \
169     "SIGTERM\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Yes"
170 gdb_test "b handle_TERM" "Breakpoint \[0-9\]"
171 gdb_test "continue" \
172     "Continuing.*Program received signal SIGTERM" \
173     "get signal TERM"
174 gdb_test "continue" "Breakpoint.*handle_TERM" "send signal TERM"
175 gdb_test "continue" "Program exited normally" "continue to sigall exit"
176
177 return 0