Next: Interfacing with other Up: Programming in Maple Previous: Reading and Saving

Debugging Maple Programs

The simplest debugging tool is the printlevel facility. printlevel is a global variable that is initially assigned 1. If you set it to a higher value, a trace of all assignments, procedure entry and exits are printed. The higher the value of printlevel, the more levels of procedure execution that will be traced. Often, however, the output from the printlevel facility will be too much. The trace function allows you to trace the execution of the specified functions only. Examples of these two tools have already been given in this document. We mention here one further tool. If you set the printlevel variable to 3 or higher, then if a run-time error occurs, Maple will print a stack trace of the calling sequence at the time the error occurs. Specifically, it will print the arguments to all procedures currently being executed, and the values of the local variables and the statement being executed in the procedure where the error occured. This is simplest illustrated by an example.


> f := proc(x) local y; y := 1; g(x,y); end:
> g := proc(u,v) local s,t; s := 0; t := v/s; s+t end:
> printlevel := 4:
> f(3);
Error, (in g) division by zero
        executing statement: t := v/s
        locals defined as: s = 0, t = t
        g called with arguments: 3, 1
        f called with arguments: 3


bondaren@thsun1.jinr.ru