7. QGen Model Debugger: Step by Step Tutorial¶
7.1. General comments¶
7.2. Create a Debugging project from MATLAB¶
Open the model that you want to debug in MATLAB, in this example we will be using the model available QGEN_INSTALL/share/qgen/examples/speedometer/speedometer.mdl, and click on QGen > Create Debug session. This will create a new harness model in the same directory called <model_name>_sim.slx.
This model references the original model and logs the signals connected to its input and outputs ports. Additionally, it creates an inputs subsystem that you can use to generate an appropriate test case. Click OK on the dialog window that appeared, and proceed by updating the signals within the Signal Builder window. Please refer to the signal builder documentation for more detail.
Feel free to replace the signal builder block by any combination of blocks or model references if desired.
Once the test case is ready, run the simulation on your model by clicking on the icon highlighted in red below.
7.3. Start Debugging the model in GNAT Studio¶
Once you can simulate the model successfully, click on QGen > Start QGen Debugger in GNAT Studio.
Two dialog windows will appear to define the debugging environment. The first will ask you whether you want to use the test case created previously, click on Yes if you want to use the Simulink inputs to call your generated code. If you click on No, a simple main file will be generated and you will be able to write the calling code manually. This is the recommended choice for more complex integrations with existing handwritten code.
You can choose a directory to store the exported XMI files, this allows you to target an existing export directory to speed up the process.
If your model is using workspace variables click on Yes in the next dialog.
GNAT Studio will then open and ask you to choose a target language for code generation, pick Ada or C and click on OK.
If you selected Yes at the first step. The next pop-up will ask you about a tolerance value that is used to consider the simulation correct or not. All output values coming from the generated code will have to be inside the range [simulated-value - tolerance, simulated-value + tolerance] to be considered correct. Choose a value suiting you needs or leave it empty to use 0.0 as default.
You can then generate code, build the executable and start the debugger by clicking on the right icon shown in the image below or by clicking on Build > MDL generate, build & debug > main.adb
After the generation and build process complete a Debugger Console Panel will appear. Double click on your original model in the project view to display it in a new GNAT Studio view.
Once the model is open browse to the desired subsystem by double-clicking on a subsystem or by using the outline view on the left. Set a breakpoint on a block by right clicking on it and clicking on Debug > Break on <block_name>.
Click on Debug > Run…, uncheck Stop at beginning of main subprogram and click on OK to start debugging.
Execution will reach the breakpoint on the block defined earlier and you can examine the values and execute step by step. Please refer to QGen Model Debugger for all the functionalities available to you at that stage.