Execute a procedure in single-step mode

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.




debug(statement) starts the MuPAD® debugger, allowing to execute statement step by step.

debug called with an argument switches the state of the MuPAD kernel to debug mode and, if statement contains procedure calls that can be debugged, enters the interactive MuPAD debugger for controlled single-step execution of statement.

If debug is called without arguments, the current state is returned without changing the state. If the debugger is on, the return value is TRUE, otherwise FALSE.

In a MuPAD version with a graphical user interface, a separate debugger window pops up. In the UNIX® terminal version, the text interface of the command line debugger is activated.

The debugger features single stepping, inspection of variables and stack frames, breakpoints, etc. Read the online help of the debugger window for a description.

Debugging is possible only for procedures written in the MuPAD language that do not have the option noDebug. In particular, debugging of kernel functions is not possible.

After calling Pref::ignoreNoDebug(TRUE), the procedure option noDebug is ignored.

You can also debug a sequence of statements separated by semicolons if the sequence is enclosed in parentheses.

debug(statement) returns the same result as statement, if the execution is not aborted within the debugger by the user.


Example 1

debug() is called to check whether the kernel is in debug mode:


To switch on the debugger mode, debug(1) is called:

Activating debugger...   For those library functions which are already
loaded, the format of the source code  displayed by the debugger 
may differ from that of the original source code file. To avoid this,
restart the kernel in debug mode. Execution completed.           

Example 2

We start the debugger for stepwise execution of the statement int(cos(x),x), which integrates the cosine function:

debug(int(cos(x), x)):



Any MuPAD object; typically a function call

Return Values

Return value of statement or TRUE or FALSE.


In debug mode, the MuPAD parser is re-configured. When a procedure is read from a file, the parser inserts additional debug nodes containing file identifications and line numbers into procedures. These debug nodes allow the debugger to associate the currently executed piece of MuPAD code with the corresponding source text file.

If the debug mode is activated and MuPAD encounters a procedure without debug nodes, it will write the procedure to a temporary file and add debug nodes on the fly. This allows interactively entered procedures to be debugged in the same way as procedures read from files. The temporary debug file is deleted at the end of the session.

Since this also applies to procedures that were read before debug mode was switched on, it is recommended to start the kernel in debug mode (see below) when bigger applications are to be debugged.

If the MuPAD kernel was not started in debug mode, this mode is turned on at the first execution of debug. It remains activated until the end of the session.

It is possible to start the kernel in debug mode. In the MuPAD Notebook, this can be configured by choosing “Configure …” in the “View” menu (“Preferences…” on the Apple Macintosh) and then clicking on “Kernel”. Enter “-g” in the text field “Arguments:”.