From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id D39273857B93 for ; Fri, 17 Feb 2023 20:38:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D39273857B93 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=FreeBSD.org Received: from gimli.baldwin.net (c-98-35-126-114.hsd1.ca.comcast.net [98.35.126.114]) by mail.baldwin.cx (Postfix) with ESMTPSA id 362351A84C5E for ; Fri, 17 Feb 2023 15:38:25 -0500 (EST) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH 2/5] gdb.base/catch-syscall.exp: Remove some Linux-only assumptions. Date: Fri, 17 Feb 2023 12:38:15 -0800 Message-Id: <20230217203818.11287-3-jhb@FreeBSD.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230217203818.11287-1-jhb@FreeBSD.org> References: <20230217203818.11287-1-jhb@FreeBSD.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Fri, 17 Feb 2023 15:38:25 -0500 (EST) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_STATUS,KHOP_HELO_FCRDNS,SPF_HELO_PASS,SPF_SOFTFAIL,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: - Some OS's use a different syscall for exit(). For example, the BSD's use SYS_exit rather than SYS_exit_group. Update the C source file and the expect script to support SYS_exit as an alternative to SYS_exit_group. - The cross-arch syscall number tests are all Linux-specific with hardcoded syscall numbers specific to Linux kernels. Skip these tests on non-Linux systems. FreeBSD kernels for example use the same system call numbers on all platforms, so the test is also not relevant on FreeBSD. --- gdb/testsuite/gdb.base/catch-syscall.c | 4 ++ gdb/testsuite/gdb.base/catch-syscall.exp | 48 ++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/gdb/testsuite/gdb.base/catch-syscall.c b/gdb/testsuite/gdb.base/catch-syscall.c index 8c252a06b20..070c0122e45 100644 --- a/gdb/testsuite/gdb.base/catch-syscall.c +++ b/gdb/testsuite/gdb.base/catch-syscall.c @@ -38,7 +38,11 @@ int unknown_syscall = 0x0f07ff; #else int unknown_syscall = 123456789; #endif +#ifdef SYS_exit_group int exit_group_syscall = SYS_exit_group; +#else +int exit_syscall = SYS_exit; +#endif /* Set by the test when it wants execve. */ int do_execve = 0; diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp index 22181bc884e..4a9302fb9b7 100644 --- a/gdb/testsuite/gdb.base/catch-syscall.exp +++ b/gdb/testsuite/gdb.base/catch-syscall.exp @@ -63,7 +63,7 @@ set all_syscalls_numbers { } # The last syscall (exit()) does not return, so # we cannot expect the catchpoint to be triggered # twice. It is a special case. -set last_syscall "exit_group" +set last_syscall { } set last_syscall_number { } set vfork_syscalls "(vfork|clone2?)" @@ -494,7 +494,7 @@ proc do_syscall_tests {} { # Testing if the 'catch syscall' command works when switching to # different architectures on-the-fly (PR gdb/10737). - if {[runto_main]} { test_catch_syscall_multi_arch } + if {[istarget *-linux*] && [runto_main]} { test_catch_syscall_multi_arch } # Testing the 'catch' syscall command for a group of syscalls. if {[runto_main]} { test_catch_syscall_group } @@ -677,13 +677,12 @@ proc do_syscall_tests_without_xml {} { # This procedure fills the vector "all_syscalls_numbers" with the proper # numbers for the used syscalls according to the architecture. proc fill_all_syscalls_numbers {} { - global all_syscalls_numbers last_syscall_number unknown_syscall_number all_syscalls + global all_syscalls_numbers unknown_syscall_number all_syscalls foreach syscall $all_syscalls { lappend all_syscalls_numbers [get_integer_valueof "${syscall}_syscall" -1] } - set last_syscall_number [get_integer_valueof "exit_group_syscall" -1] set unknown_syscall_number [get_integer_valueof "unknown_syscall" -1] } @@ -693,6 +692,7 @@ proc setup_all_syscalls {} { global all_syscalls global gdb_prompt global decimal + global last_syscall last_syscall_number # They are ordered according to the file, so do not change this. lappend all_syscalls "close" @@ -769,6 +769,46 @@ proc setup_all_syscalls {} { lappend all_syscalls "write" lappend all_syscalls "read" + # Determine the right syscall to use for exit() + set test "check SYS_exit" + set have_SYS_exit 0 + set SYS_exit -1 + gdb_test_multiple "p exit_syscall" $test { + -re -wrap " = ($decimal)" { + pass $test + set have_SYS_exit 1 + set SYS_exit $expect_out(1,string) + } + -re -wrap "No symbol .*" { + pass $test + } + } + + set test "check SYS_exit_group" + set have_SYS_exit_group 0 + set SYS_exit_group -1 + gdb_test_multiple "p exit_group_syscall" $test { + -re -wrap " = ($decimal)" { + pass $test + set have_SYS_exit_group 1 + set SYS_exit_group $expect_out(1,string) + } + -re -wrap "No symbol .*" { + pass $test + } + } + + if { $have_SYS_exit == 0 && $have_SYS_exit_group == 0 } { + return 0 + } + + if { $have_SYS_exit } { + set last_syscall "exit" + set last_syscall_number $SYS_exit + } else { + set last_syscall "exit_group" + set last_syscall_number $SYS_exit_group + } return 1 } -- 2.38.1