> < ^ Date: Fri, 06 Nov 1992 03:10:43 +0100
> < ^ From: Werner Nickel <nickel@mathematik.tu-darmstadt.de >
> < ^ Subject: Re: debugging

Peter Jipsen writes:

> Is it possible to trace through gap code?
> Are there some useful commands to help debugging
> gap routines? I found out about Backtrace in some
> message on this forum, but couldn't find it
> in the manual. Of course one can always interrupt
> execution and inspect variables (very useful) and
> after inserting enough ugly print statements in the
> clean (but errant) gap code
> one can eventually figure out what went wrong,
> but then everything needs to be cleaned back up.
> Maybe other users have come up with more
> elegant ideas?
>
> [stuff deleted]
Instead of interrupting an execution and end up at a more or
less random point in the GAP code one can use the function
Error() to halt the execution of GAP code at specific points.
For example, the following function has a bug. In order to look
at what's going on in the for-loop one can insert a call to
Error():

WrongIntegratePol := function( p )

local   i, q;
        q := [ 0 ];
        for i in [1..Length(p)] do
            q[i+1] := 1/(i+1) * p[i];
            Error( "break point" );
        od;
        return p;
end;

As soon as Error() is executed, GAP goes into a break loop and one
can have a look at the state of the execution at this point. It is
possible, of course, to continue the execution by `returning' from
the break loop.

This technique suggests a way of implementing a step by step execution
of GAP code. The user would tell GAP at some point that she wants to
start to trace through the GAP code step by step. This could be done
by calling an internal function (which would have to be inserted at
some point into the GAP code). From then on, the internal functiont
which is responsible for executing a sequence of GAP statements could
generate a call to Error() after each statement has been executed. It
would also be useful to choose specific functions for step by step
execution. In this case a break loop would be created after each
statement in one of the chosen functions has been executed.

I don't know how difficult it would be to make the necessary changes
to the GAP kernel. At a superficial level it does not look to be too hard.

Any comments ?

Werner Nickel
Mathematics Research Section
Australian National University


> < [top]