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