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

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.

 채택된 답변

Mark McBroom
Mark McBroom 2019년 3월 22일

0 개 추천

댓글 수: 4

Thank you very much for the link, Mark! To test this, I have downloaded the visual studio community 2017 with a trial of the MATLAB 2019a, running the example timestwo.c, as suggested by the tutorial. The C S-Function was indeed debugged. Howevere, some points must be taken in consideration:
  • After I attach the VS Community to MATLAB.exe process,running simulink model for the first time causes an exception to be thrown in Visual Studio Code (some exception caused by jvm.dll, which I just ignore by clicking continue on Visual Studio and everytihing goes on normally)
  • Whenever the breakpoint did not stop when the simulink model is run, I needed to typ "clear mex" in the MATLAB window and rund the simulink again.
  • I was not able to edit the code and compile it again using "mex -g timestwo.c" while MATLAB was attached to Visual Studio. Even while running as administrator. Everytime I needed to edit the code, I would need to stop debugging, edit whatever I needed, compile it and type "clear mex" before attaching again and debugging it.
  • I have had the degugging simulink C S-Funcitons before in MATLAB 2015b, Windows 7 (SDK 7.1) and Visual C++ Express 2010. Seemed a lot more friendly and less complicate
Also, I am trying to be able to use Visual Code instead of Visual Studio Community, since I would like to use the same license also in a Mac (not simultaneously, off course), and the Mac version of the visual studio community does not contemplate C++ as far as I know. I have tried to compline C S-Functions in a mac with Visual Studio Code, but whenever simulink opens, it is the same as if a break point was hit and the debugger stops with some thread number showing up at the conole. I was able to overcome this problem with the MATLAB window, but the same command does not seem to work for the case of simulink. Would you know any solution for this problem?
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 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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Manual Performance Optimization에 대해 자세히 알아보기

제품

질문:

2019년 3월 21일

댓글:

2019년 10월 30일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by