public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
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	[thread overview]
Message-ID: <20230217203818.11287-3-jhb@FreeBSD.org> (raw)
In-Reply-To: <20230217203818.11287-1-jhb@FreeBSD.org>

- 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


  parent reply	other threads:[~2023-02-17 20:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-17 20:38 [PATCH 0/5] Various test suite fixes (mostly thread related) John Baldwin
2023-02-17 20:38 ` [PATCH 1/5] gdb.threads/multi-create: Double the existing stack size John Baldwin
2023-02-17 20:38 ` John Baldwin [this message]
2023-02-17 20:38 ` [PATCH 3/5] gdb.threads/execl.c: Ensure all threads are started before execl John Baldwin
2023-02-17 20:38 ` [PATCH 4/5] gdb.threads/next-bp-other-thread.c: Ensure child thread is started John Baldwin
2023-02-17 20:38 ` [PATCH 5/5] gdb tests: Allow for "LWP" in thread IDs from info threads John Baldwin
2023-03-03 17:59 ` [PING] [PATCH 0/5] Various test suite fixes (mostly thread related) John Baldwin
2023-03-03 19:16 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230217203818.11287-3-jhb@FreeBSD.org \
    --to=jhb@freebsd.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).