public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH, v2][gdb/testsuite] Handle pipe2 syscall in gdb.base/catch-syscall.exp
Date: Thu, 5 May 2022 13:47:05 +0200	[thread overview]
Message-ID: <d0415e7a-d90a-705f-719d-2c9dc657750c@suse.de> (raw)
In-Reply-To: <20220503145732.GA26729@delia.home>

[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]

On 5/3/22 16:57, Tom de Vries wrote:
> Hi,
> 
> When running test-case gdb.reverse/pipe-reverse.exp on openSUSE Tumbleweed,
> I run into:
> ...
> (gdb) continue^M
> Continuing.^M
> ^M
> Catchpoint 2 (returned from syscall pipe2), in pipe () from /lib64/libc.so.6^M
> (gdb) FAIL: gdb.base/catch-syscall.exp: without arguments: \
>    syscall pipe has returned
> ...
> 
> The current glibc on Tumbleweed is 2.35, which contains commit
> "linux: Implement pipe in terms of __NR_pipe2", and consequently syscall pipe2
> is used in stead of syscall pipe.
> 
> Fix this by detecting whether syscall pipe or pipe2 is used before running the tests.
> 
> Tested on x86_64-linux, specifically on:
> - openSUSE Tumbleweed (with glibc 2.35), and
> - openSUSE Leap 15.3 (with glibc 2.31).
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29056
> 
> Any comments?
> 

I'm submitting a v2.  I found out that with target board unix/-m32, 
pipe2 is not recognized as syscall name (which I'll fix in a follow-up 
patch), so I made the test robust against this, by using the syscall 
number instead.

Thanks,
- Tom


