Execute a procedure in single-step mode
This functionality does not run in MATLAB.
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.
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.
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. 1
We start the debugger for stepwise execution of the statement int(cos(x),x), which integrates the cosine function:
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 app, 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:".