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