8 gdb_reinitialize_dir $srcdir/$subdir
9 set binfile $objdir/$subdir/signals
11 if ![file exists $binfile] then {
12 perror "$binfile does not exist."
16 proc signal_tests_1 {} {
18 if [runto main] then {
19 gdb_test "next" "signal \[(\]+SIGUSR1" \
20 "next over signal \[(\]SIGALRM, handler\[)\]+"
21 gdb_test "next" "alarm \[(\]" \
22 "next over signal \[(\]+SIGUSR1, handler\[)\]+"
23 gdb_test "next" "\[+\]+count" \
25 # An alarm has been signaled, give the signal time to get delivered.
28 # i386 BSD currently fails the next test with a SIGTRAP.
29 setup_xfail "i*86-*-bsd*"
30 # But Dynix has a DECR_PC_AFTER_BREAK of zero, so the failure
31 # is shadowed by hitting the through_sigtramp_breakpoint.
32 clear_xfail "i*86-sequent-bsd*"
33 # Univel SVR4 i386 continues instead of stepping.
34 setup_xfail "i*86-univel-sysv4*"
37 -re "alarm .*$prompt $" { pass "next to 2nd alarm (1)" }
38 -re "Program received signal SIGTRAP.*first.*$prompt $" {
40 # This can happen on machines that have a trace flag
41 # in their PS register.
42 # The trace flag in the PS register will be set due to
44 # Before calling the signal handler, the PS register
45 # is pushed along with the context on the user stack.
46 # When the signal handler has finished, it reenters the
47 # the kernel via a sigreturn syscall, which restores the
48 # PS register along with the context.
49 # If the kernel erroneously does not clear the trace flag
50 # in the pushed context, gdb will receive a SIGTRAP from
51 # the set trace flag in the restored context after the
52 # signal handler has finished.
54 # I do not yet understand why the SIGTRAP does not occur
55 # after stepping the instruction at the restored PC on
56 # i386 BSDI 1.0 systems.
58 # Note that the vax under Ultrix also exhibits
59 # this behaviour (it is uncovered by the `continue from
60 # a break in a signal handler' test below).
61 # With this test the failure is shadowed by hitting the
62 # through_sigtramp_breakpoint upon return from the signal
65 fail "next to 2nd alarm (1) (probably kernel bug)"
66 gdb_test "next" "alarm" "next to 2nd alarm (1)"
68 -re "Program exited with code.*$prompt $" {
70 # This is apparently a bug in the UnixWare kernel (but
71 # has not been investigated beyond the
72 # resume/target_wait level, and has not been reported
73 # to Univel). If it steps when a signal is pending,
74 # it does a continue instead. I don't know whether
75 # there is a workaround.
77 # Perhaps this problem exists on other SVR4 systems;
78 # but (a) we have no reason to think so, and (b) if we
79 # put a wrong xfail here, we never get an XPASS to let
80 # us know that it was incorrect (and then if such a
81 # configuration regresses we have no way of knowing).
82 # Solaris is not a relevant data point either way
83 # because it lacks single stepping.
85 fail "'next' behaved as 'continue'"
88 -re ".*$prompt $" { fail "next to 2nd alarm (1)" }
89 timeout { fail "next to 2nd alarm (1); (timeout)" }
90 eof { fail "next to 2nd alarm (1); (eof)" }
93 gdb_test "break handler" "Breakpoint \[0-9\]*"
94 gdb_test "next" "\[+\]+count" "next to 2nd ++count"
95 # An alarm has been signaled, give the signal time to get delivered.
101 -re "Breakpoint.*handler.*$prompt $" { pass "next" }
102 -re "Program received signal SIGEMT.*$prompt $" {
103 # Bash versions before 1.13.5 cause this behaviour
104 # by blocking SIGTRAP.
105 fail "next (known problem with bash versions before 1.13.5)"
107 gdb_test "signal 0" "Breakpoint.*handler"
109 -re ".*$prompt $" { fail "next" }
110 timeout { fail "(timeout)" }
114 # This doesn't test that main is frame #2, just that main is frame
115 # #2, #3, or higher. At some point this should be fixed (but
116 # it quite possibly would introduce new FAILs on some systems).
117 gdb_test "backtrace" "#0.*handler.*#1.*#2.*main"
119 gdb_test "break func1" "Breakpoint \[0-9\]*"
120 gdb_test "break func2" "Breakpoint \[0-9\]*"
122 # Vax Ultrix and i386 BSD currently fail the next test with
123 # a SIGTRAP, but with different symptoms.
124 setup_xfail "vax-*-ultrix*"
125 setup_xfail "i*86-*-bsd*"
128 -re "Breakpoint.*func1.*$prompt $" { pass "continue" }
129 -re "Program received signal SIGTRAP.*second.*$prompt $" {
131 # See explanation for `next to 2nd alarm (1)' fail above.
132 # We did step into the signal handler, hit a breakpoint
133 # in the handler and continued from the breakpoint.
134 # The set trace flag in the restored context is causing
135 # the SIGTRAP, without stepping an instruction.
137 fail "continue (probably kernel bug)"
138 gdb_test "continue" "Breakpoint.*func1"
140 -re "Program received signal SIGTRAP.*func1 ..;.*$prompt $" {
142 # On the vax under Ultrix the set trace flag in the restored
143 # context is causing the SIGTRAP, but after stepping one
144 # instruction, as expected.
146 fail "continue (probably kernel bug)"
147 gdb_test "continue" "Breakpoint.*func1"
149 -re ".*$prompt $" { fail "continue" }
150 default { fail "continue" }
152 gdb_test "signal SIGUSR1" "Breakpoint.*handler"
154 # Will tend to wrongly require an extra continue.
156 # The problem here is that the breakpoint at func1 will be
157 # inserted, and when the system finishes with the signal
158 # handler it will try to execute there. For GDB to try to
159 # remember that it was going to step over a breakpoint when a
160 # signal happened, distinguish this case from the case where
161 # func1 is called from the signal handler, etc., seems
162 # exceedingly difficult. So don't expect this to get fixed
168 -re "Breakpoint.*func2.*$prompt $" { pass "continue" }
169 -re "Breakpoint.*func1.*$prompt $" {
171 gdb_test "continue" "Breakpoint.*func2"
173 -re ".*$prompt $" { fail "continue" }
174 default { fail "continue" }
179 # GDB yanks out the breakpoints to step over the breakpoint it
180 # stopped at, which means the breakpoint at handler is yanked.
181 # But if NO_SINGLE_STEP, we won't get another chance to reinsert
182 # them (at least not with procfs, where we tell the kernel not
183 # to tell gdb about `pass' signals). So the fix would appear to
184 # be to just yank that one breakpoint when we step over it.
186 setup_xfail "sparc-*-*"
187 setup_xfail "rs6000-*-*"
189 # A faulty bash will not step the inferior into sigtramp on sun3.
190 if {$bash_bug} then {
191 setup_xfail "m68*-*-sunos4*"
194 gdb_test "continue" "Breakpoint.*handler"
196 # If the NO_SINGLE_STEP failure happened, we have already exited.
197 # If we succeeded a continue will return from the handler to func2.
198 # GDB now has `forgotten' that it intended to step over the
199 # breakpoint at func2 and will stop at func2.
201 # The sun3 with a faulty bash will also be `forgetful' but it
202 # already got the spurious stop at func2 and this continue will work.
203 if {$bash_bug} then {
204 clear_xfail "m68*-*-sunos4*"
206 gdb_test "continue" "Program exited with code 010"
210 # On a few losing systems, ptrace (PT_CONTINUE) or ptrace (PT_STEP)
211 # causes pending signals to be cleared, which causes these tests to
212 # get nowhere fast. This is totally losing behavior (perhaps there
213 # are cases in which is it useful but the user needs more control,
214 # which they mostly have in GDB), but some people apparently think it
215 # is a feature. It is documented in the ptrace manpage on Motorola
216 # Delta Series sysV68 R3V7.1 and on HPUX 9.0. Even the non-HPUX PA
217 # OSes (BSD and OSF/1) seem to have figured they had to copy this
220 if {[ istarget "m68*-motorola-*" ] || [ istarget "hppa*-*-bsd*" ] ||
221 [ istarget "*-*-hpux*" ] || [ istarget "hppa*-*-osf*" ]} then {
223 fail "ptrace loses on signals on this target"
231 # Force a resync, so we're looking at the right prompt. On SCO we
232 # were getting out of sync (I don't understand why).
235 -re "= 2.*$prompt $" {}
236 -re ".*$prompt $" { perror "sync trouble in signals.exp" }
237 default { perror "sync trouble in signals.exp" }
240 if [runto main] then {
241 gdb_test "break handler if 0" "Breakpoint \[0-9\]*"
242 gdb_test "set \\\$handler_breakpoint_number = \\\$bpnum" ""
244 # Get to the point where a signal is waiting to be delivered
245 gdb_test "next" "signal \[(\]+SIGUSR1"
246 gdb_test "next" "alarm \[(\]+"
247 gdb_test "next" "\[+\]+count"
248 # Give the signal time to get delivered
251 # Now call a function. When GDB tries to run the stack dummy,
252 # it will hit the breakpoint at handler. Provided it doesn't
253 # lose its cool, this is not a problem, it just has to note
254 # that the breakpoint condition is false and keep going.
256 gdb_test "p func1 ()" "^p func1 \[)(\]+\r\n.\[0-9\]* = void"
258 # Make sure the count got incremented.
260 # Haven't investigated this xfail
261 setup_xfail "rs6000-*-*"
262 gdb_test "p count" "= 2"
263 if [istarget "rs6000-*-*"] { return 0 }
265 gdb_test "condition \\\$handler_breakpoint_number" "now unconditional"
266 gdb_test "next" "alarm \[(\]+"
267 gdb_test "next" "\[+\]+count"
270 # This time we stop when GDB tries to run the stack dummy.
271 # So it is OK that we do not print the return value from the function.
272 gdb_test "p func1 ()" \
273 "Breakpoint \[0-9\]*, handler.*
274 The program being debugged stopped while in a function called from GDB"
275 # But we should be able to backtrace...
276 gdb_test "bt" "#0.*handler.*#1.*#2.*main"
278 gdb_test "continue" "Continuing"
279 # ...and then count should have been incremented
280 gdb_test "p count" "= 5"