aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2024-06-15 08:10:44 +0200
committerTom de Vries <tdevries@suse.de>2024-06-15 08:10:44 +0200
commit486df2b7c88e3a08d3d799b1595b5fd0dce41d6f (patch)
tree9c09f909e3a8c4c7807e1720d03d2e011b43a0be
parentf2869f51b2ee7fc9357c2030add11435d7f1beef (diff)
downloadgdb-486df2b7c88e3a08d3d799b1595b5fd0dce41d6f.zip
gdb-486df2b7c88e3a08d3d799b1595b5fd0dce41d6f.tar.gz
gdb-486df2b7c88e3a08d3d799b1595b5fd0dce41d6f.tar.bz2
[gdb/testsuite] Clean up gdb/contrib/expect-read1.sh
Clean up script gdb/contrib/expect-read1.sh by: - fixing shellcheck warnings, - using mktemp (which takes TMPDIR into account) instead of a hardcoded "/tmp/expect-read1.$$.so", - adding comments, and - adding emacs / vi settings for local tab size 2 (copied from ./ltmain.sh). Tested on x86_64-linux. Approved-by: Kevin Buettner <kevinb@redhat.com>
-rwxr-xr-xgdb/contrib/expect-read1.sh25
1 files changed, 20 insertions, 5 deletions
diff --git a/gdb/contrib/expect-read1.sh b/gdb/contrib/expect-read1.sh
index 890a1cd..82c638c 100755
--- a/gdb/contrib/expect-read1.sh
+++ b/gdb/contrib/expect-read1.sh
@@ -26,17 +26,32 @@
# or
# bash$ EXPECT=../contrib/expect-read1.sh runtest
-C=`echo $0|sed 's/\.sh$/.c/'`
-if ! test -e $C; then
+# Find source file.
+C=$(echo "$0" | sed 's/\.sh$/.c/')
+if ! test -e "$C"; then
echo >&2 "$0: Cannot find 'srcdir/gdb/contrib/expect-read1.c' at '$C'."
exit 2
fi
-SO=/tmp/expect-read1.$$.so
-rm -f $SO
+
+# Create temp directory.
+tmpdir=$(mktemp -d)
+
+# Schedule cleanup.
+trap 'rm -rf $tmpdir' EXIT
+
+# Compile shared library.
+SO=$tmpdir/expect-read1.so
CMD="${CC_FOR_TARGET:-gcc} -o $SO -Wall -fPIC -shared $C"
if ! $CMD; then
echo >&2 "$0: Failed: $CMD"
exit 2
fi
-trap "rm -f $SO" EXIT
+
+# Call expect with the shared library preloaded.
LD_PRELOAD=$SO expect "$@"
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation:2
+# End:
+# vi:sw=2