Using the TLC Debugger
The TLC debugger helps you identify programming errors in your TLC code. Using the debugger,
you can execute TLC code line-by-line, analyze and/or change variables in a specified block
scope, and view the TLC call stack. The TLC debugger has a command-line interface that provides
commands similar to standard debugging tools such as
Tips for Debugging TLC Code
Here are a few tips that will help you to debug your TLC code:
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.
To trace the value of a variable in a function, place the following statement in your TLC file:
%trace This is in my function %<variable>
Your message will appear when the Target Language Compiler is run with the
-vcommand switch, but not otherwise. You can use
%traceto print variables, but you will need to remove or comment out such lines after you are through debugging.
Use the TLC coverage log files to identify parts of your code that have not been reached.
Invoking the Debugger
Use the TLC debugger to identify bugs and potential problems in your TLC files. To use the TLC debugger:
On the Configuration Parameters dialog box, select Retain .rtw file. This prevents the
file from being deleted after code generation.
Select Start TLC debugger when generating code to invoke the TLC debugger when starting the code generation process.
Selecting Start TLC debugger when generating code is equivalent to specifying the TLC option
-dcon the Code Generation pane of the Configuration Parameters dialog box.
Apply changes and start code generation by pressing Ctrl+B. This stops at the first line of executed TLC code, breaks into the TLC command-line debugger, and displays the following prompt:
You can now set breakpoints, explore the contents of code generator files, and explore
variables in your TLC file using
An alternative way to invoke the TLC debugger is from the MATLAB® prompt. (This assumes you retained the
file in the project folder.) To avoid
making mistakes, copy the
tlc command output of the build process to the
MATLAB Command Window, and issue it after appending
-dc to that
A complete list of command-line switches for the TLC debugger is available in the table Target Language Compiler Switches.
TLC Debugger Command Summary
The table TLC Debugger Commands summarizes the TLC debugger commands.
To obtain more detailed help on individual commands, use the syntax
from within the TLC debugger, as in this example:
TLC-DEBUG> help clear
You can abbreviate a TLC debugger command to its shortest unique form. For example,
TLC-DEBUG> break warning
can be abbreviated to
TLC-DEBUG> br warning
To view a complete list of TLC debugger commands, type
help at the
TLC Debugger Commands
Change a variable in the running program.
Set a breakpoint. See also %breakpoint Directive.
Remove a breakpoint.
Attach a condition to a breakpoint.
Continue from a breakpoint.
Disable a breakpoint.
Move down the stack.
Enable a breakpoint.
Break after completing the current function.
Obtain help for a command.
Set the ignore count of a breakpoint.
Display contents of I/O stack.
List lines from the file from start to end.
Load debugger breakpoint state from a file.
Single step without going into functions.
Print the value of a TLC expression. To print a record, you must specify a fully
qualified scope such as
Quit the TLC debugger. You can also exit the debugger by typing Ctrl+C at the prompt.
Run a batch file of command-line debugger commands.
Save debugger breakpoint state to a file.
Display a list of active breakpoints.
Set a breakpoint (same as
Set a temporary breakpoint.
Change the active thread to thread
List the currently active TLC execution threads.
Set a temporary breakpoint.
Move up the stack.
Show the currently active execution chains.
Look up the name and display what scope it comes from.
List the variables in the given scope.
As an alternative to the
break command, you can embed breakpoints at
locations in a TLC file by adding the directive
errorto break or stop on error
warnto break or stop on warning
traceto break or stop on trace
For example, if you need to break on error, use
TLC_DEBUG> break error
clear, get the status of breakpoints using
status and clear specific breakpoints. For example
TLC-DEBUG> break "foo.tlc":46 TLC-DEBUG> break "foo.tlc":25 TLC-DEBUG> status Breakpoints:  break File: foo.tlc Line: 46  break File: foo.tlc Line: 25 TLC-DEBUG> clear 2
In this example,
clear 2 clears the second breakpoint.