Debug Generated Code During SIL or PIL Execution - MATLAB & Simulink (original) (raw)
Main Content
If a software-in-the-loop (SIL) or processor-in-the-loop (PIL) execution fails or you notice differences between the outputs of your original functions and the generated code, you can rerun the execution with a debugger enabled. By inserting breakpoints, you can observe the behavior of code sections, which might help you to understand the cause of the problem.
For a SIL or PIL execution failure, you can also view information from the standard output and standard error streams in the MATLAB® Command Window. For example:
- Output from
printf
statements in your code. - If you enable run-time error detection, messages sent to
stderr
. - Some low-level system messages.
Note
During a SIL execution, the target application redirects thestdout
and stderr
streams. When the application terminates, the MATLAB Command Window displays the information from the redirected streams. The target application also provides a basic signal handler, which captures the POSIX® signals SIGFPE
, SIGILL
,SIGABRT
, and SIGSEV
. For this signal handler, the target application includes the filesignal.h
.
SIL Debugging
This table gives information about debugger support.
Note
You can perform SIL debugging only if the MATLAB product family supports your Microsoft Visual C++®, Xcode, or GNU GCC compiler. For more information, see supported compilers.
To run a SIL execution with debugging enabled:
- On the Generate Code page, click Verify Code.
- Select the Enable source-level debugging for SIL or PIL check box.
- Click Run Generated Code.
On a Windows computer, your _`userfn`_.c
or _`userfn`_.cpp
file opens, for example, in the Microsoft Visual Studio IDE with debugger breakpoints at the start of the_userfn
_initialize
anduserfn
_ functions.
You can now use the debugger features to observe code behavior. For example, you can step through code and examine variables.
When using a dynamic link library (DLL), Microsoft Visual Studio applies two breakpoints per function breakpoint for SIL debugging: one for the C/C++ code function and another for the DLL entry point in disassembly code. When the debugger runs through the code, it reaches the DLL entry point first. To reach the corresponding point in the C/C++ code, click theContinue button (F5).
To end the debugging session:
- Remove all breakpoints.
- Click the Continue button (F5).
The SIL execution runs to completion. - To terminate the SIL execution process, on the Test Output tab, click the link that follows
To terminate execution
, for example,clear kalman01_sil
.
The Microsoft Visual Studio IDE closes automatically.
Note
If you select > , the SIL execution times out with the following error message:
Communications error: failed to send data to the target. There might be multiple reasons for this failure.
... ...
PIL Debugging
When you set up PIL connectivity between Simulink® and the target hardware, specify a debugger by usingtarget.ExecutionService
andtarget.DebugExecutionTool
objects — see Support PIL Debugging and DebugExecutionTool Template.
To run a PIL execution with debugging enabled:
- On the Generate Code page, clickVerify Code.
- Select the Enable source-level debugging for SIL or PIL check box.
- Click Run Generated Code.