mesa/src/intel/tools/intel_dump_gpu.in
Lionel Landwerlin feb43ef674 intel: tools: dump: protect against multiple calls on destructor
When running gdb, make sure to pass the LD_PRELOAD variable only to
the executed program, not the debugger. Otherwise the debugger will
run the preloaded constructor/destructor too and bad things will
happen.

Suggested-by: Rafael Antognolli <rafael.antognolli@intel.com>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
2018-07-20 17:36:56 +01:00

106 lines
2.1 KiB
Bash
Executable file

#!/bin/bash
# -*- mode: sh -*-
function show_help() {
cat <<EOF
Usage: intel_dump_gpu [OPTION]... [--] COMMAND ARGUMENTS
Run COMMAND with ARGUMENTS and dump an AUB file that captures buffer
contents and execution of the GEM application.
-o, --output=FILE Name of AUB file. Defaults to COMMAND.aub
--device=ID Override PCI ID of the reported device
-v Enable verbose output
-vv Enable extra verbosity - dumps gtt mappings
--help Display this help message and exit
EOF
exit 0
}
ld_preload="@install_libexecdir@/libintel_dump_gpu.so${LD_PPRELOAD:+:$LD_PRELOAD}"
args=""
file=""
gdb=""
function add_arg() {
arg=$1
args="$args$arg\n"
}
while true; do
case "$1" in
-o)
file=$2
add_arg "file=${file:-$(basename ${file}).aub}"
shift 2
;;
-v)
add_arg "verbose=1"
shift 1
;;
-vv)
add_arg "verbose=2"
shift 1
;;
-o*)
file=${1##-o}
add_arg "file=${file:-$(basename ${file}).aub}"
shift
;;
--output=*)
file=${1##--output=}
add_arg "file=${file:-$(basename ${file}).aub}"
shift
;;
--device=*)
add_arg "device=${1##--device=}"
shift
;;
--gdb)
gdb=1
shift
;;
-g)
gdb=1
shift
;;
--help)
show_help
;;
--)
shift
break
;;
-*)
echo "intel_aubdump: invalid option: $1"
echo
show_help
;;
*)
break
;;
esac
done
[ -z $1 ] && show_help
[ -z $file ] && add_arg "file=intel.aub"
tmp_file=`mktemp`
echo -e $args > $tmp_file
if [ -z $gdb ]; then
LD_PRELOAD="$ld_preload" INTEL_DUMP_GPU_CONFIG=$tmp_file $@
else
gdb -iex "set exec-wrapper env LD_PRELOAD=$ld_preload INTEL_DUMP_GPU_CONFIG=$tmp_file" --args $@
fi
ret=$?
rm $tmp_file
exit $ret