dbstop in
当然你可以重载disp或fprintf,或者你可以告诉调试器使用dbstop停止这些功能.然后使用dbstack查看你的位置以及你是如何到达那里的.没有MATLAB代码就可以内置这些内容.它将在通话前停止:
>> dbstop in disp
Warning: MATLAB debugger can only stop in MATLAB code files, and "libmwbuiltins>disp" is not a MATLAB code file.
Instead, the debugger will stop at the point right before "libmwbuiltins>disp" is called.
>> dbstop in fprintf
Warning: MATLAB debugger can only stop in MATLAB code files, and "libmwbuiltins>fprintf" is not a MATLAB code file.
Instead, the debugger will stop at the point right before "libmwbuiltins>fprintf" is called.
看起来不错!
考虑以下带有嵌套函数fprintTest的测试函数testdbstop:
function testdbstop
x=1;
disp(x)
fprintTest(x)
function fprintTest(x)
fprintf('%d\n',x);
end
end
从命令行运行它:
>> testdbstop
3 disp(x)
K>> dbstack
> In testdbstop at 3
K>> dbcont
1
6 fprintf('%d\n',x);
K>> dbstack
> In testdbstop>fprintTest at 6
In testdbstop at 4
K>> dbcont
1
你有它 – 在testdbstop.m的第3行调用disp,在testdbstop> testdbstop的第4行调用的testdbstop> fprintTest中的testdbstop.m的第6行调用fprintf.
注意:完成后,使用dbclear删除虚拟断点(即db中的dbclear和fprintf中的dbclear).