xref: /aosp_15_r20/external/mesa3d/src/intel/tools/intel_stub_gpu.in (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1#!/usr/bin/env bash
2# -*- mode: sh -*-
3
4function show_help() {
5    cat <<EOF
6Usage: intel_stub_gpu [OPTION]... [--] COMMAND ARGUMENTS
7
8Run COMMAND with ARGUMENTS faking a particular device.
9
10  -g, --gdb           Launch GDB
11
12  -p, --platform=NAME Override PCI ID using a platform name
13
14      --help          Display this help message and exit
15
16EOF
17
18    exit 0
19}
20
21gdb=
22valgrind=
23platform="skl"
24
25while true; do
26    case "$1" in
27        --gdb)
28            gdb=1
29            shift
30            ;;
31        -g)
32            gdb=1
33            shift
34            ;;
35        --valgrind)
36            valgrind=1
37            shift
38            ;;
39        -p)
40            platform=$2
41            shift 2
42            ;;
43        -p*)
44            platform=${1##-p}
45            shift
46            ;;
47        --platform=*)
48            platform=${1##--platform=}
49            shift
50            ;;
51        --help)
52            show_help
53            ;;
54        --)
55            shift
56            break
57            ;;
58        -*)
59            echo "intel_stub_gpu: invalid option: $1"
60            echo
61            show_help
62            ;;
63        *)
64            break
65            ;;
66    esac
67done
68
69[ -z $1 ] && show_help
70
71INTEL_STUB_GPU_PLATFORM=$platform
72
73drm_shim_dir="@install_libdir@"
74
75if [ -n "$MESON_DEVENV" ]; then
76    drm_shim_dir=$(realpath "$(dirname "$0")")
77fi
78
79ld_preload="$drm_shim_dir/libintel_noop_drm_shim.so${LD_PRELOAD:+:$LD_PRELOAD}"
80if [ -n "$gdb" ]; then
81    gdb -iex "set exec-wrapper env LD_PRELOAD=$ld_preload INTEL_STUB_GPU_PLATFORM=$platform" --args "$@"
82elif [ -n "$valgrind" ]; then
83    LD_PRELOAD=$ld_preload INTEL_STUB_GPU_PLATFORM=$platform exec valgrind "$@"
84else
85    LD_PRELOAD=$ld_preload INTEL_STUB_GPU_PLATFORM=$platform exec "$@"
86fi
87