Skip to content

Instantly share code, notes, and snippets.

@rkwitt
Last active December 14, 2015 14:58
Show Gist options
  • Save rkwitt/5104192 to your computer and use it in GitHub Desktop.
Save rkwitt/5104192 to your computer and use it in GitHub Desktop.
Exemplary steps to debug segfaulting .mex* files in MATLAB (on a Linux platform)
1) Compile your code (using mex) with -g flag
2) Call gdb via MATLAB's 'matlab -Dgdb' functionality
3) Set a breakpoint for instance by 'break testfile.cpp:9'
3) Run MATLAB without the JVM by 'run -nojvm'
4) Now, run the segfaulting mex function
5) Get a backtrace via 'bt' and use your debugging magic
Example:
$ cd '/mycode/
$ mex -g testfun.cpp
$ matlab -Dgdb
>> break testfun.cpp:20
>> run -nojvm
>> testfun
...
(Now the segfault happens)
>> bt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment