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;
}
Related
Often times I add a breakpoint at a line in a loop and keep playing the to the next loop until I find the desired execution loop. And I might have to do this repeatedly to find the next possible error in the loop. I either count the number of times I hit the play button (F8) or identify a variable to add conditional breakpoint.
Is there a way to identify the number of time a breakpoint is hit? can I add a "watch" expression to get this?
This would help me if I have to debug the same line in multiple debugging sessions after changing something.
One of the options under Conditional Breakpoint is "Log Message". This outputs a message in the debug console with a number next to it showing how many times the log point was hit.
(This is dependent on the debugger extension, but it works in like this in the Python and JavaScript debuggers.)
There is an option for specifying "Hit Count" when you right click in the margin and select "Add Conditional Breakpoint." A text box appears with a drop down box beside it where you select "Hit Count" and add the number of hits desired in the text box:
The exact syntax depends on the debugger extension you are using, but for the Node.js debugger the syntax is as follows (from the documentation):
The syntax is either an integer or one of the operators <, <=, ==, >, >=, % followed by an integer.
Some examples:
>10 break always after 10 hits
<3 break on the first two hits only
10 same as >=10
%2 break on every other hit
Python syntax appears to be the same. It looks like hit counts are not currently working in the C++ extension though: https://github.com/Microsoft/vscode-cpptools/issues/714#issuecomment-663528553
See also https://code.visualstudio.com/Docs/editor/debugging#_conditional-breakpoints.
I am experiencing very strange behavior within VB6 IDE whenever the break point hits(Step Into, Out, Over), the class is closed and makes it impossible to debug. Then within window-Cascade i can re-open the class but again when break point hits, the class is closed. Can anyone help please.
Step execution does sometimes behave that way. The reason is that VB is event driven and when an event occurs, then the code behind that event will run, and your code that you are stepping through might NOT be the code that gets run, so things change and code runs while your PAUSED code is still on hold.
When I encounter that I overcome it by using debug.print to send my monitored variables' current values to the OUTPUT window, or if you need more elaborate capability, write a sub that sends the data to a local text file and then invoke that sub as needed, passing into the variables ( and labels ) that you want displayed.
Once debug.print or a logging routine is in place then run the code WITHOUT pauses or breaks. The debugging output will tell you what is happening, in what order etc, so no need to stop the code or risk altering the order of execution.
Be sure to include lots of 'context' data such as : 'Entering SUB_XYZ, Param values are A, B, C... NOW at line 99 in SUB XYZ.... NOW in TRUE side of IF TEST # 1....
Include time stamps on all outputs.
Put your tracing logic only around the suspected problem area, expand from there only as needed.
It's a pain, but it works.
I finally resolved this issue and problem was within Display settings within windows 10. Basically if I apply vertical settings by placing both screen vertically 2nd on top of first then this issue happens,if i apply horizontal settings then this issue does not happen.
problematic settings with vb
settings that does solves debugging issue. VB is so weird and old cannot cope with display settings
You can easily set a watchpoint in XCode by following these steps (btw if there is a simpler way, I'd like to know it...):
- Run your program
- Set a breakpoint in the code where your variable is used
- when reaching breakpoint, use a right click on the variable and select 'Watch "nameOfTheVariable"'
- Continue execution.
The only problem is that execution will stop every time the variable value changes. I would like XCode to continue the execution without stopping, i.e. merely display the value changes in the console output.
This feature seems available in command line mode, and although I initially wanted to avoid it, I posted a solution using that mode (see below), as it seems to be the only way to do what I want, i.e. continue execution while displaying variable changes.
Well it seems that the only way to achieve this is to use the LLDB command line. So for those of you who, like me, had never used it here is a step-by-step (actually fairly easy) way to use it and watch variables without stopping execution:
Set a breakpoint in Xcode (click to the left of your source line) where the variable you want to watch is used (in scope), and run your code until it reaches the breakpoint.
In the console view (little window displayed at the bottom right where you can display console things) you should see a (lldb) prompt. This is where you enter the following commands:
w s v stuff (or watchpoint set variable stuff) where stuff is the name of the variable you want to watch
w c a (or watchpoint command add) to enter a script mode where you enter one command per line as follows after the '>'
p stuff (or print stuff) to display the new stuff variable value
c (or continue) to continue execution
DONE to finish this little script (note the UPPERCASE characters!)
THAT'S IT ! You can remove your breakpoint and continue execution. From then on messages will be displayed in the console every time the variable "stuff" is updated, without stopping the execution of your code (it might slow it down a little of course, but that is usually not important).
Watchpoint is just like a breakpoint which gets hit when the value of a variable which is being watched gets updated.
To set it please follow below steps:
1.Set a breakpoint such that the variables view in the debugger shows the variable you want to watch.
2.Right click on the variable and select Watch "variable name".
3.This will stop the execution whenever the value of the variable changes.
The watchpoint will now start showing in the debug navigator.
In order to remove it just drag is towards the editor and you are good to go.
PS : this is just a smarter version of implemention didset for a variable and setting and breakpoint inside it.
I rarely used the netbeans debugger but I have this bug in my program which I'm trying to get to the bottom of. Basically my program searches a binary file (4.5gb) for a seqeunce of bytes and writes it to file. However, the programm always stalls at this specific point in the file when reading near halfway of the file (~2gb). They way I using the debugger if putting a breakpoint and keep "continuing" the debugger until it reaches that point in the file but it's going to take forever to reach the 2gb mark. I'm guessing there's a better way to use the debugger which I'm not aware of. Any suggestions?
Netbeans supports conditional breakpoints. If you add a breakpoint via the menu "Debug / New Breakpoint" (or just hit Ctrl+Shift+F8) you can specify a condition (either how often the breakpoint has to be hit until it execution is halted on this breakpoint or an expression).
You could keep a count of how much data you have processed, and add an if() block which checks whether you are up to the 2GB mark. Put a dummy command inside the if() block, and add a breakpoint on the dummy command; this will only be reached when you have processed sufficient data.
I have this really nasty bug in my program, which somehow changes the value of my variable. I have tried setting break points but can't find the line of code that's the culprit.
Is there any way to pause program execution when there's a line of code that's changing the value of a variable in Xcode 4?
One way would be to find the value changing operations or in general any bug using bisection. Ie. you choose two breakpoints that have the problematic operation in between and move one of them to middle and check if the value still changes. If it does repeat in this halt, if not repeat in the other half.