Main Content

Configure Model for Debugging

In the Configuration Parameters dialog box, use parameters on the Diagnostics pane and debugging parameters to configure a model such that the generated code and the build process are set for debugging. You can set parameters that apply to the model compilation phase, the target language code generation phase, or both.

Parameters in the following table will be helpful if you are writing TLC code for customizing targets, integrating legacy code, or developing new blocks.

Display progress information during code generation in the MATLAB® Command Window

Verbose build.Compiler output also displays.

Prevent the build process from deleting the model.rtw file from the build folder at the end of the build

Retain .rtw file. This parameter is useful if you are modifying the target files, in which case you need to look at the model.rtw file.

Instruct the TLC profiler to analyze the performance of TLC code executed during code generation and generate a reportProfile TLC. The report is in HTML format and can be read in your web browser.
Start the TLC debugger during code generationStart TLC debugger when generating code. Alternatively, enter the argument -dc for the System target file parameter on the Code Generation pane. To start the debugger and run a debugger script, enter -df filename for System target file.
Generate a report containing statistics indicating how many times the code generator reads each line of TLC code during code generationStart TLC coverage when generating code. Alternatively, enter the argument -dg for the System Target File parameter on the Code Generation pane.
Halt a build if a user-supplied TLC file contains an %assert directive that evaluates to FALSE

Enable TLC assertion. Alternatively, you can use MATLAB commands to control TLC assertion handling.

To set the flag on or off, use the set_param command. The default is off.

set_param(model, 'TLCAssertion', 'on|off') 

To check the current setting, use get_param.

get_param(model, 'TLCAssertion')
Detect loss of tunability

Detect loss of tunability on the Diagnostics > Data Validity pane. You can use this parameter to report loss of tunability when an expression is reduced to a numeric expression. This can occur if a tunable workspace variable is modified by Mask Initialization code, or is used in an arithmetic expression with unsupported operators or functions. Possible values are:

  • none — Loss of tunability can occur without notification.

  • warning — Loss of tunability generates a warning (default).

  • error — Loss of tunability generates an error.

For a list of supported operators and functions, see Tunable Expression Limitations

Enable model verification (assertion) blocks

Model Verification block enabling. Use this parameter to enable or disable model verification blocks such as Assert, Check Static Gap, and related range check blocks. The diagnostic applies to generated code and simulation behavior. For example, simulation and code generation ignore this parameter when model verification blocks are inside an S-function. Possible values are:

  • User local settings

  • Enable All

  • Disable All

For Assertion blocks not disabled, generated code for a model includes one of the following statements, depending on the blocks input signal type (Boolean, real, or integer, respectively).

utAssert(input_signal != 0.0);
utAssert(input_signal != 0);

If the model contains variant blocks with the Variant activation time parameter set to startup and the Allow zero active variant controls parameter set to off, the model_initialize function in the generated code contains this assertion.

utAssert(<variant condition expression on the block>);
This statement checks that at least one variant choice is active for such variant blocks.

By default, utAssert does not change generated code. For assertions to abort execution, you must enable them by specifying the following make_rtw command for Code Generation > Make command parameter:


Use the following variant if you want triggered assertions to print the assertion statement instead of aborting execution:


utAssert is defined as #define utAssert(exp) assert(exp).

To customize assertion behavior, provide your own definition of utAssert in a handwritten header file that overrides the default utAssert.h. For details on how to include a customized header file in generated code, see Integrate External Code by Using Model Configuration Parameters.

When running a model in accelerator mode, the Simulink® engine calls back to itself to execute assertion blocks instead of using generated code. Thus, user-defined callbacks are still called when assertions fail.

For more information about the TLC debugging options, see Debugging on Target Language Compiler. Also, consider using the Model Advisor as a tool for troubleshooting model builds. For more information about the Model Advisor, see Run Model Advisor Checks.

Related Topics