chiark / gitweb /
regress/gdbwrap: Provide a convenience script
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 23 Jul 2014 23:52:51 +0000 (00:52 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 24 Jul 2014 00:56:52 +0000 (01:56 +0100)
This lets you run gdb from within r1test with appropriate fd plumbing.
(It's a shame gdb doesn't have a way to simply tell it to take its
commands from /dev/tty.)

Add the suggested example gdb script file, x.gdb, to .gitignore.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
.gitignore
regress/gdbwrap [new file with mode: 0755]

index 258e160..aea004a 100644 (file)
@@ -10,6 +10,7 @@ settings.make
 *.so
 *.a
 *~
+x.gdb
 client/Makefile
 client/adnstest_s
 client/fanftest_s
diff --git a/regress/gdbwrap b/regress/gdbwrap
new file mode 100755 (executable)
index 0000000..b3782b0
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+set -e
+
+# For example, put this in x.gdb
+#   break adns__revparse_label
+#   break adns__revparse_done
+#   run
+# and then
+#   debug='./gdbwrap -n x.gdb' ./r1test tcpptr
+#
+# gdbwrap can be passed arguments like
+#    *.gdb     passed to gdb with -x
+#    -n        exit with exit status 5 which makes r1test think "skipped"
+#
+# other arguments are taken to be the program name provided by
+# whatever has been told to use gdbwrap (eg r1test)
+
+while true; do
+       case "$1" in
+       *.gdb)    xgdb="-x $1"; shift;;
+       -n)       x5='exit 5'; shift;;
+       *)        break;;
+       esac
+done
+
+exe=$1; shift
+
+exec 5<&0 6>&1 7>&2
+exec 0<>/dev/tty 1>&0 2>&0
+
+set +e
+ex="set args <&5 >&6 2>&7"
+for a in "$@"; do
+       ex="$ex '$a'"
+done
+gdb --return-child-result -ex "$ex" $xgdb $exe
+$x5