trace, untrace - Maple Programming Help

trace, untrace

trace procedures in order to debug them

 Calling Sequence trace(f) trace(f, g, h, ...) debug(f) debug(f, g, h, ...) untrace(f) untrace(f, g, h, ...) undebug(f) undebug(f, g, h, ...)

Parameters

 f, g, h, ... - name(s) of procedure(s) to be traced

Description

 • The trace function is a debugging tool for tracing the execution of the procedure(s) f, g, h, and so forth.
 • A module may be given in place of a procedure name. In this case, all the exports of the module are traced. This process is recursive, so all exported procedures in all submodules are also traced.
 • During execution, the entry points, the results of the statements that are executed (see below), and the exit points of the traced procedure(s) are printed. At entry points, all passed positional arguments (declared and undeclared) are displayed; note that default values are not displayed. At exit points, the returned function value is displayed.
 • The amount of information displayed during tracing depends on whether the expression being evaluated (some part of which is presumably being traced) was terminated with a colon or a semicolon. If terminated with a colon (":"), only entry and exit points of the traced procedure(s) are printed. If terminated with a semicolon (";"), the results of the statements that are executed are also printed.
 • Each entry point is printed with a left brace ("{") at the beginning of the line, and each exit point is printed with a right brace ("}") at the end of the line. If you are viewing trace output with a text editor that has a delimiter-matching function, you can use this to jump back and forth between corresponding entry and exit points.
 • The untrace function turns off the tracing of its arguments.
 • The trace (untrace) function returns an expression sequence of the names of the procedures for which tracing was turned on (off).
 • A special syntax, similar to that used for stopat and unstopat, may be used for tracing local procedures in modules. If a module m has a local variable g that is a procedure, then you can trace g by issuing the command trace( m::g ). Similarly, tracing of g can be turned off with the call untrace( m::g ). Note that, in this call, the expression g must be of type symbol and must be global in scope. (This special way of referring to locals of a module is recognized only when used with debugging related utilities. It is not a general syntax for referring to module locals.)
 • Note that it is not possible to trace any function which has special evaluation rules, namely any of: assigned, eval, evalhf, evalf, evaln, seq, userinfo. However, when tracing a procedure that calls evalf, any traceable code that is executed by evalf is traced.
 • The trace function will silently ignore any argument which is not the name of a traceable procedure. In particular, it is possible to invoke trace(anames()) to cause tracing of all procedures which correspond to currently-assigned names even though many of the names in anames() may not be assigned procedures.
 • The names debug and undebug are alternate names for trace and untrace.

Examples

 > f := proc(x) local y; y := x * 2; g(x) / 4; end proc;
 ${f}{≔}{\mathbf{proc}}\left({x}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{y}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{y}{≔}{2}{*}{x}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{1}{/}{4}{*}{g}{}\left({x}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (1)
 > g := proc(x) local z; z := x^2; z * 2; end proc;
 ${g}{≔}{\mathbf{proc}}\left({x}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{z}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{z}{≔}{x}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{2}{*}{z}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (2)
 > $\mathrm{trace}\left(f,g\right)$
 ${f}{,}{g}$ (3)
 > $f\left(3\right)$
 {--> enter f, args = 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 y := 6 {--> enter g, args = 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 z := 9                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   18 <-- exit g (now in f) = 18}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   9/2 <-- exit f (now in mpldoc/process_example) = 9/2}
 $\frac{{9}}{{2}}$ (4)
 > $f\left(3\right):$
 {--> enter f, args = 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 y := 6 {--> enter g, args = 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 z := 9                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   18 <-- exit g (now in f) = 18}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   9/2 <-- exit f (now in mpldoc/process_example) = 9/2}
 > m := module()   export f;   local g;   g := proc( x )     local y;     y := 2 * x;     y   end proc;   f := x -> g( x / 3 ); end module:
 > $\mathrm{trace}\left(m::g\right)$
 ${g}$ (5)
 > $m:-f\left(2\right)$
 {--> enter g, args = 2/3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                y := 4/3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   4/3 <-- exit g (now in f) = 4/3}
 $\frac{{4}}{{3}}$ (6)
 > $\mathrm{untrace}\left(m::g\right)$
 ${g}$ (7)
 > $m:-f\left(s\right)$
 $\frac{{2}}{{3}}{}{s}$ (8)