Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling dbstep from a function

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?

like image 916
Itamar Katz Avatar asked Nov 10 '22 10:11

Itamar Katz


1 Answers

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.

like image 131
Itamar Katz Avatar answered Nov 15 '22 08:11

Itamar Katz