[-- Attachment #2: 0008-gdb-testsuite-Handle-pipe2-syscall-in-gdb.base-catch-syscall.exp.patch --]
[-- Type: text/x-patch, Size: 5938 bytes --]

[gdb/testsuite] Handle pipe2 syscall in gdb.base/catch-syscall.exp

When running test-case gdb.reverse/pipe-reverse.exp on openSUSE Tumbleweed,
I run into:
...
(gdb) continue^M
Continuing.^M
^M
Catchpoint 2 (returned from syscall pipe2), in pipe () from /lib64/libc.so.6^M
(gdb) FAIL: gdb.base/catch-syscall.exp: without arguments: \
  syscall pipe has returned
...

The current glibc on Tumbleweed is 2.35, which contains commit
"linux: Implement pipe in terms of __NR_pipe2", and consequently syscall pipe2
is used instead of syscall pipe.

Fix this by detecting whether syscall pipe or pipe2 is used before running the tests.

Tested on x86_64-linux, specifically on:
- openSUSE Tumbleweed (with glibc 2.35), and
- openSUSE Leap 15.3 (with glibc 2.31).

On openSUSE Tumbleweed + target board unix/-m32, this exposes:
...
(gdb) catch syscall pipe2^M
Unknown syscall name 'pipe2'.^M
...
so make the test robust against this by using the syscall number instead,
while still noting that the syscall name pipe2 is not recognized:
...
FAIL: gdb.base/catch-syscall.exp: determine pipe syscall: catch syscall pipe2
...
which will be fixed in a folllow-up patch.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29056

---
 gdb/testsuite/gdb.base/catch-syscall.c   |   3 +-
 gdb/testsuite/gdb.base/catch-syscall.exp | 100 ++++++++++++++++++++++++++++---
 2 files changed, 93 insertions(+), 10 deletions(-)

diff --git a/gdb/testsuite/gdb.base/catch-syscall.c b/gdb/testsuite/gdb.base/catch-syscall.c
index 0ab96318d3e..8c252a06b20 100644
--- a/gdb/testsuite/gdb.base/catch-syscall.c
+++ b/gdb/testsuite/gdb.base/catch-syscall.c
@@ -24,7 +24,8 @@ int chroot_syscall = SYS_chroot;
 int read_syscall = SYS_read;
 #ifdef SYS_pipe
 int pipe_syscall = SYS_pipe;
-#else
+#endif
+#ifdef SYS_pipe2
 int pipe2_syscall = SYS_pipe2;
 #endif
 int write_syscall = SYS_write;
diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp
index a5dfd02411b..cc76a2cf61d 100644
--- a/gdb/testsuite/gdb.base/catch-syscall.exp
+++ b/gdb/testsuite/gdb.base/catch-syscall.exp
@@ -185,7 +185,11 @@ proc insert_catch_syscall_with_many_args { syscalls numbers } {
     set filter_str ""
 
     foreach name $syscalls number $numbers {
-      set filter_str "${filter_str}'${name}' \\\[${number}\\\] "
+	if { [string is integer $name] } {
+	    append filter_str "${name} "
+	} else {
+	    append filter_str "'${name}' \\\[${number}\\\] "
+	}
     }
 
     set filter_str [ string trimright $filter_str " " ]
@@ -662,42 +666,120 @@ proc fill_all_syscalls_numbers {} {
     global all_syscalls_numbers last_syscall_number unknown_syscall_number all_syscalls
 
     foreach syscall $all_syscalls {
-	lappend all_syscalls_numbers [get_integer_valueof "${syscall}_syscall" -1]
+	if { [string is integer $syscall] } {
+	    lappend all_syscalls_numbers $syscall
+	} else {
+	    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]
 }
 
-# Set up the vector all_syscalls.
+# Catch syscall with NAME, or if gdb doesn't support that (yet), try NR
+# instead.
+
+proc catch_syscall_name_or_nr { name nr } {
+    global decimal
+
+    gdb_test_multiple "catch syscall $name" "" {
+	-re -wrap "Catchpoint $decimal \\(syscall '$name' \\\[$nr\\\]\\)" {
+	    pass $gdb_test_name
+	}
+	-re -wrap "Unknown syscall name '$name'\." {
+	    fail $gdb_test_name
+	    gdb_test "catch syscall $nr" "Catchpoint $decimal \\(syscall $nr\\)"
+	}
+    }
+}
+
+# Set up the vector all_syscalls.  Returns 1 upon success, 0 upon failure.
 
 proc setup_all_syscalls {} {
     global all_syscalls
     global gdb_prompt
+    global decimal
 
     # They are ordered according to the file, so do not change this.
     lappend all_syscalls "close"
     lappend all_syscalls "chroot"
 
+    if { ![runto_main] } {
+	return 0
+    }
+
     # SYS_pipe doesn't exist on aarch64 kernel.
     set test "check SYS_pipe"
+    set have_SYS_pipe 0
     gdb_test_multiple "p pipe_syscall" $test {
-	-re " = .*$gdb_prompt $" {
+	-re -wrap " = ($decimal)" {
+	    pass $test
+	    set have_SYS_pipe 1
+	    set SYS_pipe $expect_out(1,string)
+	}
+	-re -wrap "No symbol .*" {
+	    pass $test
+	}
+    }
+
+    set test "check SYS_pipe2"
+    set have_SYS_pipe2 0
+    gdb_test_multiple "p pipe2_syscall" $test {
+	-re -wrap " = ($decimal)" {
 	    pass $test
-	    lappend all_syscalls "pipe"
+	    set have_SYS_pipe2 1
+	    set SYS_pipe2 $expect_out(1,string)
 	}
-	-re "No symbol .*$gdb_prompt $" {
+	-re -wrap "No symbol .*" {
 	    pass $test
-	    # SYS_pipe isn't defined, use SYS_pipe2 instead.
-	    lappend all_syscalls "pipe2"
+	}
+    }
+
+    if { $have_SYS_pipe == 0 && $have_SYS_pipe2 == 0 } {
+	return 0
+    }
+
+    with_test_prefix "determine pipe syscall" {
+	set line [gdb_get_line_number "pipe (fd)"]
+	gdb_test "break $line"
+	gdb_continue_to_breakpoint "before pipe call"
+	if { $have_SYS_pipe } {
+	    catch_syscall_name_or_nr pipe $SYS_pipe
+	}
+	if { $have_SYS_pipe2 } {
+	    catch_syscall_name_or_nr pipe2 $SYS_pipe2
+	}
+	set ok 0
+	gdb_test_multiple "continue" "" {
+	    -re -wrap "Catchpoint $decimal \\(call to syscall (pipe|$SYS_pipe)\\).*" {
+		lappend all_syscalls $expect_out(1,string)
+		pass $gdb_test_name
+		set ok 1
+	    }
+	    -re -wrap "Catchpoint $decimal \\(call to syscall (pipe2|$SYS_pipe2)\\).*" {
+		lappend all_syscalls $expect_out(1,string)
+		pass $gdb_test_name
+		set ok 1
+	    }
+	    -re -wrap "" {
+		fail $gdb_test_name
+	    }
+	}
+	if { ! $ok } {
+	    return 0
 	}
     }
 
     lappend all_syscalls "write"
     lappend all_syscalls "read"
+
+    return 1
 }
 
-setup_all_syscalls
+if { ![setup_all_syscalls] } {
+    return -1
+}
 
 # Fill all the syscalls numbers before starting anything.
 fill_all_syscalls_numbers

  reply	other threads:[~2022-05-05 11:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-03 14:57 [PATCH][gdb/testsuite] " Tom de Vries
2022-05-05 11:47 ` Tom de Vries [this message]
2022-05-05 11:49   ` [PATCH][gdb/tdep] Support catch syscall pipe2 for i386 Tom de Vries
2022-05-05 13:20     ` Simon Marchi
2022-05-09 10:26       ` [PATCH][gdb] Add gdb/syscalls/Makefile Tom de Vries
2022-05-09 14:41         ` Simon Marchi
2022-05-09 14:46           ` Tom de Vries
2022-05-09 10:39       ` [PATCH][gdb] Update syscalls/{amd64,i386}-linux.xml Tom de Vries
2022-05-09 14:48         ` Simon Marchi
2022-05-09 15:29           ` Tom de Vries
2022-05-09 15:40             ` Andreas Schwab
2022-05-09 15:42               ` Tom de Vries
2022-05-09 15:45                 ` Andreas Schwab
2022-05-09 16:04                   ` Tom de Vries
2022-05-09 17:19         ` Tom Tromey
2022-05-10 11:39           ` Tom de Vries
2022-05-12  9:00             ` Tom de Vries
2022-05-10 11:53         ` Tom de Vries
2022-05-16 16:07           ` Tom Tromey
2022-05-18  9:58             ` [committed][gdb/tdep] Add gdb/syscalls/update-linux-from-src.sh Tom de Vries
2022-05-05 13:23   ` [PATCH, v2][gdb/testsuite] Handle pipe2 syscall in gdb.base/catch-syscall.exp Simon Marchi
2022-05-09 10:18     ` Tom de Vries

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=d0415e7a-d90a-705f-719d-2c9dc657750c@suse.de \
    --to=tdevries@suse.de \
    --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).