Commit | Line | Data |
---|---|---|
6aba47ca | 1 | # Copyright 1997, 1998, 1999, 2003, 2004, 2007 Free Software Foundation, Inc. |
c906108c SS |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
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. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 15 | |
c906108c SS |
16 | if [target_info exists gdb,nosignals] { |
17 | verbose "Skipping signals.exp because of nosignals." | |
18 | continue | |
19 | } | |
20 | ||
21 | if $tracelevel then { | |
22 | strace $tracelevel | |
23 | } | |
24 | ||
25 | set prms_id 0 | |
26 | set bug_id 0 | |
27 | ||
28 | set testfile signals | |
29 | set srcfile ${testfile}.c | |
30 | set binfile ${objdir}/${subdir}/${testfile} | |
31 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
b60f0898 JB |
32 | untested signals.exp |
33 | return -1 | |
c906108c SS |
34 | } |
35 | ||
36 | # Create and source the file that provides information about the compiler | |
37 | # used to compile the test case. | |
38 | if [get_compiler_info ${binfile}] { | |
39 | return -1; | |
40 | } | |
41 | ||
085dd6e6 JM |
42 | if {$hp_cc_compiler} { |
43 | set void 0 | |
44 | } else { | |
45 | set void void | |
46 | } | |
47 | ||
c906108c SS |
48 | gdb_exit |
49 | gdb_start | |
50 | ||
51 | # This will need to be updated as the exact list of signals changes, | |
52 | # but I want to test that TARGET_SIGNAL_0, TARGET_SIGNAL_DEFAULT, and | |
53 | # TARGET_SIGNAL_UNKNOWN are skipped. | |
78650829 | 54 | |
c906108c SS |
55 | proc test_handle_all_print {} { |
56 | global timeout | |
57 | # Increase timeout and expect input buffer for large output from gdb. | |
58 | # Allow blank or TAB as whitespace characters. | |
59 | set oldtimeout $timeout | |
60 | set timeout [expr "$timeout + 360"] | |
61 | verbose "Timeout is now $timeout seconds" 2 | |
7a292a7a SS |
62 | if { ![istarget "*-*-linux*"] |
63 | && ( [istarget "*-*-gnu*"] | |
64 | || [istarget "*-*-mach*"] ) } { | |
c906108c SS |
65 | gdb_test "handle all print" "Signal\[ \]+Stop\[ \]+Print\[ \]+Pass to program\[ \]+Description\r\nSIGHUP\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Hangup.*SIG63\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Real-time event 63.*EXC_BREAKPOINT\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Breakpoint" |
66 | } else { | |
104c1213 | 67 | gdb_test "handle all print" "Signal\[ \]+Stop\[ \]+Print\[ \]+Pass to program\[ \]+Description\r\nSIGHUP\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Hangup.*SIG63\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Real-time event 63.*" |
c906108c SS |
68 | } |
69 | set timeout $oldtimeout | |
70 | verbose "Timeout restored to $timeout seconds" 2 | |
71 | } | |
72 | test_handle_all_print | |
73 | ||
74 | gdb_exit | |
75 | gdb_start | |
76 | gdb_reinitialize_dir $srcdir/$subdir | |
77 | gdb_load $binfile | |
c906108c | 78 | |
c906108c | 79 | if [runto_main] then { |
78650829 AC |
80 | |
81 | # Since count is a static variable outside main, runto_main is no | |
82 | # guarantee that count will be 0 at this point. | |
83 | ||
b7844da6 | 84 | gdb_test "set variable count = 0" "" |
23b451cf AC |
85 | |
86 | # Test an inferior function call that takes a signal that hits a | |
87 | # breakpoint (with a false condition). When GDB tries to run the | |
88 | # stack dummy, it will hit the breakpoint at handler. Provided it | |
89 | # doesn't lose its cool, this is not a problem, it just has to | |
90 | # note that the breakpoint condition is false and keep going. | |
91 | ||
92 | # ...setup an always false conditional breakpoint | |
93 | ||
c906108c SS |
94 | gdb_test "break handler if 0" "Breakpoint \[0-9\]+ .*" |
95 | gdb_test "set \$handler_breakpoint_number = \$bpnum" "" | |
96 | ||
23b451cf | 97 | # ...setup the signal |
78650829 | 98 | |
23b451cf AC |
99 | gdb_test "next" "signal \\(SIGUSR1.*" "next to signal" |
100 | gdb_test "next" "alarm \\(.*" "next to alarm #1" | |
c906108c | 101 | gdb_test "next" "\\+\\+count; /\\* first \\*/" \ |
23b451cf | 102 | "next to ++count #1" |
78650829 | 103 | sleep 2 |
23b451cf AC |
104 | |
105 | # ...call the function | |
c906108c | 106 | |
085dd6e6 | 107 | gdb_test "p func1 ()" "^p func1 \\(\\)\r\n.\[0-9\]* = $void" \ |
23b451cf | 108 | "p func1 () #1" |
c906108c | 109 | |
23b451cf | 110 | # ...veryfiy that the cout was updated |
c906108c | 111 | |
23b451cf | 112 | gdb_test "p count" "= 2" "p count #1" |
78650829 | 113 | |
23b451cf AC |
114 | # Now run the same test but with a breakpoint that does stop. |
115 | ||
116 | # ...set up the breakpoint and signal | |
c906108c SS |
117 | |
118 | gdb_test "condition \$handler_breakpoint_number" "now unconditional\\." | |
23b451cf | 119 | gdb_test "next" "alarm \\(.*" "next to alarm #2" |
c906108c | 120 | gdb_test "next" "\\+\\+count; /\\* second \\*/" \ |
23b451cf | 121 | "next to ++count #2" |
c906108c SS |
122 | sleep 2 |
123 | ||
23b451cf | 124 | # ...call the function, which is immediatly interrupted |
78650829 | 125 | |
c906108c SS |
126 | gdb_test "p func1 ()" \ |
127 | "Breakpoint \[0-9\]*, handler.* | |
128 | The program being debugged stopped while in a function called from GDB.*" \ | |
23b451cf | 129 | "p func1 () #2" |
78650829 | 130 | |
23b451cf | 131 | # ...verify the backtrace |
78650829 | 132 | |
23b451cf AC |
133 | gdb_test "backtrace" \ |
134 | "#0 handler.*#1 .signal handler called.*#2 func1.*#3 .function called from gdb.*#4.*main.*" \ | |
135 | "backtrace from handler when calling func1" | |
78650829 | 136 | |
23b451cf | 137 | # ...and continue (silently returning) |
78650829 | 138 | |
23b451cf | 139 | gdb_test "continue" "Continuing\\." |
78650829 | 140 | |
c906108c | 141 | # ...and then count should have been incremented |
78650829 | 142 | |
23b451cf | 143 | gdb_test "p count" "= 5" "p count #2" |
c906108c SS |
144 | |
145 | ||
78650829 AC |
146 | # Verify that "info signals" produces reasonable output. |
147 | ||
23b451cf AC |
148 | gdb_test "info signals" "SIGHUP.*SIGINT.*SIGQUIT.*SIGILL.*SIGTRAP.*SIGABRT.*SIGEMT.*SIGFPE.*SIGKILL.*SIGBUS.*SIGSEGV.*SIGSYS.*SIGPIPE.*SIGALRM.*SIGTERM.*SIGURG.*SIGSTOP.*SIGTSTP.*SIGCONT.*SIGCHLD.*SIGTTIN.*SIGTTOU.*SIGIO.*SIGXCPU.*SIGXFSZ.*SIGVTALRM.*SIGPROF.*SIGWINCH.*SIGLOST.*SIGUSR1.*SIGUSR2.*SIGPWR.*SIGPOLL.*SIGWIND.*SIGPHONE.*SIGWAITING.*SIGLWP.*SIGDANGER.*SIGGRANT.*SIGRETRACT.*SIGMSG.*SIGSOUND.*SIGSAK.*SIGPRIO.*SIG33.*SIG34.*SIG35.*SIG36.*SIG37.*SIG38.*SIG39.*SIG40.*SIG41.*SIG42.*SIG43.*SIG44.*SIG45.*SIG46.*SIG47.*SIG48.*SIG49.*SIG50.*SIG51.*SIG52.*SIG53.*SIG54.*SIG55.*SIG56.*SIG57.*SIG58.*SIG59.*SIG60.*SIG61.*SIG62.*SIG63.*Use the \"handle\" command to change these tables.*" \ |
149 | "info signals" | |
c906108c | 150 | |
78650829 AC |
151 | # Verify that "info signal" correctly handles an argument, be it a |
152 | # symbolic signal name, or an integer ID. | |
153 | ||
23b451cf AC |
154 | gdb_test "info signal SIGTRAP" \ |
155 | "SIGTRAP\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*No\[ \t\]*Trace/breakpoint trap.*" \ | |
156 | "info signal SIGTRAP" | |
c906108c | 157 | |
23b451cf AC |
158 | gdb_test "info signal 5" \ |
159 | "SIGTRAP\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*No\[ \t\]*Trace/breakpoint trap.*" \ | |
160 | "info signal 5" | |
c906108c | 161 | |
78650829 AC |
162 | # Verify that "handle" with illegal arguments is gracefully, um, |
163 | # handled. | |
164 | ||
23b451cf AC |
165 | gdb_test "handle" \ |
166 | "Argument required .signal to handle.*" \ | |
167 | "handle without arguments" | |
c906108c | 168 | |
23b451cf AC |
169 | gdb_test "handle SIGFOO" \ |
170 | "Unrecognized or ambiguous flag word: \"SIGFOO\".*" \ | |
171 | "handle with bogus SIG" | |
c906108c | 172 | |
23b451cf AC |
173 | gdb_test "handle SIGHUP frump" \ |
174 | "Unrecognized or ambiguous flag word: \"frump\".*" \ | |
175 | "handle SIG with bogus action" | |
c906108c | 176 | |
78650829 AC |
177 | # Verify that "handle" can take multiple actions per SIG, and that |
178 | # in the case of conflicting actions, that the rightmost action | |
179 | # "wins". | |
180 | ||
23b451cf AC |
181 | gdb_test "handle SIGHUP print noprint" \ |
182 | "SIGHUP\[ \t\]*No\[ \t\]*No\[ \t\]*Yes\[ \t\]*Hangup.*" \ | |
183 | "handle SIG with multiple conflicting actions" | |
c906108c | 184 | |
78650829 AC |
185 | # Exercise all the various actions. (We don't care what the |
186 | # outcome is, this is just to ensure that they all can be parsed.) | |
187 | ||
23b451cf AC |
188 | gdb_test "handle SIGHUP print noprint stop nostop ignore noignore pass nopass" \ |
189 | "Signal.*" \ | |
190 | "handle SIG parses all legal actions" | |
c906108c | 191 | |
78650829 AC |
192 | # Verify that we can "handle" multiple signals at once, |
193 | # interspersed with actions. | |
194 | ||
23b451cf AC |
195 | gdb_test "handle SIG63 print SIGILL" \ |
196 | "SIGILL\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Illegal instruction.*SIG63\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Real-time event 63.*" \ | |
197 | "handle multiple SIGs" | |
c906108c | 198 | |
78650829 AC |
199 | # Verify that "handle" can take a numeric argument for the signal |
200 | # ID, rather than a symbolic name. (This may not be portable; | |
201 | # works for HP-UX.) | |
202 | ||
203 | # Also note that this testpoint overrides SIGTRAP, which on HP-UX | |
204 | # at least, is used to implement single-steps and breakpoints. | |
205 | # Don't expect to run the inferior after this! | |
206 | ||
23b451cf AC |
207 | set test "override SIGTRAP" |
208 | gdb_test_multiple "handle 5 nopass" "$test" { | |
209 | -re "SIGTRAP is used by the debugger.*Are you sure you want to change it.*y or n.*" { | |
210 | gdb_test "y" \ | |
211 | "SIGTRAP\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*No\[ \t\]*Trace/breakpoint trap.*" \ | |
212 | "$test" | |
78650829 | 213 | } |
c906108c SS |
214 | } |
215 | ||
78650829 AC |
216 | # GDB doesn't seem to allow numeric signal IDs larger than 15. Verify |
217 | # that restriction. ??rehrauer: Not sure if this is a feature or a | |
218 | # bug, actually. Why is the range 1-15? | |
219 | ||
23b451cf AC |
220 | gdb_test "handle 58" \ |
221 | "Only signals 1-15 are valid as numeric signals.*Use \"info signals\" for a list of symbolic signals.*" \ | |
222 | "invalid signal number rejected" | |
c906108c | 223 | |
78650829 AC |
224 | # Verify that we can accept a signal ID range (number-number). |
225 | # ??rehrauer: This feature isn't documented on the quick-reference | |
226 | # card. | |
227 | ||
23b451cf AC |
228 | gdb_test "handle 13-15" \ |
229 | "SIGPIPE.*SIGALRM.*SIGTERM.*" \ | |
230 | "handle multiple SIGs via integer range" | |
c906108c | 231 | |
78650829 AC |
232 | # Bizarrely enough, GDB also allows you to reverse the range stat, |
233 | # stop IDs. E.g., "3-1" and "1-3" mean the same thing. Probably | |
234 | # this isn't documented, but the code anticipates it, so we'd best | |
235 | # test it... | |
236 | ||
23b451cf AC |
237 | gdb_test "handle 15-13" \ |
238 | "SIGPIPE.*SIGALRM.*SIGTERM.*" \ | |
239 | "handle multiple SIGs via reverse integer range" | |
c906108c | 240 | |
78650829 AC |
241 | # SIGINT is used by the debugger as well. Verify that we can |
242 | # change our minds about changing it. | |
243 | ||
23b451cf AC |
244 | set test "override SIGINT" |
245 | gdb_test_multiple "handle SIGINT nopass" "$test" { | |
246 | -re "SIGINT is used by the debugger.*Are you sure you want to change it.*y or n.*" { | |
247 | gdb_test_multiple "n" "$test" { | |
248 | -re "Not confirmed, unchanged.*Signal.*$gdb_prompt $" { | |
249 | # "Signal ..." should not be in the output. | |
250 | kfail gdb/1707 "$test" | |
78650829 | 251 | } |
23b451cf AC |
252 | -re "Not confirmed, unchanged.*$gdb_prompt $" { |
253 | pass "$test" | |
78650829 AC |
254 | } |
255 | } | |
256 | } | |
c906108c SS |
257 | } |
258 | ||
78650829 AC |
259 | # Verify that GDB responds gracefully to the "signal" command with |
260 | # a missing argument. | |
261 | ||
23b451cf AC |
262 | gdb_test "signal" \ |
263 | "Argument required .signal number..*" \ | |
264 | "signal without arguments disallowed" | |
78650829 AC |
265 | |
266 | # Verify that we can successfully send a signal other than 0 to | |
267 | # the inferior. (This probably causes the inferior to run away. | |
268 | # Be prepared to rerun to main for further testing.) | |
c906108c | 269 | |
e05b62ac AC |
270 | gdb_test "signal SIGUSR1" "Breakpoint.*handler.*" |
271 | gdb_test "bt" \ | |
272 | "#0 handler .*#1 .signal handler called.*\#2 .*main.*" \ | |
273 | "backtrace for SIGUSR1" | |
c906108c SS |
274 | } |
275 | ||
276 | return 0 |