REDUCE

19.3 Procedure Tracing: RTR, UNRTR

Tracing of one or more procedures is initiated by the command rtr:

rtr <proc1>, <proc2>, ..., <procn>;

and cancelled by the command unrtr:

unrtr <proc1>, <proc2>, ..., <procn>;

Every time a traced procedure is executed, a message is printed when the procedure is entered or exited. The entry message displays the actual procedure arguments equated to the dummy parameter names, and the exit message displays the value returned by the procedure. Recursive calls are marked by a level number. Here is a (simplistic) example, using first the default algebraic display and second conventional Lisp display:

algebraic procedure power(x, n);
   if n = 0 then 1 else x*power(x, n-1)$

rtr power;

(power)

power(x+1, 2);

Enter (1) power
   x:  x + 1$
   n:  2$
Enter (2) power
   x:  x + 1$
   n:  1$
Enter (3) power
   x:  x + 1$
   n:  0$
Leave (3) power = 1$
Leave (2) power = x + 1$
Leave (1) power = x**2 + 2*x + 1$

 2
x  + 2*x + 1

off rtrace;

power(x+1, 2);

Enter (1) power
   x:  (plus x 1)
   n:  2
Enter (2) power
   x:  (plus x 1)
   n:  1
Enter (3) power
   x:  (plus x 1)
   n:  0
                                                                     

                                                                     
Leave (3) power = 1
Leave (2) power = (!*sq ((((x . 1) . 1) . 1) . 1)
t)
Leave (1) power = (!*sq ((((x . 2) . 1) ((x . 1) .
2) . 1) . 1) t)

 2
x  + 2*x + 1

on rtrace;

unrtr power;

(power)

Many algebraic-mode operators are implemented as internal procedures with different names. If an internal procedure with the specified name does not exist then rtrace tracing automatically applies to the appropriate internal procedure and returns a list of the names of the internal procedures, e.g.

rtr int;

(simpint)

This facility is an extension of the rdebug package.

Tracing of compiled procedures by the rtrace package is not completely reliable, in that recursive calls may not be traced. This is essentially because tracing works only when the procedure is called by name and not when it is called directly via an internal compiled pointer. It may not be possible to avoid this restriction in a portable way. Also, arguments of compiled procedures are not displayed using the names given to them in the source code, because these names are no longer available. Instead, they are displayed using the names Arg1, Arg2, etc.


Hosted by Download REDUCE Powered by MathJax