2

I have a question related to debugging .mex32/.mex64 files. Suppose now I have a file named test.cpp:

#include "mex.h" 
#include <iostream>
void mexFunction(int nlhs, mxArray *plhs[],
    int nrhs, const mxArray *prhs[])
{
    mexPrintf("Hello Matlab, and this is a test program\n"); 
} 

I can then compile and build test.mex64 with Visual Studio 2010.Then in matlab, I can write the following script to test the function:

clc; 
test;

Now suppose I want to debug the test.mex64 function, what should I do? The have adopted the following procedure, but failed:

  1. Toggle break point at the begging of the line mexPrintfwith VS2010.
  2. With VS2010 from Debug->Attach to Process... select MATLAB.exe.
  3. Run MATLAB script clc; test;

The error message I have obtained is as follows:

The breakpoint will not currently be hit. No symbols have been loaded for this document. 
feelfree
  • 11,175
  • 20
  • 96
  • 167
  • You might want to look at [this question](http://stackoverflow.com/questions/11220250/how-do-i-profile-a-mex-function-in-matlab/12405131#12405131). It deals with profiling mex on Linux, but similar ideas should be used on Windows. Admittedly, profiling is a bit different, but you may start there. – angainor Nov 28 '12 at 19:19

2 Answers2

1

Did you build your mex file with debug option "-g"?

Navan
  • 4,407
  • 1
  • 24
  • 26
1

I have found the solution: when I created the .mexw64 function (test.mexw64 in our case), I copied it to the MATLAB work directory. In order to debug this function, it is important to copy test.pdb file to the MATLAB work directory as well. After doing that, I can debug.

feelfree
  • 11,175
  • 20
  • 96
  • 167