aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2023-03-06 16:55:22 -0800
committerJohn Baldwin <jhb@FreeBSD.org>2023-03-06 16:55:22 -0800
commitcf622c39abfa8fe1df1a019020a529a81572ca7b (patch)
treeeef1e37b0113cb994ffb77d20f07f590e830ecb5
parent3c75f00adcea9d57c0d92669249dd884e49c4c3b (diff)
downloadbinutils-cf622c39abfa8fe1df1a019020a529a81572ca7b.zip
binutils-cf622c39abfa8fe1df1a019020a529a81572ca7b.tar.gz
binutils-cf622c39abfa8fe1df1a019020a529a81572ca7b.tar.bz2
gdb.base/catch-syscall.exp: Remove some Linux-only assumptions.
- 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.
-rw-r--r--gdb/testsuite/gdb.base/catch-syscall.c4
-rw-r--r--gdb/testsuite/gdb.base/catch-syscall.exp48
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 8c252a0..070c012 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 22181bc..4a9302f 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
}