intel/sanitize_gpu: add help/gdb options to wrapper
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Mon, 29 Oct 2018 18:14:45 +0000 (18:14 +0000)
committerLionel Landwerlin <lionel.g.landwerlin@intel.com>
Mon, 5 Nov 2018 15:45:07 +0000 (15:45 +0000)
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
src/intel/tools/intel_sanitize_gpu.in

index 3dac954c40843d4642a76711570e1a6a01b17db1..a5b032abc6d350a56adf9877b639be7648fcd649 100755 (executable)
@@ -1,4 +1,57 @@
 #!/bin/bash
 # -*- mode: sh -*-
 
-LD_PRELOAD="@install_libexecdir@/libintel_sanitize_gpu.so${LD_PRELOAD:+:$LD_PRELOAD}" exec "$@"
+function show_help() {
+    cat <<EOF
+Usage: intel_sanitize_gpu [OPTION]... [--] COMMAND ARGUMENTS
+
+Run COMMAND with ARGUMENTS and verify the GPU doesn't write outside its memory
+mapped buffers.
+
+  -g, --gdb          Launch GDB
+
+      --help         Display this help message and exit
+
+EOF
+
+    exit 0
+}
+
+gdb=""
+
+while true; do
+    case "$1" in
+        --gdb)
+            gdb=1
+            shift
+            ;;
+        -g)
+            gdb=1
+            shift
+            ;;
+        --help)
+            show_help
+            ;;
+        --)
+            shift
+            break
+            ;;
+        -*)
+            echo "intel_sanitize_gpu: invalid option: $1"
+            echo
+            show_help
+            ;;
+        *)
+            break
+            ;;
+    esac
+done
+
+[ -z $1 ] && show_help
+
+ld_preload="@install_libexecdir@/libintel_sanitize_gpu.so${LD_PRELOAD:+:$LD_PRELOAD}"
+if [ -z $gdb ]; then
+    LD_PRELOAD=$ld_preload exec "$@"
+else
+    gdb -iex "set exec-wrapper env LD_PRELOAD=$ld_preload" --args $@
+fi