[PATCH 3/3] Add gdb remote protocol handling to strace
Stan Cox
scox at redhat.com
Fri Feb 10 20:24:27 UTC 2017
Add a test: gdbrsp.c and a test driver gdbrsp.test. The test checks if
gdbserver is available and if it supports syscall catching.
diff --git a/tests/Makefile.am b/../src/tests/Makefile.am
index 90b7bf3..2c059e4 100644
--- a/tests/Makefile.am
+++ b/../src/tests/Makefile.am
@@ -143,7 +143,6 @@ check_PROGRAMS = \
ftruncate64 \
futex \
futimesat \
- gdbrsp \
get_mempolicy \
getcpu \
getcwd \
@@ -547,7 +546,6 @@ DECODER_TESTS = \
ftruncate64.test \
futex.test \
futimesat.test \
- gdbrsp.test \
get_mempolicy.test \
getcpu.test \
getcwd.test \
diff --git a/tests/gdbrsp.c b/tests/gdbrsp.c
new file mode 100644
index 0000000..f39a7c9
--- /dev/null
+++ b/tests/gdbrsp.c
@@ -0,0 +1,79 @@
+/* This file is used to test the 'catch syscall' feature on GDB.
+
+ Please, if you are going to edit this file DO NOT change the syscalls
+ being called (nor the order of them). If you really must do this, then
+ take a look at catch-syscall.exp and modify there too.
+
+ Written by Sergio Durigan Junior <sergiodj at linux.vnet.ibm.com>
+ September, 2008
+
+ This is the gdb catch-syscall.c test */
+
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sched.h>
+
+/* These are the syscalls numbers used by the test. */
+
+int close_syscall = SYS_close;
+int chroot_syscall = SYS_chroot;
+/* GDB had a bug where it couldn't catch syscall number 0 (PR 16297).
+ In most GNU/Linux architectures, syscall number 0 is
+ restart_syscall, which can't be called from userspace. However,
+ the "read" syscall is zero on x86_64. */
+int read_syscall = SYS_read;
+#ifdef SYS_pipe
+int pipe_syscall = SYS_pipe;
+#else
+int pipe2_syscall = SYS_pipe2;
+#endif
+int write_syscall = SYS_write;
+#if defined(__arm__)
+/* Although 123456789 is an illegal syscall umber on arm linux, kernel
+ sends SIGILL rather than returns -ENOSYS. However, arm linux kernel
+ returns -ENOSYS if syscall number is within 0xf0001..0xf07ff, so we
+ can use 0xf07ff for unknown_syscall in test. */
+int unknown_syscall = 0x0f07ff;
+#else
+int unknown_syscall = 123456789;
+#endif
+int exit_group_syscall = SYS_exit_group;
+
+/* Set by the test when it wants execve. */
+int do_execve = 0;
+
+int
+main (int argc, char *const argv[])
+{
+ int fd[2];
+ char buf1[2] = "a";
+ char buf2[2];
+
+ /* Test a simple self-exec, but only on request. */
+ if (do_execve)
+ execv (*argv, argv);
+
+ /* A close() with a wrong argument. We are only
+ interested in the syscall. */
+ close (-1);
+
+ chroot (".");
+
+ pipe (fd);
+
+ write (fd[1], buf1, sizeof (buf1));
+ read (fd[0], buf2, sizeof (buf2));
+
+ /* Test vfork-event interactions. Child exits immediately.
+ (Plain fork won't work on no-mmu kernel configurations.) */
+ if (vfork () == 0)
+ _exit (0);
+
+ /* Trigger an intentional ENOSYS. */
+ syscall (unknown_syscall);
+
+ /* The last syscall. Do not change this. */
+ _exit (0);
+}
diff --git a/tests/gdbrsp.test b/tests/gdbrsp.test
new file mode 100755
index 0000000..9f8767e
--- /dev/null
+++ b/tests/gdbrsp.test
@@ -0,0 +1,65 @@
+#!/bin/sh
+#
+# Check -G option: gdb remote serial protocol
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+. "${srcdir=.}/init.sh"
+
+check_prog gdb
+check_prog gdbserver
+
+gdb -batch -iex 'target remote | gdbserver --remote-debug -
/usr/bin/true' >| /tmp/,gdb 2>&1
+if grep QCatchSyscalls /tmp/,gdb > /dev/null
+then :
+else framework_skip_ "Correct version of gdbserver is not available"
+fi
+
+run_prog > /dev/null
+
+gdbserver --once --multi :65432 &
+if [ $? -gt 0 ] ; then
+ framework_skip_ "Unable to start gdbserver"
+fi
+$STRACE -G localhost:65432 $(readlink -f ./gdbrsp) >& $LOG
+
+EXPECTED="$LOG.expected"
+cat > "$EXPECTED" << __EOF__
+close.-1..* = -1 EBADF .Bad file descriptor.
+chroot.* = -1 EPERM .Operation not permitted.*
+pipe..3, 4...* = 0
+write.4, "a.0", 2..* = 2
+read.3, "a.0", 2..* = 2
+vfork.*unfinished.*
+.pid.*exited with 0.*
+.pid.*vfork resumed.* =.*
+__EOF__
+
+match_grep "$LOG" "$EXPECTED"
+rm -f $EXPECTED
+
+exit 0
+
+
More information about the Strace-devel
mailing list