MATLAB Answers

Tony
0

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

Asked by Tony
on 21 Mar 2019
Latest activity Commented on by Tony
on 26 Mar 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.

1 Answer

Answer by Mark McBroom on 22 Mar 2019
 Accepted Answer

  1 Comment

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?

Sign in to comment.