Breakpoint is cleared w/o using "clear all"
Afficher commentaires plus anciens
Hello,
I am using MATLAB R2014a, 64 bit. Recently I often have troubles using breakpoints. It happens, I set a breakpoint somewhere in a function and when I call this function, MATLAB does not stop at the breakpoint, but runs further. When I then stop the execution and check the breakpoint it is gone. I am aware of the fact that "clear all" clears breakpoints as well. So I always make sure, there is no "clear all" somewhere. Sometimes it helps to close MATLAB and re-start it.
Thanks for any advice,
BG
3 commentaires
Morten Haastrup
le 16 Juin 2015
Hi, When I'm debugging a program the second time without changing anything, all breakpoints are cleared. I have made sure that there is no "clear all", not even a "clear". A workaround is to add a space and delete it again just so that MATLAB thinks the program has been changed. Is there any permanent solution to this? Some setting that can be changed? Best regards Morten
Sean de Wolski
le 24 Juin 2015
Morten, are they grayed out until you add/remove space? There was a setting that changed in 14b I believe that now automatically saves files, but it does not do this if you're in debug mode. I've seen this happen a few times there where the breakpoints are there but disabled because the file is not saved.
DrLoz
le 12 Avr 2017
Re starting matlab is what I do to fix the "feature" (bug) unfortunately. Not ideal but it works
Réponses (4)
Sean de Wolski
le 21 Août 2014
Modifié(e) : Sean de Wolski
le 21 Août 2014
My guess is you are unknowingly calling clear all or possibly dbclear all :(.
To find out, one thing you can do is overload clear temporarily and put a break point in it.
function clear(varargin)
dbstop in clear at 3
1;
1;
end
Now the debugger will stop in this clear when it's called and you can look at the call stack to see where the offending clear all came from. Be sure to rename or delete this file afterward.
The other thing that could be happening is that the file could be getting removed from the path (changing directories or explicitly modifying the path). This can clear it's breakpoints as well.
2 commentaires
Sean de Wolski
le 21 Août 2014
A workaround is to use "dbstop in file at line" in the code like I did above. That way, even if the breakpoint is cleared, it will be re-instantiated at that line.
Image Analyst
le 21 Août 2014
0 votes
"clear all" does not clear breakpoints, despite what the documentation erroneously says. Just try it in a simple 2 or 3 line script to prove it to yourself.
My guess at what you're seeing is an undocumented "feature" in GUIDE. If you're using GUIDE to create your GUI, and then save some small change you made, then it will remove all breakpoints that you've set up in your m-file. If you're running from GUIDE, rather than MATLAB, it may save automatically. Another annoying feature is that saving from GUIDE also removes any bookmarks you've set in the file you're saving.
There is another case where it won't stop at your breakpoints and that is when you set breakpoints in a GUIDE-generated function that gets called from your first function. Like you set a breakpoint in the OpeningFcn of fun2, and you run fun1 which calls fun2. It won't stop at the breakpoint in fun2. Mathworks knows about that feature/bug. Not sure if it has been fixed in R2014 yet - I haven't checked.
8 commentaires
Sean de Wolski
le 21 Août 2014
Huh? clear all certainly does clear breakpoints. I've never seen otherwise and can't reproduce it now.
Image Analyst
le 21 Août 2014
Make a 4 line script called test.m or whatever. Put these lines in it:
clear all;
fprintf('Starting %s...\n', mfilename);
pwd
fprintf('Done with %s\n', mfilename);
Put a breakpoint on the pwd line, line #3. Click the green triangle to run the script. The execution WILL stop at the breakpoint. The breakpoint is still there - it did not get cleared due to "clear all" being the first line in the script. Do you observe anything different?
Adam
le 21 Août 2014
clear all
on the command line clears breakpoints.
Image Analyst
le 21 Août 2014
Yes, but not if "clear all" is in your script or function.
Jan
le 21 Août 2014
In Matlab R2009a and 2011b, clear all removes the break points, when it is called from the command line, inside a script an insider a function also.
But as Image Analyst says, if the breakpoint appears in a function or script, the breakpoint remains active until the function returns. Then the breakpoint disappears in the editor. Breakpoints in other functions are removed immediately.
Image Analyst
le 21 Août 2014
Yes, that's exactly what I observe in R2014a also. Breakpoints are active until you're all done. Thanks for clarifying it. I'll admit that it can be confusing, and seemingly inconsistent, about when and where clear all removes breakpoints.
mary
le 22 Août 2014
Image Analyst
le 22 Août 2014
Is it possible that you're running one m-file, and then after mfile1 is running, you go into the editor and set a breakpoint in mfile2 that mfile1 calls? Because that's another situation where it might not stop at the breakpoint. It seems you have to save any mfile where you set a breakpoint unless you're running and in it already. For example if you stopped at a breakpoint in mfile1 you could set another breakpoint in mfile1 without saving it, but it won't stop at any breakpoints in mfile2 unless mfile2 is saved (and I'm not sure it will do any good to save mfile2 after mfile1 has started running, it might have to be saved before mfile1 starts - I'd have to check on that).
per isakson
le 22 Août 2014
Modifié(e) : per isakson
le 17 Juin 2016
0 votes
I believe that you are seeing a bug in Matlab.
I experience problems with breakpoints on a regular basis (in R2013a and older releases). Restart of Matlab is the only remedy, (that I found). I have never been able to reproduce the problem such that it is meaningful to report to tech-support.
If I ignore this behavior and continue to use Matlab there is risk that Matlab eventually crashes.
PS. I never use GUIDE.
4 commentaires
mary
le 22 Août 2014
per isakson
le 22 Août 2014
"Sometimes it helps to close MATLAB and re-start it."   Doesn't it always help?
per isakson
le 23 Août 2014
Modifié(e) : per isakson
le 23 Août 2014
"MATLAB is likely to crash"   No, I didn't mean to convey that meaning. I deleted the word "significant" in "significant risk".
Nearly all my unexplained crashes occur when I'm debugging and very often they are preceded by malfunctioning breakpoints. Such crashes may occur once a month or something, depending on whether I listen to the warnings or not.
Yair Altman
le 4 Sep 2014
I envy you per - I crash or hang Matlab several times a day...
Then again, I'm not known for working with run-of-the-mill code... :-)
Aaron Thrasher
le 16 Juin 2016
0 votes
I know this is an old post, but as I see that there are still recent viewers I figured its worth sharing.
I am running on 14b and I experience this issue on a constant basis. I recently spent some time investigating it on my own and I have found a quick and easy solution. If you close and reopen the file in the editor window, the problem goes away. This suggests that somewhere Matlab does not think it is saved for whatever reason. Clearing the break point is probably a safety measure built in. I'm thinking the bug exists within the method of saving the m-file that instead of turning a grey dot red it doesn't do anything, but this means it doesn't update its underlying skip break point action. Since saving has to do with the .asv file, closing the m-file in the editor clears this file. I've tried to implicitly reproduce the error and not been successful, but I hope this helps people experiencing the issue and Matlab to find the bug if it hasn't already been found in later versions of matlab already.
2 commentaires
Ray Maynard
le 14 Oct 2016
Thanks Aaron, tried this in 2014b but no luck, still ran but ignored the breakpoint. I did notice though, that it acknowledges the breakpoints when I do a full run (f5) whereas it ignores them when I run sections (ctrl + enter). Maybe there's something to that, in combination with what you mentioned.
Steven Lord
le 14 Oct 2016
Catégories
En savoir plus sur Whos dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!