How to add breakpoints when I am pausing a running code

4 ビュー (過去 30 日間)
Runcong Kuang
Runcong Kuang 2022 年 11 月 7 日
コメント済み: Walter Roberson 2022 年 11 月 9 日
I add breakpoint in the debugging mode when pausing a running code.
But it's grey. It gets ignored. Continue running the code will not stop at my grey breakpoint.
The code piece under is in a loop. I know line 459 will repeatedly execute in the loop. I verify by pausing it several time and it will stop at line 459 sometimes.
I find a video doing the same thing as I do but the breakpoint is red in that video. https://www.mathworks.com/videos/pause-to-add-a-breakpoint-1487283318236.html
I am using matlab R2021a.
So please help.

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 11 月 8 日
A file that is modified but not yet written will have the breakpoints show up in gray until the file is written out.
If I understand correctly, breakpoints set that way are somehow handled internally by modifying the file, and somehow it needs the file saved to disk to do that.
Historically I have seen cases where I was not able to set a breakpoint in a file I did not have write access to. I have not seen that behaviour for a while -- these days I am generally able to set breakpoints in any file that is not been changed since the last write to disk.
  2 件のコメント
Runcong Kuang
Runcong Kuang 2022 年 11 月 8 日
Thanks for pointing this out.
I think because the code is running, I cannot save the file after adding breakpoint in the debug mode.
Are you talking about non-debug mode behavior?
I am focusing on the debugging mode now because I already started run my code and it has been run for 2 weeks. I want to find out what the problem is in my loop.
Walter Roberson
Walter Roberson 2022 年 11 月 9 日
Several releases ago, MATLAB changed the editor to add a Pause button in the editor (it is present in your release.) In the time since then, as long as I am able to get an editor session onto a file, and the file does not have any uncommitted edit changes, then I have been able to add breakpoints while the code is running.
While the code is running, if you have an edit session open, you should be able to click on the pause button. The pause should take effect the at the beginning of the next MATLAB line of code that is executed (or if the code returns to the command line for some reason.) That is MATLAB source line at any level -- if for example you called cell2mat() then because that is written in MATLAB itself the code can stop in cell2mat(); it does not have to stop in "your" routine.
The flip side of this is that if the code is processing something extensive for the Symbolic Toolbox, or is processing a large matrix using the external fast-mathematics routines in MKL or LAPACK, or is executing a mex file, or is calling into an DLL or is swapping memory to disk... then it can be rather a long time before the next MATLAB source line is ready for execution.
At the times that MATLAB is busy for the above kinds of reasons, you might have difficulty using the editor menu to open a file. I have had difficulty going through the editor menus in any case in which the editor needs to check to see what files are available -- but if the file I want is in the Recently Used list then it become easier. So you can accidentally end up stuck not being able to open any relevant file to put in breakpoints.
When you are getting the graying breakpoints, those are breakpoints that are not active yet, either because the file has not been written out since the last change, or because the breakpoint was placed more recently than the last time MATLAB execution engine was in a state to accept breakpoints.
I do not know how breakpoints are handled internally these days. There was a time at which the debugger GUI interface sent "dbstop" commands to the command window.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by