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