I am trying to write my version of Matlab's debug step command dbstep
, that is I want to do dbstep and some other things, in a single call. However, putting dbstep
into a function does not work:
% in file my_dbstep.m
function my_dbstep()
evalin('caller', 'dbstep');
When I call my_dbstep
while in a debug session, it acts as if I typed dbstep
inside the function, and not in the caller.
Is there another solution?
The solution I found is to use a mex file, from which I can call a function in Matlab to do stuff I want each time I step a line in debug mode (using this new dbstep2
mex file), followed by a call to dbstep
from the mex:
// file dbstep2.c
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
mexCallMATLAB(0,NULL,0, NULL, "do_some_stuff");
mexCallMATLAB(0,NULL,0, NULL, "dbstep");
}
In my case, I use the do_some_stuff
function to send key strokes to vim while debugging in Matlab (no gui), so the current line is highlighted in the script which is opened in vim. Of course it can be used to any other use case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With