MATLAB Answers


Debugging C S-Functions called from simulink using Visual Studio Code

Asked by Tony
on 21 Mar 2019
Latest activity Commented on by claudio trinca on 30 Oct 2019 at 14:05
Dear all,
I would like to be able to debug an s-function written in C using Visual Studio Code. I was able to debugg a C code called directly from matlab window, however, following the same instructions, I was not able to debug a C code when called from simulink. What extra steps should be taken? Thank you very much.


Sign in to comment.

1 Answer

Answer by Mark McBroom on 22 Mar 2019
 Accepted Answer


Show 1 older comment
Hello Tony,
I'm facing your same issues. I have a C++ S-Function that I want to be able to debug using Visual-Studio 2017
As you said basically you need to give the command "clear mex" as most as you can...
I confirm that sometimes VisualStudio intercepts some exceptions such as:
Exception thrown at 0x000000004A95E95F in MATLAB.exe: 0xC0000005: Access violation reading location 0x000000000E3E0000.
in this case I ... reattached the process MATLAB.exe but then when running the model the break point in VisualStudi was "not working/blocking" -> so I did "clear mex" in the matlab command window... then break point works was blocking correctly the execution of the model when running It.
The fact is that I cannot re-establish the correct working condition in VisualStudio with the breakpoints working correctly after I open the Simulink Test-Manager:
I started TEST-MANAGER and in Visual-Studio intercepted the following exception
Exception thrown at 0x000000004B1C61F1 in MATLAB.exe: 0xC0000005: Access violation reading location 0x000000000E3E0000.
I had to stop being attached to the process otherwise could not see the model window (the Simulink window was forced kept in back-ground)
"clear mex"
attached to process....
tried everything but could not block on breakpoints in VisualStudio while debugging
You should be able to ignore VS exceptions. When the exception window comes up, click the box that allows you to ignore and the hit the Continue/Run button in VS.
Hi Mark,
thank you the quick response.
the important thing that happens to me is that I can use correctly the brealpoints if I run the model from the Simulink "play" button but if instead I launch Test-Manager and run the model from the Test-Manager user interface the break-points that I set in VisualStudio while debugging the C++ S-Function are skipped
If you want I have a simplified model that I've attached in the ZIP file
In the ZIP file there is also the TestManager file so you can try to launch It and check if you can make the breakpoints work

Sign in to comment.