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 Breakpoints skipped due to optimization?? (Read 3201 times)
Gary12
Newbies
*
Offline


Posts: 7
Location: California
Joined: Dec 12th, 2013
Breakpoints skipped due to optimization??
Dec 12th, 2013 at 8:17pm
Print Post  
I'm new to Arduino and Visual Micro, but not to Visual Studio or embedded programming for that matter. I've been trying to evaluate the Debugger, but have run into a problem that may be related to the breakpoint being inserted in code that isn't executed due to compiler optimization. Here's the code I'm using to evaluate things...

int GetDelay()
{
     if (!Serial.available())
           return delayTime;
     while(Serial.available())
     {
           int key = Serial.read();
           switch(key)
           {
                 case '+':
                       delayTime += 10;
                       break;
                 case '-':
                       delayTime -= 10;
           }
     }
     if (delayTime < 100)
           delayTime = 100;
     //Serial.println(delayTime);
     return delayTime;
}

Briefly... This is a modification to the Blink sketch, and I use this function to determine if something has been sent from the terminal window. If the data is a +, I increase the blink delay, and if it's a - I decrease it. All works as expected, but...

If I place an unconditional breakpoint inside the while loop, I get the results I expect. If on the other hand I place the breakpoint at this point "if (delayTime < 100)" it's not hit if the delayTime variable is greater than 100. Seems strange. Also, if I put the breakpoint on the return line, it's never hit!!! Any suggestions????  Am I missing something???
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Breakpoints skipped due to optimization??
Reply #1 - Dec 13th, 2013 at 7:17pm
Print Post  
Hi Gary,

Sorry for the delayed response. 

This debugger is a software debugger designed to replace the need to litter code with Serial.print() instructions.

Arduino does not have any simple debugging which is why serial.print() commands are used to report runtime position or values back to the pc serial terminal.

In effect, the Visual Micro debugger does the same thing as a result of adding breakpoints with the various optional properties.

Arduino compilations are always performed in a temp copy of the real code which allows the debugger to injects serial statements without touching the real code.

To answer your question these injected statements are always injected at the end of the line of code at the breakpoint position. Therefore setting a breakpoint on the "if" statement would only execute when the "if" evaluates to be true in your example "delayedTime < 100".

The same applies if you add a breakpoint to a return statement. The code would have returned before being able to process the breakpoint.

Because we can not easily step a single line of source it seemed to make more sense to report the breakpoint after the line of code has executed, it was also easier to design it this way.

So the debugger isn't perfect but a step forward compared to the usual Arduino solution of sending Serial messages from withing the code.

There is a wiki with some articles but the docs need more work. There is also this debug overview which also needs improvement. This YouTube video is a little slow at the start but can be useful
« Last Edit: Dec 13th, 2013 at 7:18pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Gary12
Newbies
*
Offline


Posts: 7
Location: California
Joined: Dec 12th, 2013
Re: Breakpoints skipped due to optimization??
Reply #2 - Dec 13th, 2013 at 8:32pm
Print Post  
Thanks, makes sense now that I understand how it was implemented. I'll keep this in mind as I continue playing with the debugger.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint