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