1
votes

I have a Simulink model that uses an s_function, which is a mexw32 file. The s_function block uses a .lib module as well. Now, when I'm trying to run the model Matlab crash before the simulation end and without any errors in the command window. What are my options for debugging if Matlab crash?

2
When you say MATLAB "crashes", what do you mean? You say it doesn't return an error in red at the MATLAB command line - does it give some other form of error, such as a SEGV crash dump, and then exit? Does MATLAB itself just disappear?Sam Roberts
@SamRoberts Matlab freeze and there is a windows that appears : MATLAB has stopped working, Check online for a solution, Close the program. If i click on View details, Problem Event Name = APPCRASH. I'm unable to understand the rest.m_power
What OS are you using?Sam Roberts
@SamRoberts Windows 7 Enterprise x64, with Matlab R2010a 32 bit. The mexw32 were compiled with VS C++ 2010 express.m_power
I assume that the other DLL module is also 32-bit, right? cause you cant mix 32/64 bit libraries in the same process...Amro

2 Answers

1
votes

This is typical behaviour of a badly written S-function that is causing a seg-fault. Debug it using the steps outlined at: http://www.mathworks.com/support/solutions/en/data/1-3KK6RK/

1
votes

I dont know about Simulink or S-functions (never used them), but usually when a MEX-file segfaults, MATLAB will recover from it most of the times, showing a stack trace and placing you in the "you need to restart MATLAB" command prompt mode. You'll find a crash dump and error log files in the system %TMP% folder.

As other have said, if you have access to the source code of the MEX-function, recompile it with debugging symbols, attach a debugger to MATLAB, place breakpoints in the debugger, and initiate the MEX-function by calling it from MATLAB. Once inside the C code, debug it code step by step until you find the problem.

Here is the relevant doc page describing this process in more details.


You mentioned that your MEX-executable is linked against an external library. So you might also want to check that for the source of the problem.