Debug Generated Code During SIL Simulation
If a software-in-the-loop (SIL) simulation fails or you notice differences between the outputs of your original functions and the generated code, you can rerun the SIL simulation with a debugger enabled. By inserting breakpoints, you can observe the behavior of code sections, which can help you to understand the cause of the issue.
For a SIL simulation failure, you can also view information from the standard output and standard error streams in the Diagnostic Viewer. For example:
printfstatements in your code.
Error messages sent to
Some low-level system messages.
During a SIL simulation, the SIL application redirects the
stderr streams. When the application terminates, the Diagnostic
Viewer displays the information from the redirected streams. The SIL application also
provides a basic signal handler, which captures the POSIX® signals
SIGSEV. For this signal handler,
the SIL application includes the file
This table gives information about debugger support.
|Operating System||Supported Debuggers|
Microsoft® Visual Studio® IDE.
Visual Studio Code with MinGW® GDB. Requires installation of MATLAB® Coder™ Interface for Visual Studio Code Debugging support package, which you can download from MATLAB Central™ File Exchange.
Visual Studio Code with LLDB. Requires installation of MATLAB Coder Interface for Visual Studio Code Debugging support package, which you can download from MATLAB Central File Exchange.
GNU® Data Display Debugger (DDD).
Visual Studio Code with GDB. Requires installation of MATLAB Coder Interface for Visual Studio Code Debugging support package, which you can download from MATLAB Central File Exchange.
You can perform SIL debugging only if the Simulink® product family supports your Microsoft Visual C++®, Xcode, or GNU GCC compiler. For more information, see supported compilers.
To enable your debugger for a SIL simulation, perform one of these actions:
On the SIL/PIL tab, click Settings > SIL Debugging.
In the Configuration Parameters dialog box, select the Enable source-level debugging for SIL check box.
If your top model has Model blocks, the Enable source-level debugging for SIL parameter for the top model overrides the corresponding parameter for referenced models.
When you run the SIL simulation, your
file opens, for example,
in the Microsoft
Visual Studio IDE with debugger breakpoints at the start of the
You can now use the debugger features to observe code behavior. For example, you can step through code and examine variables.
To end the debugging session:
Remove all breakpoints.
The SIL simulation runs to completion and the Microsoft Visual Studio IDE closes.
In the Microsoft Visual Studio IDE, if you select Debug > Stop Debugging, the SIL simulation times out with the following error message:
The timeout of 1 seconds for receiving data from the rtiostream interface has been exceeded. There are multiple possible causes for this failure. ... ...