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 Placement of Breakpoints (Read 8809 times)
uChip
Junior Member
**
Offline


Posts: 22
Location: Washington, USA
Joined: Apr 22nd, 2013
Placement of Breakpoints
Apr 25th, 2013 at 6:15pm
Print Post  
I have migrated this topic since it makes more sense to have the discussion here.

Tim@Visual Micro wrote on Apr 25th, 2013 at 12:16pm:
uChip Quote:- If I set a breakpoint on an if statement and output a message "When Hit..." the message is only output if the if statement is true.  That is inconsistent with desktop code.

Forgot to answer this one....
Because the arduino can't really perform debug we inject serial print statements. This means that we don't really have the option to examine a line of code unless you have pre-set the variables to be examined. At the moment we don't have the facility to stop at a line and then continue to the end of the same line, all we can do it stop at each breakpoint. So we stop after the line of code for which you have applied the breakpoint.

So, this debugger replaces the concept of serial.print() messages which users would often add to the end of a line of code to report the values of variables. 

This is what the debugger does, when you set a breakpoint it is added (in background) to the end of the current line of code, if the line of code is an IF {} statement then the breakpoint is placed inside the first brace of the IF. If the IF is a single line without braces then braces are automatically added in background during compilation. (A users source code is never amended)

Unlike a normal debugger, you can place a breakpoint on empty code lines and even on commented code lines, so as you can see it is slightly different to normal.

This is an important discussion which I was hoping would be discussed more during the beta of the debugger. 

So far we have two windows/netduino users who feel it would be better if breakpoints were placed at the start of a code line and many arduino users that feel the way the current system works is okay. I'm not sure what the right solution is and have been considering making it an option.

If you progress with the debugger and use the facility to alter variable values when an arduino is running and have time to consider this issue more I will be very interested to hear your thoughts.

Also keen to hear your thoughts for new users that add a breakpoint, for example, to a function name such as "loop()". In this case the same functionality is applied, the breakpoint is actually inserted (in background) inside the first brace of the function. So again the breakpoint is inserted after the line of code. 

I am trying to keep things consistent for new users but in doing so I know that this can be confusing for experienced debugger users

Feedback and discussion about this is very much appreciated 

  
Back to top
 
IP Logged
 
uChip
Junior Member
**
Offline


Posts: 22
Location: Washington, USA
Joined: Apr 22nd, 2013
Re: Placement of Breakpoints
Reply #1 - Apr 25th, 2013 at 6:19pm
Print Post  
I place the blame for this one squarely on Microsoft. When setting a breakpoint the affected statement is highlighted.  A better indication would be insertion of a breakpoint indicator -between- statements to make it clear where the break will occur.

I think my strongest argument supporting breaking at the beginning of the line is this: I believe that clicking on the object of interest is intuitive.  If I am focused on investigating the conditional of an if statement I would click on it.  I may eventually want to backtrack to see how we got to the current state, but I start by investigating the current state.  I will never see that state if the breakpoint doesn't hit, therefore the break should be before the conditional is evaluated.

Another argument for placing the breakpoint at the beginning of the line is consistency with the VS debugger.  While VMDB won't be able to match VSDB everywhere it should match as much as possible.  The reason why I think this is important is that a key reason for using VM over ArduinoIDE is to not have to remember the idiosyncrasies of multiple tools.  Keeping things consistent means there is less to learn/remember.  In VSDB placing a breakpoint on a line with an if statement would break prior to the if condition being evaluated, therefore VMDB should do likewise.

What this really points out is that when debugging an if statement I really want two breakpoints.  The first allows me to check the inputs to the conditional.  The second allows me to see if the conditional evaluated as I thought it would.  In normal VSDB I set the break on the if and use step to see how it evaluated.  Since step is not possible in VMDB I need to remember to set two breakpoints. 

Your comment about making it easy for people migrating from ArduinoIDE has merit, however I will point out that the pain of migration is temporary, the pain of an inconsistent environment is permanent.  This is in the eye of the beholder.  Painful migration might be a barrier to VM adoption.  Longer term inconsistency is irrelevant if the barrier prevents folks from migrating.  No easy answer there, but I think this reasoning applies to other features more than the debugger since ArduinoIDE has none.

- Chip
  
Back to top
 
IP Logged
 
uChip
Junior Member
**
Offline


Posts: 22
Location: Washington, USA
Joined: Apr 22nd, 2013
Re: Placement of Breakpoints
Reply #2 - Apr 25th, 2013 at 6:53pm
Print Post  
uChip wrote on Apr 25th, 2013 at 6:15pm:
Also keen to hear your thoughts for new users that add a breakpoint, for example, to a function name such as "loop()". In this case the same functionality is applied, the breakpoint is actually inserted (in background) inside the first brace of the function. So again the breakpoint is inserted after the line of code. 


If I understand you correctly, I think this situation is a little different.  An if statement conditional has visible code that I may want to debug.  A function name does not.  From a programmer view the function name is just a marker for the beginning of the function.  There is no functional difference between before and after.

Another way to say this is that the if statement conditional is divisible and therefore before or after makes a difference.  The function name is not really divisible and therefore before or after should be equivalent.

If there has been discussion on this point it was probably around thinking that placing the breakpoint at the beginning would make it outside the function (prior to the function) and therefore not be hit when the function is called.

I would disagree with such thinking since I would regard the function name as part of the function.  As stated in my previous post I think that intuitively I would click on the function name if that were my interest and expect the break to occur immediately upon the function being called prior to any function code being executed.

I can see the other point of view, but believe that the intuitive solution is the one where clicking on the function name does what I want.

