In general, you run the mex
command with the -g
option, and depending on your OS, either attach to MATLAB (Visual Studio in Windows) or start the debugger with the matlab
startup script (e.g. matlab -Dgdb
in Linux). Use these detailed instructions for your own MEX files.
However, for LIBSVM, you are provided with make.m
, which can be used to build in any supported OS, and Makefile
for use in Linux only. The Makefile is used for building the MEX files outside of MATLAB (i.e. without using mex.m
, but instead a shell script in $(MATLABDIR)/bin/mex
). In Windows, you need to edit make.m
and add the -g
option to each mex
call:
mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims -g libsvmread.c mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims -g libsvmwrite.c mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims -g svmtrain.c ../svm.cpp svm_model_matlab.c mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims -g svmpredict.c ../svm.cpp svm_model_matlab.c
Then, in MATLAB, run make
(the modified make.m). Start Visual Studio, set one or more break points, and from the Debug menu, "Attach to Process...". Now you can run the MEX functions (e.g. svmtrain
) and it will stop in Visual Studio when it hits the break points.
Just for completeness, if you were using Linux and wanted to go the Makefile route, just change the following line to build debug versions of the code:
MEX_OPTION += -largeArrayDims -g