I have a simple loop code, and try to debug it. Imagine there is 100 step in my code(a counter cont it). is it possible in VS2010 that for example I trace step 1 and 2 and then ignore the rest until 90,again start debugging from 90 to 100?
I know that I can use an if condition in my code, but can VS 2010 handle such this scenario?
press right click near the breakpoint
you will see
hit count...
condition...
etc.
you can use this to control the break point
Related
The topic says it all. Sometimes i just want to take a quick look and then continue, especially when a code line get hit several times. Can i automate the press-manually-f5-to-continue-after-a-second?
Right click on a breakpoint an select "When Hit...":
You can run a macro like this:
Sub Sleep1s()
System.Threading.Thread.Sleep(1000)
End Sub
Or you can call 11 times {System.Threading.Thread.Sleep(90)} in the message. (Because VS debugger doesn't allow for expression to run for more than 100 ms).
But sleeping this way will block the main IDE UI thread. I don't know is it acceptable for you.
I was debugging my code and thought about a possibility of automatic stepping over or Step into line by line in the xCode debug mode. It would be more efficient to see the way the code will be executed line by line without clicking for every next step. Maybe theres a way you can set a timer for every next step.
I was searching for something like that but there are too many posts for the debug mode which just explain the basic stuff.
Maybe I'm not understanding the question, but the three key buttons are:
- "Step over", F6, continuing execution but stopping at the next line of code (but not single stepping through the method that the current line of code references);
- "Step into", F7, continuing execution but stopping at the first line of code in the method your current line of code references;
- "Step out", F8, continuing execution but stopping at code that called current method.
See Control Program Execution of the Xcode Users Guide.
The other obvious technique is judicious use of setting breakpoints or setting "watch point" (i.e. have the debugger automatically pause whenever a particular variable changes).
Probably worth seeing Debugging in Xcode WWDC 2012 video
I have a method that is executed multiple times (reading data from a database) and now I need to debug a code that executes this method and it seems that it is executed until it reads all rows from the table (1000+) I just want to let the program execute this method and continue with the debugging from there.
Just to be more specific - in debug mode I use F11 to go through the code and this behavior is frustrating. I don't want to change my break point, just want to let this method executes itself, but the only way I know for now is pressing F5 which executes everything not just the current method.
Two options:
1. Press Shift+F11 to step back out of the function
2. Once you have stepped into the function, insert another breakpoint immediately after the loop, then press F5 to skip to that breakpoint.
You can decorate your method with [DebuggerStepThrough]
Instead of using Step Into (F11) Use - Step Over (F10)
and if you've already entered the function (because you pressed F11) you can always Step Out using Shift + F11
For more information see Mastering Debugging in Visual Studio 2010
I may sound silly, but I am naive in debugging.
I have one doubt, in order to track the flow of execution in a program, what should be the optimum point to put a breakpoint?
Is it so that wherever we will put a breakpoint, the application execution flow before that would not be traced?
The best point to place a breakpoint is where you need the function to break.
If that exact point will not be reached because of conditionals, break on the conditional that would cause it to skip and ensure the code you do want to debug will get reached.
You need to place breakpoints where you can get to the code you wish to debug the fastest.
You would place a breakpoint very near or just before a piece of code you want to step through in order to debug it, then when execution pauses at your breakpoint, step through line by line to examine the state of variables and follow the path of execution.
how can i set de debugger to stop when some particular variable has a defined value?. For example i have a code that it crash that loops 10000 time to make some postprocessing. I know that the error could be produced from the 7000 iteration up, so i want to stop from there on, avoiding manual loop from the first 7000.
Im using visual studio 2008 and 2010 with c#, i think that the solution will be the same for both.
What you're looking for is a conditional break point. Here's how to set it up assuming the variables name is i.
Set a normal breakpoint on the line after the value is set
Right click on the red dot portion of the breakpoint and select "Condition"
Enter the condition which you want to check for. Example: i == 10000
Hit OK
Now run your scenario again and the breakpoint will be hit only when the value of i equals 10000.
A word of warning. You can put pretty much any legal C# expression into a conditional break point but it will be evaluated every single time the break point is hit. That can lead to very slow debugging if use a complex conditional
Open the breakpoint window and create a new data breakpoint from its menu.
The easy way to do that is:
if (nameVariable = X ) {
BreakPoint: nameVariable;
}