Using Visual C++ attached to Matlab session to debug mex function but local variables are wrong.

When I attached the Visual C++ 2010 Express to R2011b and then set a breakpoint inside the source for a complied mex function I expected the locals window to show values of variables defined in the function scope. Some are there but wrong and others are missing - like a variable defined by "int function_id;" for example. This is the first time I have tried this so I assume I am missing some large concept. It seems like it should work. What do I need to do or need to understand? The compiler selected by mex -setup is the Visual C++ express.

6 Comments

aha maybe not - where do I find the compiler options? Here is the cmd line for compiling: cl -DDEBUG -D__MSCVC_ /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD /FoC:\Users\enestler\AppData\Local\Temp\mex_WLhZS8\mex_beamform.obj -I"C:\Program Files\MATLAB\R2011b\extern\include" /Z7 /O2 /Oy- /DNDEBUG -DMX_COMPAT_32 c\mex_beamform.c
Also there seems to be an issue with 32bit vs 64bit for the Visual C++ mode that I do not understand.
I mostly compile mex files in Matlab itself where the -g option adds the required debug information.
When I compile in Visual Studio I don't seem to remember doing much beyond setting up the correct combinations in the Configuration Manager to build correctly in either debug or release mode for x64 or Win32 (not in my case), but it is a while since I setup such a project so I may be wrong.
Thanks for replying Adam. So I am compiling also in Matlab. The cmd is: mex -DDEBUG -g -v -compatibleArrayDims -D__MSCVC_ -O -output bft c/mex_beamform.c I do have the -g option. I am trying to use the Visual Studio to debug a memory issue. I am using the Visual Studio C++ Express that I attached to Matlab and put in a breakpoint right after the entry into the mex function. I'm pretty sure this is about 32bit vs 64bit. Maybe int versus size_t and casting, etc. But I'm not a skilled C programmer let alone C++.
You may need the
-largeArrayDims
option instead of -compatibleArrayDims. This is a problem I had on first building mex when using size_t's, but again this is a good few months ago so I can't remember the exact details. I do remember reading the mex documentation and deciding that largeArrayDims was the option I needed though.
Thanks Adam - I seem to be making progress now. Eric

Sign in to comment.

Answers (0)

Asked:

on 15 Sep 2014

Commented:

on 15 Sep 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!