Codementor: Debug VLfeat’s Mex files in Visual Studio Community 2013 edition and Matlab release 2013a

It is highly recommended to go through this tutorial once. If you don’t know much about Mex files, please refer to this tutorial once. However it is not necessary. You’d be able to follow this entire tutorial without even knowing much about mex files. But it’d seem less magical if you refer to that link. 🙂

  1. Download Vlfeat.
  2. Inside downloaded folder, navigate to vl_compile.m inside the toolbox folder.
  3. In vl_compile.m find this snippet:
cmd = {['-I' toolboxDir], ...
 ['-I' vlDir], ...
 '-o', ...
 '-outdir', mexwDir, ...
 filePath } ;

Replace -o flag with -g flag: [no optimization but debugging instead] i.e.

cmd = {['-I' toolboxDir], ...
 ['-I' vlDir], ...
 '-g', ...
 '-outdir', mexwDir, ...
 filePath } ;
  1. Compile Vlfeat source using vl_compile command. i.e In Matlab command window, navigate to folder which contains vl_compile.m and run vl_compile.

  2. It takes a while to compile all the CMEX source files. Meanwhile you’d find a brand new folder named mex inside the toolbox folder. This mex folder contains all the mex binaries which are needed to use Vlfeat’s Matlab interface. Since I am using Windows x64 platform, folder named mexw64 is the one I should be looking into.

Note: You might not be able to run vlfeat Matlab commands even after compiling. You might run into some errors. I’ve made a list of those errors and their solutions which worked in my case.

  1. Inside mexw64 (Choose folder according to the platform you’re working on), you’d find pdb [Program Debug database] files alongside mex binaries. These are the files which contain the debug information and hence used by Visual Studio later while debugging.
    Note: When you don’t use -g flag, no pdb files are formed.

  2. Now you’re all set to debug.

Start Visual Studio (VS) [Don’t terminate your Matlab session]. In VS, navigate to tools, select Attach to Process and select MATLAB from the list.

  1. Open file that you wish to debug in VS. In my case it was vl_siftdescriptor.c. So I navigated to sift folder inside toolbox folder and opened vl_siftdescriptor.c

  2. Set breakpoints on desired locations.

  3. From Matlab command window run vl_siftdescriptor with proper arguments. You’d be navigated to VS when the first debugger hits first breakpoint.

Just for the sake of this tutorial, I am pasting the exacts commands which I used to run vl_siftdescriptor in Matlab:

I1 = im2single(imread('lena.png'));
I_ = vl_imsmooth(I1, sqrt(F(3)^2 - 0.5^2)) ;
[Ix, Iy] = vl_grad(I_) ;
mod = sqrt(Ix.^2 + Iy.^2) ;
ang = atan2(Iy,Ix) ;
grd = shiftdim(cat(3,mod,ang),2) ;
grd = single(grd) ;
vl_siftdescriptor(grd, F);


P.S: Just in case if you still can’t debug in VS.
In my case, this link helped a lot!

Also found at : Codementor: Debug VLfeat’s Mex files in Visual Studio Community 2013 edition and Matlab release 2013a

Post author

Dustin Gurley is an Designer, Developer, Artist, Instructor, Critical Theorist and Systems Engineer. He has an extensive background working professionally with 2D/2.5D/3D Motion Graphics, Compositing, Film, Video, Photography and client-side performance techniques as it pertains to web development. Dustin recently completed work on his Master of Fine Art degree in Motion Media Design (Motion Graphics) from the Savannah College of Art and Design. Prior to beginning his graduate work, Dustin obtained a Bachelor of Art degree in Communication Studies with a concentration in Broadcast and Emerging Media from the University of North Carolina at Wilmington. In addition to design and modeling, Dustin enjoys toying with his view camera, working with scratch film, authoring media related material and contributing to various industry conferences. When not in front of a computer, Dustin can be found with his wife, Regina Everett Gurley. The couple enjoys dividing their time between their home just outside of Raleigh, North Carolina and the beautiful North Carolina coast. Currently, Dustin serves as the Lead Instructor of Internet Technologies for Wake Technical Community College in Raleigh, North Carolina.