Target Language Compiler    

Tips for Debugging TLC Code

Here are a few tips that will help you to debug your TLC code:

  1. To see the full TLC call stack, place the following statement in your TLC code before the line that is pointed to by the error message. This will be helpful in narrowing down your problem.

    %setcommandswitch "-v1"

  1. To trace the value of a variable in a function, place the following statement in your TLC file.

    %warning This is in my function %<variable>

  1. Use the TLC coverage log files to ensure that most parts of your code have been exercised.

Using the TLC Debugger

This section provides a tutorial that illustrates the steps for invoking and using the TLC debugger with Simulink and RTW generated code. The files and models for this example are in

This tutorial uses the simple_log model and the gain.tlc TLC file located in this directory.

For the purpose of this tutorial, the TLC file contains a bug, so this function cannot be used in an actual scenario.

Tutorial

Generate the Results

  1. Make sure that you are in the proper directory as given above. This tutorial uses the simple_log model, which contains a Gain block. Note that the gain.tlc used here will be the one in the current directory as the model. This is the simple_log model.
  2. Simulate the model. This model saves tout and yout to the workspace, which you can view by selecting View -> Workspace from the MATLAB desktop menu.
  3. Build the model and run the executable. This creates the file simple_log.mat. (For more information about the build process, see the Real-Time Workshop User's Guide.)
  4. To compare the results from Simulink and Real-Time Workshop, load the simple_log.mat file. The result from Simulink, yout, does not match the Real-Time Workshop result, rt_yout, because the TLC code contains a bug. You must debug the TLC code to identify the problem.

Invoke the Debugger

  1. To debug the code, bring up the RTW options page by selecting Tools -> Real-Time Workshop -> Options from the model's menu. This brings up the Real-Time Workshop page of the Simulation Parameters dialog box.
  2. Select TLC debugging from the Category pulldown. From this screen you can select options that are specific to TLC debugging.
  3. Select Retain .rtw file, otherwise it gets deleted after code generation. Also, select Start TLC debugger when generating code to invoke the TLC debugger when starting the code generation process. This is equivalent to adding -dc to the System target file field in the Real-Time Workshop page of the Simulation Parameters dialog box. The dialog box should look like this.
  4. Apply your changes and press Build to start code generation. This stops at the first line of executed TLC code, breaks into the TLC command line debugger, and displays the following prompt.

    TLC_DEBUG>

    You can now set breakpoints, explore the contents of RTW file, and explore variables in your TLC file using print, which, or whos.

An alternate way to invoke the TLC debugger is from the MATLAB prompt. (This assumes you retained the model.rtw file in the project directory.) Use the following command and replace matlabroot with the full pathname to the location where MATLAB is installed on your system.


 Debugging TLC TLC Debugger Commands