Again, a clear marker -between- statements would make it clearer where the breakpoint really is.  It is all Microsoft's fault.  Wink

- Chip
  
Back to top
 
IP Logged
 
uChip
Junior Member
**
Offline


Posts: 22
Location: Washington, USA
Joined: Apr 22nd, 2013
Re: Placement of Breakpoints
Reply #3 - Apr 25th, 2013 at 7:14pm
Print Post  
I did not miss your comment about the impact of/on modifying variables.  I will dig in on that next.
- Chip
  
Back to top
 
IP Logged
 
uChip
Junior Member
**
Offline


Posts: 22
Location: Washington, USA
Joined: Apr 22nd, 2013
Re: Placement of Breakpoints
Reply #4 - Apr 26th, 2013 at 2:52am
Print Post  
Ok, I'm not THE expert but here are my thoughts after playing with the debugger for a little while.

I believe variable modification helps strengthen the argument for breaking before the conditional is evaluated in an if statement.  My thinking is as follows.  Presume I am investigating the code focused on the if conditional.  I click on that statement as the focus of my investigation. At the breakpoint I examine the inputs to the conditional and perhaps modify them to experiment with their impact on the evaluation.  This all works naturally if the break is at the beginning of the if.  After validating the inputs I would then step (second break in VMDB) to see that the computer and I agree on the outcome of the evaluation.

I think all would agree that the behaviors should be natural and intuitive.  The problem is that intuitive is really just our expectations which are heavily influenced by our prior experience.  I am used to debuggers that effectively replace the selected statement with a break, and only process the statement if the break is continued.  I would be interested to hear the argument of why it would be more intuitive to break after the statement to see I can map my thinking to that.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Placement of Breakpoints
Reply #5 - Apr 26th, 2013 at 10:18am
Print Post  
I agree with a lot of what you have said. 

What about this for a new user

Line of code...

Code
Select All
a = random(1000); 



Now if I want to set a conditional breakpoint on this line of code to break when (a > 500 && a < 700)  where would new users expect the breakpoint to be placed?
  
Back to top
IP Logged
 
uChip
Junior Member
**
Offline


Posts: 22
Location: Washington, USA
Joined: Apr 22nd, 2013
Re: Placement of Breakpoints
Reply #6 - Apr 27th, 2013 at 6:40pm
Print Post  
I think that the simpler case would also make your point.  If a new user wants to examine the assignment where would they set the breakpoint?  They would be focused on the assignment statement and would therefore be likely to click there.  The break would hit, but suppose the user examines "a" or wants to modify it.  If the break is before the statement then "a" would be the prior value (for discussion I'm assuming this is inside of Loop() ) at the time of the break which would be misleading for subsequent code.  If break is before and the user attempted to modify "a" their assignment would immediately be overwritten when they continued.

The reason I step back from the conditional break is that a new user is less likely to employ a conditional break.  Also, if the break doesn't hit (or hits on wrong values), I think the immediate fall-back would be to remove or simplify the conditional.  This simpler case would work and lead to what the debugger was really doing.

Note that just as in the "if" example either breakpoint behavior can be made to serve.  The user just has to know what the behavior is so they can set the breakpoint appropriately.

I spent some time trying to think of other examples to 1) see if there was a statistical preference for before or after and 2) see if there were any cases where useful behavior could not be implemented.  Here are the additional cases I thought about.  I'm sure you've thought about even more cases having had to implement them all.

   - Do {   -> like function name - before and after are equivalent
   - } While (...)   -> like "if" this favors break before if you credit my earlier argument
   - While (...) {   -> like "if"
   - For (...;...;...) {   -> like "if"
   - Switch (...) {   -> like "if"
   - Case   -> like function name, I think, but thinking about the Case value as an expression makes it like an "if"
   - }   -> like function name except when preceded by return(...); and then it's very confusing regardless of break before or after.

So one interpretation would be that statements that alter code flow generally favor break before (again, if you agree with my earlier argument).  Of course, expressions and assignments occur more frequently than code flow changes.

Another interpretation is that I could find no case where I could not achieve the break I wanted as long as I know if the break is before or after.  Does that mean this is much ado about nothing?  Wink

I think that language and documentation can help the experience be more intuitive.  We can speak of setting a breakpoint on a statement to examine its outcome (implicit after), or its inputs (implicit before).

I'm not sure I examined enough cases but it seems logical that it is true that there is no unreachable code using either break before or break after.  I am therefore left with consistency (with the host environment) as the only argument in favor of break before.  For those who use only Visual Micro in VS to get access to the debugger a consistency argument would have no weight.  For anyone who intends to switch back and forth between Visual Micro and desktop VS debuggers, difference in behavior is a pain-point to be avoided.

Interesting to contemplate.  Thanks for the opportunity to think and discuss the topic!

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Placement of Breakpoints
Reply #7 - Apr 27th, 2013 at 10:44pm
Print Post  
Actually it's not "much a do about nothing" it is something that has concerned me all the way through the debugger development. 

You are the first person to offer some detail to the argument. It helps a lot thanks  Smiley

Aside from your well reasoned arguments you make a good point about switching between vm and other windows dev. I think some experienced people have already hit this and thought it all broken or unacceptably unnatural.

I should have said earlier that I need to make a better code parser. This would allow to work out where syntax such as if {} statements start and end. Vs won't give me that level of detail so it is safer for me to find the first or missing brace than the last brace. I don't think it's that much work to make a string parser once someone tell me what to do  Smiley (to find the start and end of code blocks).

The rules do need to be clearly defined before changing things but the injected code is certainly an area that needs a v2 overhaul.

« Last Edit: Apr 27th, 2013 at 10:46pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint