6. QGen Model Debugger: Step by Step Tutorial

6.1. General comments

For installation and general documentation please refer to QGen Model Debugger. This tutorial assumes QGen and QGen debugger have been setup succesfully, see Installing QGen for more details.

6.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.

_images/DebuggerTuto1.png

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.

_images/DebuggerTuto2.png

Feel free to replace the signal builder block by any combination of blocks or model references if desired.

_images/DebuggerTuto3.png

Once the test case is ready, run the simulation on your model by clicking on the icon highlighted in red below.

_images/DebuggerTuto4.png

6.3. Start Debugging the model in GNAT Studio

Once you can simulate the model successfully, click on QGen > Start QGen Debugger in GNAT Studio.

_images/DebuggerTuto5.png

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.

_images/DebuggerTuto6.png

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.

_images/DebuggerTuto14.png

If your model is using workspace variables click on Yes in the next dialog.

_images/DebuggerTuto7.png

GNAT Studio will then open and ask you to choose a target language for code generation, pick Ada or C and click on OK.

_images/DebuggerTuto8.png

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.

_images/DebuggerTuto9.png

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

_images/GPS_Toolbar.png _images/GPS_MDL_Menu.png

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>.

_images/DebuggerTuto10.png

Click on Debug > Run..., uncheck Stop at beginning of main subprogram and click on OK to start debugging.

_images/DebuggerTuto11.png

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.

_images/DebuggerTuto12.png