MATLAB Answers

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

46 views (last 30 days)
Tony
Tony on 21 Mar 2019
Commented: claudio trinca on 30 Oct 2019
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.

  0 Comments

Sign in to comment.

Accepted Answer

Mark McBroom
Mark McBroom on 22 Mar 2019

  4 Comments

Show 1 older comment
claudio trinca
claudio trinca on 29 Oct 2019
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
Mark McBroom
Mark McBroom on 29 Oct 2019
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.
claudio trinca
claudio trinca on 30 Oct 2019
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 20191023_example_Sfunction.zip
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.

More Answers (0)

Sign in to answer this question.