Why Windbg?One of the best tools I've used so far for .NET debugging is Windbg. It's a pretty powerful tool to debug .NET code. Once you get a hang of it, it becomes iteratively easier to debug performance issues like high CPU usage, .NET memory leaks, handle leaks, and so on.
I'll be writing a series of articles on how to use windbg to debug various .NET performance issues. But before all of that, let us take a look at how to setup Windbg the right way on a windows machine.
What is Windbg?
Windbg is a debugging tool that comes for free with the Windows SDK pack. It can be downloaded from the Microsoft website.
How to setup Windbg?
The first thing we want to do before using Windbg is to set the symbols path. This symbol path is used to download symbol files for all the Microsoft owned binaries. The most common symbols files are of type VS.NET and PDB. They are generated by default on code compilation in Visual Studio. More information about symbols can be found at debugging with symbols.
To setup the symbol path, here are the steps we need to follow.
- Under Environment variables window, select new button for system variables section.
- Set the variable name to _NT_SYMBOL_PATH and variable value to symsrv*symsrv.dll*c:\localsymbols*http://msdl.microsoft.com/download/symbols.
3. Run the installer and walk through the process.
4. That's it and you're all set with Windbg!!!
Son of Strike dll
SOS.dll or Son of Strike dll is a debugging extension for Windbg that provides .NET specific debugging commands. To load this extension just type .loadby sos clr. If it loads correctly, Windbg should not return any output. Additional way to check if it loaded correctly is to also type !help and hit enter. If it's loaded correctly, all the SOS commands should be displayed in the window.
That's it and you are all set to have fun with Windbg. Enjoy your time with this nasty tool and debug your way through the code.