Trace Simulink Model Elements in Generated Code - MATLAB & Simulink (original) (raw)

Main Content

To verify the generated code, Embedded CoderĀ® provides bidirectional traceability between the SimulinkĀ® model and the generated code. You can use either method for traceability:

Note

The Code view in code perspective provides bidirectional traceability by default.

Code-to-Model Traceability

To use hyperlinks for tracing code-to-model elements:

  1. Open the model and configure it as an ERT target.
  2. Build or generate code for the model. The Code view opens by default to display the generated code next to the model.
  3. In the generated code, place your cursor over the block names in comments to highlight source blocks. For example, generate an HTML report for the model[RollAxisAutopilot](https://mdsite.deno.dev/matlab:openExample%28'ecoder/TraceGeneratedCodeToBlocksExample','supportingFile','RollAxisAutopilot'%29). In the generated code for the model step function in RollAxisAutopilot.c, place your cursor over theUnitDelay: '<Root>/Phi' block. In the model window, the corresponding Inport block is highlighted.
    Code view containing generated code is open next to the model. Mouse cursor is placed over a comment and the corresponding block is highlighted in the model.

Traceability to Hidden Blocks

The code generator sometimes inserts hidden blocks during the code generation process for various reasons, for example, to maintain data integrity. Comments for the hidden blocks are included in the generated code. These comments, and the code generated from the hidden block, trace back to the original block in the model that triggered the insertion of the hidden block. Comments to hidden blocks follow this template:

/* generated from: */

For example:

/* SignalConversion generated from: '/Subsystem' */ Varianttoground_B.VM_Conditional_Signal_Subsystem_0 = 0.0;

The hidden block SignalConversion is not present in the model. You can trace to the '<Root>/Subsystem' block in the model that triggered the insertion of the hidden block by clicking on the hyperlink on'<Root>/Subsystem'. For more information on this example, seeGenerate Code for Variant Subsystem Blocks.

Model-to-Code Traceability

To trace model elements to their corresponding generated code:

  1. Complete steps 1 and 2 as in Code-to-Model Traceability
  2. Build or generate code for the model. The generated code is displayed in the Code view window next to the model.
  3. In the model window, click on a model element. To select multiple blocks, hold theSHIFT key and select additional blocks.
  4. In the generated code in Code view window, you see the first instance of highlighted code that is generated for the model element. At the top of the Code view, numbers that appear to the right of generated file names indicate the total number of highlighted lines in each file. This figure shows the result of tracing theHDG_Ref Inport block in the [RollAxisAutopilot](https://mdsite.deno.dev/matlab:openExample%28'ecoder/TraceGeneratedCodeToBlocksExample','supportingFile','RollAxisAutopilot'%29) model.
    Code view containing generated code is open next to the model. Mouse cursor clicks a block in the model and corresponding lines of code are highlighted in Code view.
    At the top of the code window, use the navigation bar to move forward and backward through multiple instances of highlighted lines. Use the navigation sidebar to go directly to a line of code.

If you close and reopen a model, the Code view does not open until you open the app. The Code view might not be available because Embedded Coder cannot find a build folder for your model in the current working folder. Reset the current working folder to the parent folder of the existing build folder.

If you are using the code generation report and want to reload existing traceability information, see Reload Existing Traceability Information.

See Also

Topics