17ec681f3Smrg#!/bin/bash
27ec681f3Smrg# -*- mode: sh -*-
37ec681f3Smrg
47ec681f3Smrgfunction show_help() {
57ec681f3Smrg    cat <<EOF
67ec681f3SmrgUsage: intel_stub_gpu [OPTION]... [--] COMMAND ARGUMENTS
77ec681f3Smrg
87ec681f3SmrgRun COMMAND with ARGUMENTS faking a particular device.
97ec681f3Smrg
107ec681f3Smrg  -g, --gdb           Launch GDB
117ec681f3Smrg
127ec681f3Smrg  -p, --platform=NAME Override PCI ID using a platform name
137ec681f3Smrg
147ec681f3Smrg      --help          Display this help message and exit
157ec681f3Smrg
167ec681f3SmrgEOF
177ec681f3Smrg
187ec681f3Smrg    exit 0
197ec681f3Smrg}
207ec681f3Smrg
217ec681f3Smrggdb=""
227ec681f3Smrgplatform="skl"
237ec681f3Smrg
247ec681f3Smrgwhile true; do
257ec681f3Smrg    case "$1" in
267ec681f3Smrg        --gdb)
277ec681f3Smrg            gdb=1
287ec681f3Smrg            shift
297ec681f3Smrg            ;;
307ec681f3Smrg        -g)
317ec681f3Smrg            gdb=1
327ec681f3Smrg            shift
337ec681f3Smrg            ;;
347ec681f3Smrg        -p)
357ec681f3Smrg            platform=$2
367ec681f3Smrg            shift 2
377ec681f3Smrg            ;;
387ec681f3Smrg        -p*)
397ec681f3Smrg            platform=${1##-p}
407ec681f3Smrg            shift
417ec681f3Smrg            ;;
427ec681f3Smrg        --platform=*)
437ec681f3Smrg            platform=${1##-p}
447ec681f3Smrg            shift
457ec681f3Smrg            ;;
467ec681f3Smrg        --help)
477ec681f3Smrg            show_help
487ec681f3Smrg            ;;
497ec681f3Smrg        --)
507ec681f3Smrg            shift
517ec681f3Smrg            break
527ec681f3Smrg            ;;
537ec681f3Smrg        -*)
547ec681f3Smrg            echo "intel_stub_gpu: invalid option: $1"
557ec681f3Smrg            echo
567ec681f3Smrg            show_help
577ec681f3Smrg            ;;
587ec681f3Smrg        *)
597ec681f3Smrg            break
607ec681f3Smrg            ;;
617ec681f3Smrg    esac
627ec681f3Smrgdone
637ec681f3Smrg
647ec681f3Smrg[ -z $1 ] && show_help
657ec681f3Smrg
667ec681f3SmrgINTEL_STUB_GPU_PLATFORM=$platform
677ec681f3Smrg
687ec681f3Smrgld_preload="@install_libdir@/libintel_noop_drm_shim.so${LD_PRELOAD:+:$LD_PRELOAD}"
697ec681f3Smrgif [ -z $gdb ]; then
707ec681f3Smrg    LD_PRELOAD=$ld_preload INTEL_STUB_GPU_PLATFORM=$platform exec "$@"
717ec681f3Smrgelse
727ec681f3Smrg    gdb -iex "set exec-wrapper env LD_PRELOAD=$ld_preload INTEL_STUB_GPU_PLATFORM=$platform" --args "$@"
737ec681f3Smrgfi
74