Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 1997-2016 Free Software Foundation, Inc. |
fbbe92c5 SDJ |
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 | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
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. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | ||
17 | # This program tests the 'catch syscall' functionality. | |
18 | # | |
19 | # It was written by Sergio Durigan Junior <sergiodj@linux.vnet.ibm.com> | |
20 | # on September/2008. | |
21 | ||
f76495c8 | 22 | standard_testfile |
fbbe92c5 | 23 | |
2e0d821f SDJ |
24 | if { [prepare_for_testing ${testfile}.exp $testfile ${testfile}.c] } { |
25 | untested catch-syscall.exp | |
26 | return -1 | |
27 | } | |
28 | ||
a31d2f06 YQ |
29 | # Check target supports catch syscall or not. |
30 | clean_restart $binfile | |
31 | if ![runto_main] then { | |
bc6c7af4 | 32 | fail "can't run to main" |
a31d2f06 YQ |
33 | return |
34 | } | |
35 | ||
36 | set test "catch syscall" | |
37 | gdb_test_multiple $test $test { | |
38 | -re "The feature \'catch syscall\' is not supported.*\r\n$gdb_prompt $" { | |
39 | unsupported "catch syscall isn't supported" | |
40 | return -1 | |
41 | } | |
42 | -re ".*$gdb_prompt $" { | |
43 | pass $test | |
44 | } | |
45 | } | |
46 | ||
47 | set test "check catch syscall" | |
48 | gdb_test_multiple "continue" $test { | |
49 | -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" { | |
50 | unsupported "catch syscall isn't supported" | |
51 | return -1 | |
52 | } | |
53 | -re ".*Catchpoint.*$gdb_prompt $" { | |
54 | pass $test | |
55 | } | |
56 | } | |
57 | ||
f68f11b7 YQ |
58 | # All (but the last) syscalls from the example code. It is filled in |
59 | # proc setup_all_syscalls. | |
60 | set all_syscalls { } | |
fbbe92c5 | 61 | set all_syscalls_numbers { } |
2e0d821f | 62 | |
fbbe92c5 SDJ |
63 | # The last syscall (exit()) does not return, so |
64 | # we cannot expect the catchpoint to be triggered | |
65 | # twice. It is a special case. | |
66 | set last_syscall "exit_group" | |
2e0d821f | 67 | set last_syscall_number { } |
fbbe92c5 | 68 | |
bfd09d20 JS |
69 | set vfork_syscalls "(vfork|clone2?)" |
70 | ||
71 | set unknown_syscall_number { } | |
72 | ||
fbbe92c5 SDJ |
73 | # Internal procedure used to check if, after issuing a 'catch syscall' |
74 | # command (without arguments), the 'info breakpoints' command displays | |
75 | # that '"any syscall"' is to be caught. | |
76 | proc check_info_bp_any_syscall {} { | |
fbbe92c5 SDJ |
77 | # Verifying that the catchpoint appears in the 'info breakpoints' |
78 | # command, but with "<any syscall>". | |
79 | set thistest "catch syscall appears in 'info breakpoints'" | |
80 | gdb_test "info breakpoints" ".*catchpoint.*keep y.*syscall \"<any syscall>\".*" $thistest | |
81 | } | |
82 | ||
83 | # Internal procedure used to check if, after issuing a 'catch syscall X' | |
84 | # command (with arguments), the 'info breakpoints' command displays | |
85 | # that the syscall 'X' is to be caught. | |
86 | proc check_info_bp_specific_syscall { syscall } { | |
fbbe92c5 SDJ |
87 | set thistest "syscall(s) $syscall appears in 'info breakpoints'" |
88 | gdb_test "info breakpoints" ".*catchpoint.*keep y.*syscall(\[(\]s\[)\])? (.)?${syscall}(.)?.*" $thistest | |
89 | } | |
90 | ||
91 | # Internal procedure used to check if, after issuing a 'catch syscall X' | |
92 | # command (with many arguments), the 'info breakpoints' command displays | |
93 | # that the syscalls 'X' are to be caught. | |
94 | proc check_info_bp_many_syscalls { syscalls } { | |
fbbe92c5 SDJ |
95 | set filter_str "" |
96 | ||
97 | foreach name $syscalls { | |
98 | set filter_str "${filter_str}${name}, " | |
99 | } | |
100 | ||
101 | set filter_str [ string trimright $filter_str ", " ] | |
102 | ||
103 | set thistest "syscalls $filter_str appears in 'info breakpoints'" | |
104 | gdb_test "info breakpoints" ".*catchpoint.*keep y.*syscalls (.)?${filter_str}(.)?.*" $thistest | |
105 | } | |
106 | ||
bfd09d20 JS |
107 | # This procedure checks if there was a call to a syscall. The optional |
108 | # pattern can match syscalls that vary in implementation, like vfork. | |
109 | proc check_call_to_syscall { syscall { pattern "" } } { | |
2e0d821f | 110 | global decimal |
fbbe92c5 | 111 | |
bfd09d20 JS |
112 | if { $pattern eq "" } { |
113 | set pattern "${syscall}" | |
114 | } | |
115 | ||
fbbe92c5 | 116 | set thistest "program has called $syscall" |
bfd09d20 | 117 | gdb_test "continue" "Catchpoint $decimal \\(call to syscall .?${pattern}.?\\).*" $thistest |
fbbe92c5 SDJ |
118 | } |
119 | ||
bfd09d20 JS |
120 | # This procedure checks if the syscall returned. The optional pattern |
121 | # can match syscalls that vary in implementation, like vfork. | |
122 | proc check_return_from_syscall { syscall { pattern "" } } { | |
2e0d821f | 123 | global decimal |
fbbe92c5 | 124 | |
bfd09d20 JS |
125 | if { $pattern eq "" } { |
126 | set pattern "${syscall}" | |
127 | } | |
128 | ||
fbbe92c5 | 129 | set thistest "syscall $syscall has returned" |
bfd09d20 | 130 | gdb_test "continue" "Catchpoint $decimal \\(returned from syscall ${pattern}\\).*" $thistest |
fbbe92c5 SDJ |
131 | } |
132 | ||
133 | # Internal procedure that performs two 'continue' commands and checks if | |
bfd09d20 JS |
134 | # a syscall call AND return occur. The optional pattern can match |
135 | # syscalls that vary in implementation, like vfork. | |
136 | proc check_continue { syscall { pattern "" } } { | |
fbbe92c5 SDJ |
137 | # Testing if the 'continue' stops at the |
138 | # specified syscall_name. If it does, then it should | |
139 | # first print that the infeior has called the syscall, | |
140 | # and after print that the syscall has returned. | |
141 | ||
e03f9645 | 142 | # Testing if the inferior has called the syscall. |
bfd09d20 | 143 | check_call_to_syscall $syscall $pattern |
fbbe92c5 | 144 | # And now, that the syscall has returned. |
bfd09d20 | 145 | check_return_from_syscall $syscall $pattern |
fbbe92c5 SDJ |
146 | } |
147 | ||
148 | # Inserts a syscall catchpoint with an argument. | |
149 | proc insert_catch_syscall_with_arg { syscall } { | |
2e0d821f | 150 | global decimal |
fbbe92c5 SDJ |
151 | |
152 | # Trying to set the catchpoint | |
153 | set thistest "catch syscall with arguments ($syscall)" | |
2e0d821f | 154 | gdb_test "catch syscall $syscall" "Catchpoint $decimal \\(syscall \'?${syscall}\'?( \[${decimal}\])?\\)" $thistest |
fbbe92c5 SDJ |
155 | |
156 | check_info_bp_specific_syscall $syscall | |
157 | } | |
158 | ||
159 | # Inserts a syscall catchpoint with many arguments. | |
160 | proc insert_catch_syscall_with_many_args { syscalls numbers } { | |
2e0d821f SDJ |
161 | global decimal |
162 | ||
fbbe92c5 SDJ |
163 | set catch [ join $syscalls " " ] |
164 | set filter_str "" | |
165 | ||
166 | foreach name $syscalls number $numbers { | |
2e0d821f | 167 | set filter_str "${filter_str}'${name}' \\\[${number}\\\] " |
fbbe92c5 SDJ |
168 | } |
169 | ||
170 | set filter_str [ string trimright $filter_str " " ] | |
171 | ||
172 | # Trying to set the catchpoint | |
173 | set thistest "catch syscall with arguments ($filter_str)" | |
2e0d821f | 174 | gdb_test "catch syscall $catch" "Catchpoint $decimal \\(syscalls ${filter_str}\\).*" $thistest |
fbbe92c5 SDJ |
175 | |
176 | check_info_bp_many_syscalls $syscalls | |
177 | } | |
178 | ||
179 | proc check_for_program_end {} { | |
fbbe92c5 SDJ |
180 | # Deleting the catchpoints |
181 | delete_breakpoints | |
182 | ||
fda326dd | 183 | gdb_continue_to_end |
fbbe92c5 SDJ |
184 | } |
185 | ||
186 | proc test_catch_syscall_without_args {} { | |
bfd09d20 | 187 | global all_syscalls last_syscall vfork_syscalls unknown_syscall_number decimal |
fbbe92c5 | 188 | |
eb4ca471 PA |
189 | with_test_prefix "without arguments" { |
190 | # Trying to set the syscall. | |
2e0d821f | 191 | gdb_test "catch syscall" "Catchpoint $decimal \\(any syscall\\)" |
fbbe92c5 | 192 | |
eb4ca471 | 193 | check_info_bp_any_syscall |
fbbe92c5 | 194 | |
eb4ca471 PA |
195 | # We have to check every syscall. |
196 | foreach name $all_syscalls { | |
197 | check_continue $name | |
198 | } | |
fbbe92c5 | 199 | |
bfd09d20 JS |
200 | check_continue "vfork" $vfork_syscalls |
201 | ||
202 | with_test_prefix "ENOSYS" { | |
203 | check_continue $unknown_syscall_number | |
204 | } | |
205 | ||
eb4ca471 PA |
206 | # At last but not least, we check if the inferior has called |
207 | # the last (exit) syscall. | |
208 | check_call_to_syscall $last_syscall | |
fbbe92c5 | 209 | |
eb4ca471 PA |
210 | # Now let's see if the inferior correctly finishes. |
211 | check_for_program_end | |
212 | } | |
fbbe92c5 SDJ |
213 | } |
214 | ||
215 | proc test_catch_syscall_with_args {} { | |
eb4ca471 | 216 | with_test_prefix "with arguments" { |
eb4ca471 PA |
217 | set syscall_name "close" |
218 | insert_catch_syscall_with_arg $syscall_name | |
fbbe92c5 | 219 | |
eb4ca471 PA |
220 | # Can we continue until we catch the syscall? |
221 | check_continue $syscall_name | |
fbbe92c5 | 222 | |
eb4ca471 PA |
223 | # Now let's see if the inferior correctly finishes. |
224 | check_for_program_end | |
225 | } | |
fbbe92c5 SDJ |
226 | } |
227 | ||
228 | proc test_catch_syscall_with_many_args {} { | |
eb4ca471 | 229 | with_test_prefix "with many arguments" { |
2e0d821f | 230 | global all_syscalls all_syscalls_numbers |
fbbe92c5 | 231 | |
eb4ca471 | 232 | insert_catch_syscall_with_many_args $all_syscalls $all_syscalls_numbers |
fbbe92c5 | 233 | |
eb4ca471 PA |
234 | # Can we continue until we catch the syscalls? |
235 | foreach name $all_syscalls { | |
236 | check_continue $name | |
237 | } | |
fbbe92c5 | 238 | |
eb4ca471 PA |
239 | # Now let's see if the inferior correctly finishes. |
240 | check_for_program_end | |
241 | } | |
fbbe92c5 SDJ |
242 | } |
243 | ||
244 | proc test_catch_syscall_with_wrong_args {} { | |
eb4ca471 | 245 | with_test_prefix "wrong args" { |
eb4ca471 PA |
246 | # mlock is not called from the source |
247 | set syscall_name "mlock" | |
248 | insert_catch_syscall_with_arg $syscall_name | |
249 | ||
250 | # Now, we must verify if the program stops with a continue. | |
251 | # If it doesn't, everything is right (since we don't have | |
252 | # a syscall named "mlock" in it). Otherwise, this is a failure. | |
253 | set thistest "catch syscall with unused syscall ($syscall_name)" | |
254 | gdb_continue_to_end $thistest | |
255 | } | |
fbbe92c5 SDJ |
256 | } |
257 | ||
258 | proc test_catch_syscall_restarting_inferior {} { | |
eb4ca471 | 259 | with_test_prefix "restarting inferior" { |
eb4ca471 | 260 | set syscall_name "chroot" |
fbbe92c5 | 261 | |
eb4ca471 PA |
262 | with_test_prefix "entry" { |
263 | insert_catch_syscall_with_arg $syscall_name | |
fbbe92c5 | 264 | |
eb4ca471 PA |
265 | # Let's first reach the entry of the syscall. |
266 | check_call_to_syscall $syscall_name | |
267 | } | |
fbbe92c5 | 268 | |
eb4ca471 PA |
269 | with_test_prefix "entry/return" { |
270 | # Now, restart the program. | |
271 | rerun_to_main | |
fbbe92c5 | 272 | |
eb4ca471 PA |
273 | # And check for entry/return. |
274 | check_continue $syscall_name | |
fbbe92c5 | 275 | |
eb4ca471 PA |
276 | # Can we finish? |
277 | check_for_program_end | |
278 | } | |
279 | } | |
fbbe92c5 SDJ |
280 | } |
281 | ||
bfd09d20 JS |
282 | proc test_catch_syscall_skipping_return {} { |
283 | with_test_prefix "skipping return" { | |
284 | with_test_prefix "entry" { | |
285 | set syscall_name "write" | |
286 | ||
287 | insert_catch_syscall_with_arg $syscall_name | |
288 | ||
289 | # Let's first reach the entry of the syscall. | |
290 | check_call_to_syscall $syscall_name | |
291 | ||
292 | # Now purposely skip the syscall return. | |
293 | delete_breakpoints | |
294 | gdb_test "stepi" ".*" "step over syscall return" | |
295 | } | |
296 | ||
297 | # With a naive entry/return toggle, gdb will still think | |
298 | # the target is due for a syscall return. | |
299 | ||
300 | with_test_prefix "entry/return" { | |
301 | set syscall_name "read" | |
302 | ||
303 | insert_catch_syscall_with_arg $syscall_name | |
304 | ||
305 | # Check for entry first, then return. | |
306 | check_continue $syscall_name | |
307 | ||
308 | # Can we finish? | |
309 | check_for_program_end | |
310 | } | |
311 | } | |
312 | } | |
313 | ||
314 | proc test_catch_syscall_mid_vfork {} { | |
315 | global gdb_prompt decimal vfork_syscalls | |
316 | ||
317 | with_test_prefix "mid-vfork" { | |
318 | # Verify that the system supports "catch vfork". | |
319 | gdb_test "catch vfork" "Catchpoint $decimal \\(vfork\\)" "insert first vfork catchpoint" | |
320 | gdb_test_multiple "continue" "continue to first vfork catchpoint" { | |
321 | -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" { | |
322 | unsupported "continue to first vfork catchpoint" | |
323 | return | |
324 | } | |
325 | -re ".*Catchpoint $decimal \\(vforked process $decimal\\).*$gdb_prompt $" { | |
326 | pass "continue to first vfork catchpoint" | |
327 | } | |
328 | } | |
329 | ||
330 | # Check that we now reach vfork return only. | |
331 | # (The actual syscall used varies by architecture.) | |
332 | gdb_test "catch syscall" "Catchpoint $decimal \\(any syscall\\)" | |
333 | check_return_from_syscall "vfork" $vfork_syscalls | |
334 | ||
335 | # Can we finish? | |
336 | check_for_program_end | |
337 | } | |
338 | } | |
339 | ||
82075af2 JS |
340 | proc test_catch_syscall_execve {} { |
341 | global gdb_prompt decimal | |
342 | ||
343 | with_test_prefix "execve" { | |
344 | ||
345 | # Tell the test program we want an execve. | |
346 | gdb_test_no_output "set do_execve = 1" | |
347 | ||
348 | # Check for entry/return across the execve, making sure that the | |
349 | # syscall_state isn't lost when turning into a new process. | |
350 | insert_catch_syscall_with_arg "execve" | |
351 | check_continue "execve" | |
352 | ||
353 | # Continue to main so extended-remote can read files as needed. | |
354 | # (Otherwise that "Reading" output confuses gdb_continue_to_end.) | |
355 | gdb_continue "main" | |
356 | ||
357 | # Now can we finish? | |
358 | check_for_program_end | |
359 | } | |
360 | } | |
361 | ||
bccd0dd2 | 362 | proc test_catch_syscall_fail_nodatadir {} { |
eb4ca471 | 363 | with_test_prefix "fail no datadir" { |
eb4ca471 PA |
364 | # Sanitizing. |
365 | delete_breakpoints | |
bccd0dd2 | 366 | |
eb4ca471 PA |
367 | # Make sure GDB doesn't load the syscalls xml from the system |
368 | # data directory. | |
8d551b02 DE |
369 | gdb_test "set data-directory /the/path/to/nowhere" \ |
370 | "Warning: /the/path/to/nowhere: .*" | |
fc30d5e0 | 371 | |
eb4ca471 PA |
372 | # Testing to see if we receive a warning when calling "catch |
373 | # syscall" without XML support (without datadir). | |
374 | set thistest "catch syscall displays a warning when there is no XML support" | |
375 | gdb_test "catch syscall" \ | |
376 | "warning: Could not load the syscall XML file.*warning: GDB will not be able to display syscall names nor to verify if.*any provided syscall numbers are valid.*Catchpoint .*(syscall).*" \ | |
377 | $thistest | |
bccd0dd2 | 378 | |
eb4ca471 PA |
379 | # Since the catchpoint was set, we must check if it's present |
380 | # in "info breakpoints" output. | |
381 | check_info_bp_any_syscall | |
bccd0dd2 | 382 | |
eb4ca471 PA |
383 | # Sanitizing. |
384 | delete_breakpoints | |
385 | } | |
bccd0dd2 SDJ |
386 | } |
387 | ||
e3487908 GKB |
388 | proc test_catch_syscall_group {} { |
389 | global decimal | |
390 | ||
391 | set sysnum "\\\[${decimal}\\\]" | |
392 | ||
393 | gdb_test "catch syscall g:process" \ | |
394 | "Catchpoint $decimal \\(syscalls (\'(clone|fork|execve|exit)\' $sysnum)+.*" \ | |
395 | "set catchpoint on a group of syscalls" | |
396 | ||
397 | gdb_test "catch syscall group:process read" \ | |
398 | "Catchpoint $decimal \\(syscalls (\'(clone|fork|execve|exit)\' $sysnum)+.*read.*\\)" \ | |
399 | "set catchpoints on a group of syscalls and on a single syscall" | |
400 | ||
401 | gdb_test "catch syscall group:" \ | |
402 | "Unknown syscall group ''\." \ | |
403 | "set catchpoints on an invalid group" | |
404 | ||
405 | gdb_test "catch syscall g:junk" \ | |
406 | "Unknown syscall group 'junk'\." \ | |
407 | "set catchpoints on an unknown group." | |
408 | ||
409 | gdb_test "complete catch syscall g:proc" \ | |
410 | "catch syscall g:process" \ | |
411 | "complete catch syscall group with 'g:' prefix" | |
412 | ||
413 | gdb_test "complete catch syscall group:proc" \ | |
414 | "catch syscall group:process" \ | |
415 | "complete catch syscall group with 'group:' prefix" | |
416 | ||
417 | gdb_test_sequence "complete catch syscall g" \ | |
418 | "complete catch syscall group suggests 'group:' prefix" { | |
419 | "group:descriptor" "group:file" "group:ipc" "group:memory" | |
420 | "group:network" "group:process" "group:signal" | |
421 | } | |
422 | } | |
423 | ||
fbbe92c5 | 424 | proc do_syscall_tests {} { |
aae1c79a DE |
425 | # NOTE: We don't have to point gdb at the correct data-directory. |
426 | # For the build tree that is handled by INTERNAL_GDBFLAGS. | |
fbbe92c5 SDJ |
427 | |
428 | # Verify that the 'catch syscall' help is available | |
429 | set thistest "help catch syscall" | |
430 | gdb_test "help catch syscall" "Catch system calls.*" $thistest | |
431 | ||
432 | # Try to set a catchpoint to a nonsense syscall | |
433 | set thistest "catch syscall to a nonsense syscall is prohibited" | |
434 | gdb_test "catch syscall nonsense_syscall" "Unknown syscall name .*" $thistest | |
435 | ||
b45627a0 TT |
436 | # Regression test for syscall completer bug. |
437 | gdb_test "complete catch syscall close chroo" \ | |
438 | "catch syscall close chroot" \ | |
439 | "complete catch syscall with multiple words" | |
440 | ||
fbbe92c5 SDJ |
441 | # Testing the 'catch syscall' command without arguments. |
442 | # This test should catch any syscalls. | |
443 | if [runto_main] then { test_catch_syscall_without_args } | |
444 | ||
445 | # Testing the 'catch syscall' command with arguments. | |
446 | # This test should only catch the specified syscall. | |
447 | if [runto_main] then { test_catch_syscall_with_args } | |
448 | ||
449 | # Testing the 'catch syscall' command with many arguments. | |
450 | # This test should catch $all_syscalls. | |
451 | if [runto_main] then { test_catch_syscall_with_many_args } | |
452 | ||
453 | # Testing the 'catch syscall' command with WRONG arguments. | |
454 | # This test should not trigger any catchpoints. | |
455 | if [runto_main] then { test_catch_syscall_with_wrong_args } | |
456 | ||
bfd09d20 | 457 | # Testing the 'catch syscall' command during a restart of |
fbbe92c5 SDJ |
458 | # the inferior. |
459 | if [runto_main] then { test_catch_syscall_restarting_inferior } | |
458c8db8 | 460 | |
bfd09d20 JS |
461 | # Testing the 'catch syscall' command toggling off past a |
462 | # syscall return, then resuming entry/return as normal. | |
463 | if [runto_main] then { test_catch_syscall_skipping_return } | |
464 | ||
465 | # Testing the 'catch syscall' command starting mid-vfork. | |
466 | if [runto_main] then { test_catch_syscall_mid_vfork } | |
467 | ||
82075af2 JS |
468 | # Testing that 'catch syscall' entry/return tracks across execve. |
469 | if [runto_main] then { test_catch_syscall_execve } | |
470 | ||
458c8db8 SDJ |
471 | # Testing if the 'catch syscall' command works when switching to |
472 | # different architectures on-the-fly (PR gdb/10737). | |
473 | if [runto_main] then { test_catch_syscall_multi_arch } | |
e3487908 GKB |
474 | |
475 | # Testing the 'catch' syscall command for a group of syscalls. | |
476 | if [runto_main] then { test_catch_syscall_group } | |
fbbe92c5 SDJ |
477 | } |
478 | ||
fbbe92c5 | 479 | proc test_catch_syscall_without_args_noxml {} { |
eb4ca471 PA |
480 | with_test_prefix "without args noxml" { |
481 | # We will need the syscall names even not using it because we | |
482 | # need to know know many syscalls are in the example file. | |
bfd09d20 | 483 | global decimal all_syscalls last_syscall_number unknown_syscall_number all_syscalls_numbers |
eb4ca471 PA |
484 | |
485 | delete_breakpoints | |
486 | ||
487 | gdb_test "catch syscall" "Catchpoint .*(syscall).*" | |
488 | ||
489 | # Now, we should be able to set a catchpoint, and GDB shall | |
490 | # not display the warning anymore. | |
2e0d821f | 491 | foreach name $all_syscalls number $all_syscalls_numbers { |
eb4ca471 | 492 | with_test_prefix "$name" { |
2e0d821f | 493 | check_continue $number |
eb4ca471 PA |
494 | } |
495 | } | |
496 | ||
bfd09d20 JS |
497 | check_continue "vfork" $decimal |
498 | ||
499 | with_test_prefix "ENOSYS" { | |
500 | check_continue $unknown_syscall_number | |
501 | } | |
502 | ||
eb4ca471 PA |
503 | # At last but not least, we check if the inferior has called |
504 | # the last (exit) syscall. | |
2e0d821f | 505 | check_call_to_syscall $last_syscall_number |
eb4ca471 PA |
506 | |
507 | delete_breakpoints | |
fbbe92c5 | 508 | } |
fbbe92c5 SDJ |
509 | } |
510 | ||
511 | proc test_catch_syscall_with_args_noxml {} { | |
eb4ca471 | 512 | with_test_prefix "with args noxml" { |
2e0d821f | 513 | global all_syscalls_numbers |
fbbe92c5 | 514 | |
eb4ca471 | 515 | delete_breakpoints |
fbbe92c5 | 516 | |
2e0d821f SDJ |
517 | # Inserting all syscalls numbers to be caught |
518 | foreach syscall_number $all_syscalls_numbers { | |
519 | insert_catch_syscall_with_arg $syscall_number | |
520 | } | |
fbbe92c5 | 521 | |
2e0d821f SDJ |
522 | # Checking that all syscalls are caught. |
523 | foreach syscall_number $all_syscalls_numbers { | |
524 | check_continue $syscall_number | |
525 | } | |
fbbe92c5 | 526 | |
eb4ca471 PA |
527 | delete_breakpoints |
528 | } | |
fbbe92c5 SDJ |
529 | } |
530 | ||
531 | proc test_catch_syscall_with_wrong_args_noxml {} { | |
eb4ca471 | 532 | with_test_prefix "with wrong args noxml" { |
eb4ca471 | 533 | delete_breakpoints |
fbbe92c5 | 534 | |
eb4ca471 PA |
535 | # Even without XML support, GDB should not accept unknown |
536 | # syscall names for the catchpoint. | |
537 | gdb_test "catch syscall nonsense_syscall" \ | |
538 | "Unknown syscall name .nonsense_syscall.*" | |
fbbe92c5 | 539 | |
eb4ca471 PA |
540 | delete_breakpoints |
541 | } | |
fbbe92c5 SDJ |
542 | } |
543 | ||
458c8db8 SDJ |
544 | proc test_catch_syscall_multi_arch {} { |
545 | global decimal binfile | |
546 | ||
547 | if { [istarget "i*86-*-*"] || [istarget "x86_64-*-*"] } { | |
548 | set arch1 "i386" | |
549 | set arch2 "i386:x86-64" | |
550 | set syscall1_name "exit" | |
551 | set syscall2_name "write" | |
552 | set syscall_number 1 | |
553 | } elseif { [istarget "powerpc-*-linux*"] \ | |
554 | || [istarget "powerpc64-*-linux*"] } { | |
555 | set arch1 "powerpc:common" | |
556 | set arch2 "powerpc:common64" | |
557 | set syscall1_name "openat" | |
558 | set syscall2_name "unlinkat" | |
559 | set syscall_number 286 | |
560 | } elseif { [istarget "sparc-*-linux*"] \ | |
561 | || [istarget "sparc64-*-linux*"] } { | |
562 | set arch1 "sparc" | |
563 | set arch2 "sparc:v9" | |
564 | set syscall1_name "setresuid32" | |
565 | set syscall2_name "setresuid" | |
566 | set syscall_number 108 | |
567 | } elseif { [istarget "mips*-linux*"] } { | |
568 | # MIPS does not use the same numbers for syscalls on 32 and 64 | |
569 | # bits. | |
570 | verbose "Not testing MIPS for multi-arch syscall support" | |
571 | return | |
572 | } elseif { [istarget "arm*-linux*"] } { | |
573 | # catch syscall supports only 32-bit ARM for now. | |
574 | verbose "Not testing ARM for multi-arch syscall support" | |
575 | return | |
f68f11b7 | 576 | } elseif { [istarget "aarch64*-linux*"] } { |
fbd8d50d YQ |
577 | set arch1 "aarch64" |
578 | set arch2 "arm" | |
579 | set syscall1_name "reboot" | |
580 | set syscall2_name "_newselect" | |
581 | set syscall_number 142 | |
458c8db8 | 582 | } elseif { [istarget "s390*-linux*"] } { |
6d74a497 | 583 | set arch1 "s390:31-bit" |
458c8db8 SDJ |
584 | set arch2 "s390:64-bit" |
585 | set syscall1_name "_newselect" | |
586 | set syscall2_name "select" | |
587 | set syscall_number 142 | |
588 | } | |
589 | ||
590 | with_test_prefix "multiple targets" { | |
591 | # We are not interested in loading any binary here, and in | |
592 | # some systems (PowerPC, for example), if we load a binary | |
593 | # there is no way to set other architecture. | |
594 | gdb_exit | |
595 | gdb_start | |
596 | ||
597 | gdb_test "set architecture $arch1" \ | |
598 | "The target architecture is assumed to be $arch1" \ | |
599 | "set arch to $arch1" | |
600 | ||
601 | gdb_test "catch syscall $syscall_number" \ | |
602 | "Catchpoint $decimal \\(syscall .${syscall1_name}. \\\[${syscall_number}\\\]\\)" \ | |
603 | "insert catch syscall on syscall $syscall_number -- $syscall1_name on $arch1" | |
604 | ||
605 | gdb_test "set architecture $arch2" \ | |
606 | "The target architecture is assumed to be $arch2" \ | |
607 | "set arch to $arch2" | |
608 | ||
609 | gdb_test "catch syscall $syscall_number" \ | |
610 | "Catchpoint $decimal \\(syscall .${syscall2_name}. \\\[${syscall_number}\\\]\\)" \ | |
611 | "insert catch syscall on syscall $syscall_number -- $syscall2_name on $arch2" | |
612 | ||
613 | clean_restart $binfile | |
614 | } | |
615 | } | |
616 | ||
fbbe92c5 | 617 | proc do_syscall_tests_without_xml {} { |
fc30d5e0 PA |
618 | # Make sure GDB doesn't load the syscalls xml from the system data |
619 | # directory. | |
8d551b02 DE |
620 | gdb_test "set data-directory /the/path/to/nowhere" \ |
621 | "Warning: /the/path/to/nowhere: .*" | |
fbbe92c5 | 622 | |
bccd0dd2 | 623 | # Let's test if we can catch syscalls without XML support. |
fbbe92c5 SDJ |
624 | # We should succeed, but GDB is not supposed to print syscall names. |
625 | if [runto_main] then { test_catch_syscall_without_args_noxml } | |
626 | ||
627 | # The only valid argument "catch syscall" should accept is the | |
628 | # syscall number, and not the name (since it can't translate a | |
629 | # name to a number). | |
fbbe92c5 SDJ |
630 | if [runto_main] then { test_catch_syscall_with_args_noxml } |
631 | ||
632 | # Now, we'll try to provide a syscall name (valid or not) to the command, | |
633 | # and expect it to fail. | |
634 | if [runto_main] then { test_catch_syscall_with_wrong_args_noxml } | |
635 | } | |
636 | ||
637 | # This procedure fills the vector "all_syscalls_numbers" with the proper | |
638 | # numbers for the used syscalls according to the architecture. | |
639 | proc fill_all_syscalls_numbers {} { | |
bfd09d20 | 640 | global all_syscalls_numbers last_syscall_number unknown_syscall_number all_syscalls |
4924df79 GKB |
641 | |
642 | foreach syscall $all_syscalls { | |
643 | lappend all_syscalls_numbers [get_integer_valueof "${syscall}_syscall" -1] | |
644 | } | |
fbbe92c5 | 645 | |
2e0d821f | 646 | set last_syscall_number [get_integer_valueof "exit_group_syscall" -1] |
bfd09d20 | 647 | set unknown_syscall_number [get_integer_valueof "unknown_syscall" -1] |
2e0d821f | 648 | } |
fbbe92c5 | 649 | |
f68f11b7 YQ |
650 | # Set up the vector all_syscalls. |
651 | ||
652 | proc setup_all_syscalls {} { | |
653 | global all_syscalls | |
654 | global gdb_prompt | |
655 | ||
656 | # They are ordered according to the file, so do not change this. | |
657 | lappend all_syscalls "close" | |
658 | lappend all_syscalls "chroot" | |
659 | ||
660 | # SYS_pipe doesn't exist on aarch64 kernel. | |
661 | set test "check SYS_pipe" | |
662 | gdb_test_multiple "p pipe_syscall" $test { | |
663 | -re " = .*$gdb_prompt $" { | |
664 | pass $test | |
665 | lappend all_syscalls "pipe" | |
666 | } | |
667 | -re "No symbol .*$gdb_prompt $" { | |
668 | pass $test | |
669 | # SYS_pipe isn't defined, use SYS_pipe2 instead. | |
670 | lappend all_syscalls "pipe2" | |
671 | } | |
672 | } | |
673 | ||
674 | lappend all_syscalls "write" | |
675 | lappend all_syscalls "read" | |
676 | } | |
677 | ||
678 | setup_all_syscalls | |
679 | ||
2e0d821f SDJ |
680 | # Fill all the syscalls numbers before starting anything. |
681 | fill_all_syscalls_numbers | |
fbbe92c5 SDJ |
682 | |
683 | # Execute the tests, using XML support | |
1e76a7e9 | 684 | gdb_exit |
2e0d821f SDJ |
685 | if { ![gdb_skip_xml_test] } { |
686 | clean_restart $binfile | |
bccd0dd2 SDJ |
687 | do_syscall_tests |
688 | ||
689 | # Now, we have to see if GDB displays a warning when we | |
690 | # don't set the data-directory but try to use catch syscall | |
691 | # anyway. For that, we must restart GDB first. | |
2e0d821f | 692 | clean_restart $binfile |
bccd0dd2 SDJ |
693 | test_catch_syscall_fail_nodatadir |
694 | } | |
fbbe92c5 SDJ |
695 | |
696 | # Restart gdb | |
2e0d821f | 697 | clean_restart $binfile |
fbbe92c5 SDJ |
698 | |
699 | # Execute the tests, without XML support. In this case, GDB will | |
700 | # only display syscall numbers, and not syscall names. | |
701 | do_syscall_tests_without_xml |