Questions: (full description of problem is below)
- Does anyone have a suggestion on how to trick Matlab into skipping a line or several lines of code? (mex / java / rewriting some internal Matlab features?)
- Does anyone know where
db*
code files may be located (if exist)?
There are several functions in Matlab that allow flow-control while debugging / running a program: dbstop
, dbcont
, dbstep
, etc... I was trying to find a db*
function that would skip the next line in a Matlab script, dbskip
perhaps, but sadly there is no such builtin functionality and it doesn't seem like this feature going to be ever implemented (10 years and counting).
EDIT example of use:
The following script, myScript
, may call a function myFunc
which decides on whether to skip the next line in the caller script based on the value of its input, like so:
% myScript.m
x = 1;
myFunc(x);
x = 2;
x = 3;
% myFunc.m
function myFunc(u)
if u == 1
% skip next line in caller -- how to?
% ... do more stuff ...
else
% ... do other stuff ...
disp('Business as usual.')
end
% ... do even more stuff ...
end
EDIT
One way of achieving this, as @Michael Smith suggested, is to write a program that would read myScript.m
and execute it line by line skipping any line that is specified at runtime. I believe that this solution is a good start; however, in more complex cases, there would be function calls within function calls. So, making a truly general solution using this approach, would require writing a full blown Matlab code interpreter having all the capabilities that Matlab has plus some of my own requirements. This is something I would like to avoid if I can use some of Matlab's inherent reflective capabilities or by hacking into the debugging system.
In the meanwhile, I hit another wall trying to find how and where dbstep
is implemented. When debugging any of thedb*
functions the result is the following error:
Error using <db*>
Debug commands only allowed when stopped in debug mode.
The only dbstep.m
file I could find, contains documentation without any code so I assume that it is a compiled built-in.