Debugging technique in VS2010
This is my blog about VS 2010 and. NET 4 series of article 26.
Today's blog post will introduce some practical debugging technique in Visual Studio.This is my friend Scott Cate (he published dozens of great VS technology article).He recently told me that many programmers under Visual Studio, and even some very experienced developers, I don't know these techniques.Hope this article can help you to master these skills.They are very simple, but it can help you save a lot of time.
Jump to the current cursor (Ctrl + F10)
I often see people in order to reach the target code, set breakpoints, and early in the program and then repeatedly press F10 / F11, step by step, go to the target code.When programmers do need to watch every step of the change of state, F10 / F11 is a reasonable choice.However, in most cases, people just wanted to quickly reach the code they really care about, F10 / F11, it is not the best choice at this moment.
At this time, you should take advantage of "jump to the current cursor place" this feature.Put the cursor on the goal line of code to test, and at the same time press Ctrl and F10, tested the program will jump straight to the bank to stop.You don't have to press the F10 / F11 many times.Even if the target code in separate class or method, you can still from the current is checking the place to jump over it.
Conditions of the interrupt
Another common situation is that the developer to set breakpoints, run the program, using different input trigger breakpoints, and then the breakpoint manual check whether meet the certain conditions, so as to decide whether to continue investigation.If the current scene is not what they want, press F5 to continue to run the program, try other input, manually repeat process just now.
According to the above situation, Visual Studio provides a far more convenient features, interruption of conditions.Only when the program is to satisfy the developers default conditions, conditional breakpoint will be triggered, the debugger.This will avoid frequent manual inspections/recovery program is running, a substantial reduction in the manual and chores in the process of debugging.
How to set up a conditional breakpoint
Breakpoint is very easy to set conditions.In a particular line, press F9 to set breakpoints.
Then right-click on the breakpoint -- - edit window on the left side of the red dot, in the context menu select "Condition...".
Then pop up a dialog for you to set the conditions required to activate the breakpoint.For example: we hope only when the size of the local variable paginatedDinners less than 10, debugging to interrupt.We can write the following expression:
Now I'll run the program, the realization of the search, only when the return value is less than 10 program is running will be
interrupted.For the value of more than 10, the breakpoint will be skipped.
Record the breakpoint
Sometimes you want to, only when the NTH meet the conditions for running the breakpoint, interrupt program is running.For example: when the fifth return less than 10 dinner query results, interrupt program is running. By right-clicking breakpoints, then in the pop-up menu select "Hit count..."Menu command.