How to add breakpoints when I am pausing a running code

조회 수: 8 (최근 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 CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by