## `debug` -- execute a procedure in single-step mode

#### Introduction

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

#### Call(s)

`debug(statement)`

#### Parameters

`statement` | - | any MuPAD object; typically a function call

#### Returns

the return value of `statement`.

#### Related Functions

`noDebug`, `Pref::ignoreNoDebug`, `prog::check`, `prog::profile`, `prog::trace`

#### Details

- `debug` 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 a function of the system kernel.

#### Example 1

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

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

#### Background

- 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. On Windows platforms, this can be configured by choosing ``Options'' in the ``View'' menu and then clicking on ``Kernel''. In the graphical user interface on UNIX systems, clicking on ``Kernel Debug Mode'' in the ``Options'' menu toggles this setting. On a Macintosh, choose ``Preferences'' from the ``File'' menu and then ``Kernel''.

#### Changes

- The new procedure option noDebug prevents debugging of the corresponding procedure.

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000