Debugging shaders
Shaders are programs that run on your GPU as opposed to your CPU. They have a different set of compilers, languages and tools. Two common types are vertex shaders and pixel shaders. The latter are executed to determine the colour of a single pixel. They have clearly defined inputs and outputs.
They also don’t have the concept of strings or characters, nor a logging mechanism or stdio access. You can’t access the memory in your CPU area to write information.
So how do you debug them?
Depending on your graphics API and platform, there might be a tool to set breakpoints and inspect state. Otherwise, you can write your values out into your outputs. That means colours as debug values! You can branch within the shader and make up sentinel colour (or colour component) values to mean different things, and work backwards from there.
Tools you can use include: RenderDoc, Microsoft PIX for Windows, Visual Studio Graphics Debugger, AMD Radeon™ Developer Tool Suite, and NVIDIA Nsight Graphics. There are also console/device-specific tools that are under NDA. Lastly, a new tool: SHADERed, which I haven’t tried yet but looks promising.