Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic strange behaviour in the debugger - IF (Read 3618 times)
cybermec
Junior Member
**
Offline


Posts: 19
Joined: Jun 3rd, 2013
strange behaviour in the debugger - IF
Aug 21st, 2013 at 10:08pm
Print Post  
Here I discovered some strange behaviour in the debugger.
I have the following method -the one that was blocking me  Wink -

long Tension::GetScaleConstant(float vcc1, float vcc2)
{      
     static long scaleConstant = -1;
     if( scaleConstant == -1 )
     {
           float ref = 1.1 * vcc1 / vcc2;
           scaleConstant = ref * 1023 * 1000;
     }
     return scaleConstant;
}

I put a trace point on the "if(" row with the message: "Scale: {scaleConstant}".

Now Serial monitor displays the correct value (1107 in my case), while Expression analyzer always displays -1 for the scaleConstant variable.

I suppose static variables are not managed by the debugger.
« Last Edit: Aug 21st, 2013 at 11:32pm by Tim@Visual Micro »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: strange behaviour in the debugger - IF
Reply #1 - Aug 21st, 2013 at 11:17pm
Print Post  
Great.

Quote:
I put a trace point on the "if(" row with the message: "Scale: {scaleConstant}".

Now Serial monitor displays the correct value (1107 in my case), while Expression analyzer always displays -1 for the scaleConstant variable.


The debugger uses the Arduino serial to send data so it will cater for any type of variable in the same way as if you typed Serial.println(myVar) into the source code.

I think what's going on here is related to a "quirk" of injected debugging and might be optional in future releases. 

Currently the the sending of break point data is injected after the current statement has been completed, in the same way that you might add a Serial.print(myVar) after the line that calculates myVar.

If you put a breakpoint on the IF line, then the breakpoint/Serial has to be injected inside the { of the IF.

So in your case the value will always be -1 because the IF checks for -1

With injected breakpoints you can add them to blank lines, they are not really bound to the source code in the same way as a normal built-in Visual Studio debugger. This means you can add a breakpoint the line before where you have added it.

You can also add the breakpoint to the closing brace } of the IF() {, in which case the value will be reported after the entire IF has been processed.

Some experienced coders have asked why the breakpoints are not injected before the line begins. It's a complicated discussion that might become easier with a few new features due out soon. However all for another thread Smiley

Does this make sense?
« Last Edit: Aug 21st, 2013 at 11:31pm by Tim@Visual Micro »  
Back to top
IP Logged
 
cybermec
Junior Member
**
Offline


Posts: 19
Joined: Jun 3rd, 2013
Re: strange behaviour in the debugger - IF
Reply #2 - Aug 22nd, 2013 at 6:31pm
Print Post  
This is correct. I've tested it and now variable is correctly updated in the window.
Thanks
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint