Main Content

Debug FMU with Source Code Using External Debugger

This topic shows how you can debug an FMU that contains its source code by launching an external debugger from Simulink.

It is recommended that you use Visual Studio Code for debugging your FMU on Linux®.

You will need to install MATLAB® Coder™ Interface for Visual Studio® Code Debugging support package to debug FMU if you are using Visual Studio Code.

  1. Ensure that a compatible C/C++ compiler is installed on your system. Run mex -setup C in the MATLAB command line to check and select a compiler.

  2. Use the fmudialog.compileFMUSources function in the following command to generate debugging information on a specific platform for the FMU that contains sources code:

    fmudialog.compileFMUSources(fmuDir, 'DebugMode', 'on')
    This function repackages your FMU with debugging information.

  3. Add the FMU to Simulink® and compile your model to check if the FMU is imported.

  4. On the Debug tab in Simulink, select Set Breakpoints in Custom Code option to open the Select Entities to Debug dialog box, which lists entities that can be debugged.

    Debug tab with Set breakpoints in Custom Code option

  5. Select the FMU under FMU Blocks and move it to Selected Entities.

    Select Entities to Debug window with FMU

  6. Click Open to launch the external debugger.

  7. Set breakpoint on the desired line of code in the source code of your FMU in the external debugger.

    Note

    If you are using DDD in Linux, you must first simulate the model before setting the breakpoints.

  8. Start the simulation of the model on Simulink. The simulation pauses when you hit the breakpoint. Continue to move to the next time step.

See Also