How to use Intel gdb-igfx to debug Intel GPU.
Everything starts with this article: Getting Started with Debugging with Intel® Parallel Studio XE 2016 [1]. unfortunately, the article is quite old now ("Last updated on August 25, 2015") and not really up-to-date anymore.

No, wait, there is a newer version there [2] for Intel Parallel Studio 2017.
sudo modprobe igfxdcd
igfxdcd: loading out-of-tree module taints kernel. igfxdcd: module verification failed: signature and/or required key missing - tainting kernel igfxdcd: warning: this is an untested device ID. Setting dangerous option enable_hangcheck - tainting kernel Setting dangerous option enable_cmd_parser - tainting kernel igfxdcd: Debug Companion Driver for Intel(R) graphics
To work with the Intel® SDK for OpenCL* - Debugger plug-in, the OpenCL* kernel code must exist in a text file separate from the code of the host. Debugging OpenCL* code that only appears in a string embedded in the host application is not supported.
ina@nuc:~/simple_add$ gdbserver-igfx :3333 simple_add Inferior creation not supported, use the --debug option Exiting

export GFX_NOTIFY_DEBUGGER=1 export GFX_PROG_OPTIONS="-generateDebugInfo -debug -addKernelID" export GFX_OFFLOAD_TIMEOUT_FUNC=0 export IGFXDBG_IDE_START_UP_MODE=1
$TARGET_ROOT/bin/gdbserver $@
You can see strange environment variable initialized before starting the gdbserver command:
- GFX_NOTIFY_DEBUGGER:
- GFX_PROG_OPTIONS
- GFX_OFFLOAD_TIMEOUT_FUNC
- IGFXDBG_IDE_START_UP_MODE

References
[1] | Intel, Getting Started with Debugging with Intel® Parallel Studio XE 2016, https://software.intel.com/en-us/get-started-with-debugger-extension-for-linux |
[2] | Intel, Getting Started with the Intel® Debugger for Heterogeneous Compute 2017 for Linux, https://software.intel.com/en-us/psxe-2017-get-started-gdbigfx-linux |
https://software.intel.com/en-us/code-builder-user-manual-debugging-opencl-kernels-1 https://software.intel.com/sites/landingpage/opencl/user-guide/Debugging_Your_OpenCL_Kernel_with_Intel_SDK_for_OpenCL_Debugger.htm