This is a simple example to debug binary mex files compiled by Matlab.

I am going to use Gdb, and Matlab without UI.
You can apply this trick with LLDB on MacOS X, and also with GDB on any Linux platform. 

Binary Setup

The only thing you need to do before running a debugger is to compile the target binary with -g option.

>> mex -g target.c

As most developers knew, '-g' option means to add symbols' information and their location in the source code into the output binary in compile time.

Start Matlab with GDB enabled.

In terminal, 

$> matlab -Dgdb 
(gdb) run -nojvm

With -Dgdb flag, matlab will be run only after you enter 'run' command in GDB prompt. '-nojvm' option would let you debug your source faster.

Run the target command and find out what was going wrong

>> dbmex on
>> target( 1, 2, 3);
(gdb) b mexFunction
(gdb) run

In general, setting a breakpoint at the symbol, 'mexFunction', implies that debugger is going to stop at the very beginning of the routine.

Then enjoy debugging!

[ref1] Instruction page on Mathwork homepage.

저작자 표시 비영리 변경 금지

'Development > comSim' 카테고리의 다른 글

How to debug a C-MEX file on MacOS X  (0) 2014.12.26

티스토리 툴바