How can I see when the value of a variable change? - debugging

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.

Related

Debugging Step Into, Over, Out within VB6 IDE closes the class window

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

Is there a command that clears the Y-variables?

I have a command that essentially functions like clearing the memory, but doesn't wipe programs and sets the settings I like. I found out that while it does its job well, it doesn't seem to clear the equations in the Y= menu. Is there a command or another way to achieve this?
PROGRAM:CLEAR
:MATHPRINT
:Normal
...
:DiagnosticOn
:ClrDraw
:Clear Entries
:ClrAllLists
:SetUpEditor
:ClrHome
:"
On a similar note to TimTech, Delvar can be used to reset the value of a variable.
DelVar Y1
The benefit of this is that multiple DelVar calls can be chained without a line break.
DelVar Y1DelVar Y2Disp "Done
A non-programmatic way of clearing a calculator is to use the key sequence 2nd + 7 1 2. Unfortunately, this also clears programs.
This method will clear all RAM on the calculator, so use it with caution.
I found a better programmatic way of clearing the Y-VARS. This method also resets all other graph settings to their default value. In your case, this seems to be a desirable side-effect. Unfortunately, it requires a little bit of set up and occupies one of the Graph Database variables (119 Bytes). Because this variable can be kept archived, this does not consume any RAM.
Setup
Manually clear All Y-VARS, including parametric, polar and sequence variables.
Manually Reset All graph window settings to their default
ZStandard
RectGC
CoordOn
GridOff
AxesOn
LabelOff
ExprOn
Store current setting in a Graph Database variable
StoreGDB GDB1 entered with key strokes: 2ndPRGMâ—„5VARS3ENTERENTER
Archive GDB1
Archive GDB1 entered with keystrokes: 2nd+5VARS3ENTERENTER
Use in Program
To use this archived variable in a program, you must unarchive it, recall its contents, and finally archive the variable again. This is accomplished by the following code block.
UnArchive GDB1
RecallGDB GDB1
Archive GDB1
If you're using a TI-83 calculator, you need to skip the steps involving archiving because the TI-83 does not support flash memory. The TI-83 Plus and above work fine, however.
No command, but you can do "->Y1 or DelVar Y1 to clear Y1, and similarly for the others.

Pascal External:SIGSEGV

I have a program that uses linked lists. It crashes with External:SIGSEGV when it gets to
new(R);R:=queue;queue:=queue.Next;dispose(R);
where I'm getting rid of the first element of the queue list, after dispose(R). What's even more weird - when I change it to queue:=queue.Next that is, just moving forward without dumping the element - it still crashes, after this command. It's worth mentioning that the value of queue.Next=nil. And when I tried just queue:=nil; it crashed too, leaving me absolutely puzzled. Can somebody help me?
Edit: I've uploaded the whole code here, relevant line is no. 128.
The problem was that I was dereferencing the pointer later and lazarus wasn't able to backtrack to that position so he pointed at the line where the pointer was set to nil.

How can i stop the debugger in a particular variable value?

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;
}

is there a way to track the values of certain variables after the end of a program in visual studio?

i have found myself several times in the need of knowing the last values set to a range of variables that were in a certain portion of code, or method; maybe dispersed around the program.
does anyone know a way to select variables and know the last value set to them after the program ends running - in a windows maybe ?
There isn't anything I know of that will record every value ever assigned to every variable in your program in case you want to look at it later. It is possible with VS2010's historical debugging abilities to look at "values from the past" although I haven't used this yet, so I don't know if that ability extends "beyond death" of the process.
You may also be able to use tracepoints (VS2008 and later). These are like breakpoints, but instead of stopping execution they simply print information to the debug output. So you could add a tracepoint for a variable so that each time it is changed its value is reported (basically the same as printing the values out in your code, but you don't have to change your code to enable them, and can add them while your code is executing).
Two simple approaches that will work for pretty much any dev environment are:
Write the values to an application log each time they change, then read the last reported entries. If you realise you need 5 values from all around the program, simply printing them to the debug output will only take a few seconds to add to your program. (If you can't do this easily, then you're not encapsulating your data very well).
Put a breakpoint on the destructor of the class you're interested in, or at the start of the shutdown process just before you destroy the objects, or the last line of code in your program (for statics) (etc) and just use the debugger to drill down into the data.

Resources