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