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