As much as I generally don't like the discussion/subjective posts on SO, I have really come to appreciate the "Hidden Secrets" set of posts that people have put together. They provide a great overview of some commonly missed tools that you might now otherwise discover.
For this question I would like to explore the Visual Studio .NET debugger. What are some of the "hidden secrets" in the VS.NET debugger that you use often or recently discovered and wish you would have known long ago?
One of my favorite features is the "When Hit..." option available on a breakpoint. You can print a message with the value of a variable along with lots of other information, such as:
$ADDRESS
- Current Instruction$CALLER
- Previous Function Name$CALLSTACK
- Call Stack$FUNCTION
- Current Function Name$PID
- Process ID$PNAME
- Process Name$TID
- Thread ID$TNAME
- Thread NameYou can also have it run a macro, but I've never used that feature.
$exception
in the watch window will show the exception that is currently being processed even if you don't have a catch that assign theException
instance to a named variable.You can right-click an object in the Watch window and click Make Object ID.
It will assign that instance an ID number, allowing you to see, in a complicated object graph, which objects refer to the same instance.
You can open and place a breakpoint in a source file if the file belongs to another solution (external file). The debugger can still hit the breakpoint. No need to open another Visual Studio instance to debug the external file. Helpful in debugging web services which you source to. This works as long as all the sources are current and compiled.
This is kind of an old one. If you add a watch expression
err,hr
, then this will hold the result of GetLastError(), formatted as an HRESULT (VC++ debugger only).For .net applications
System.Diagnostics
has lots of useful debugging things. TheDebugger
class for example:System.Diagnostics
also has lots of good attributes. The two I've used are the debugger display attribute for changing the details put into the locals window and the step through attribute for skipping code you don't care about debugging: