필터 지우기
필터 지우기

detect debug mode

조회 수: 9 (최근 30일)
Ronan
Ronan 2011년 7월 13일
댓글: Adam Danz 2020년 8월 30일
is there a way to tell if your function has been called from the "k>>" debug prompt instead of the normal ">>" prompt?
Something like an "isdebug()" function??
Thanks
Ronan

채택된 답변

Daniel Shub
Daniel Shub 2011년 7월 13일
I don't think there is a robust way to tell. For example, you can get the "k>>" prompt with a keyboard command and I have no idea how to tell if the keyboard command has been called.
If you just want to tell if you are at a standard break point you can probably check each item in dbstack against the breakpoints returned by dbstatus.
  댓글 수: 1
Ronan
Ronan 2011년 7월 13일
Thanks Daniel
If there really is no builtin way then comparing the outputs of dbstack an dbstatus is a good suggestion. Can anyone foresee and problems with this??
R

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Jan
Jan 2011년 7월 13일
You can use this to determine, if Matlab is currently in debug mode:
feature('IsDebugMode')
This replies 1 in debug mode, 0 otherwise. This is not documented and can change with the Matlab version.
  댓글 수: 3
Ronan
Ronan 2011년 7월 14일
Thanks Jan.
Just what I was after.
Ronan
Adam Danz
Adam Danz 2020년 8월 30일
Unfortunately, this solution no longer seems to work (r2019b) unless the call to feature or system_dependent is invoked by "Evalulate Selection" (F9).
function test()
clc()
feature('IsDebugMode')
system_dependent('IsDebugMode')
end

댓글을 달려면 로그인하십시오.


Julian
Julian 2015년 10월 9일
I also needed an answer to this question! I was pleased just now to find here on Answers that feature('IsDebugMode') does the trick. Before turning to Answers I was looking in the MATLAB help, and came up with this alternative:
try
dbup % try going up the stack frame, works if in debug mode
dbdown % back to where we started
isDebugMode = true;
catch ME
assert(strcmp(ME.identifier, 'MATLAB:dbOnlyInDebugMode'))
isDebugMode = false;
end
Although the undocumented feature() is much neater, this is an alternative if you want to stay on official MATLAB.
  댓글 수: 1
Adam Danz
Adam Danz 2020년 8월 30일
This solution fails in r2019b (I haven't tested it in earlier versions).
Debug commands are only supported when stopped in debug mode so when they are executed from within a script/function as you step through it in debug mode, it will cause an error the same error as when it's invoked from outside of debug mode ('MATLAB:dbOnlyInDebugMode').

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by