Main Content

Trace Generated Code to Blocks

Navigate and trace between generated code and its source model for verification.

Open Example Model

Open the example model RollAxisAutopilot.

model='RollAxisAutopilot';
open_system(model)

Code to Model Navigation

Navigate from the generated code to the model.

  1. In the Configuration Parameters dialog box, open the Code Generation > Report pane.

  2. Verify that the following parameters are selected: Create code generation report, Open report automatically and Code-to-model.

  3. In the model editor window, press Ctrl+B to generate code. After the code generation process is complete, the code generation report appears.

  4. In the generated report, click the RollAxisAutopilot.c link to see the code with embedded hyperlinks.

  5. Click links in the code to trace generated code segments to the highlighted elements in the model. For example, if you click the hyperlink <Root>/Sum, the Sum block in the model is highlighted.

Model to Code Navigation

Navigate from the model to the generated code.

  1. In the Configuration Parameters dialog box, open the Code Generation > Report pane.

  2. Verify that the following parameters are selected: Create code generation report, Open report automatically and Model-to-code.

  3. In the model editor window, press Ctrl+B to generate code. After the code generation process is complete, the code generation report appears.

  4. In the model window, right-click any block and select C/C++ Code > Navigate To C/C++ Code. The software highlights the generated code for this block in the code generation report.

  5. Inspect the highlighted lines in the code generation report. The total number of highlighted lines is displayed at the top of the right pane in the report. Use the Previous and Next buttons to navigate through the highlighted lines.

Note: Model-to-code navigation also works for Stateflow® objects and MATLAB functions.

Note: The report displays a diagnostic message if there is no code to highlight for the selected block (for example, if you select a virtual block).

Traceability Report

Generate and inspect the Traceability Report.

  1. In the Configuration Parameters dialog box, open the Code Generation > Report pane.

  2. Verify that the following parameters are selected: Create code generation report, Open report automatically

  3. Search for the traceability report parameters using keyword GenerateTraceReport. Verify all the listed parameters are selected.

  4. In the model editor window, press Ctrl+B to generate code. After the code generation process is complete, the code generation report appears.

  5. To see a report of the untraceable (not in the generated code) and traceable blocks in your model, on the left pane of the generated report click Traceability Report.

  6. In the Traceability Report, inspect the Eliminated / Virtual Blocks and Traceable Blocks lists. For example, the Scope block is an untraceable block. It is listed under Eliminated / Virtual Blocks because the code generator does not generate code for this block.

External Websites