9.19 Debugging

If GAP 4 runs into an error or is interrupted, it enters a break loop. The command Where( number ), which replaces Backtrace of GAP 3, can be used to display number lines of information about the current function call stack.

As in GAP 3, access is only possible to the variables of the current level in the function stack, but in GAP 4 the function DownEnv, with a positive or negative integer as argument, permits one to step down or up in the stack.

When interrupting, the first line printed by Where actually may be one level higher, as the following example shows

gap> test:= function( n )
>    if n > 3 then Error( "!" ); fi; test( n+1 ); end;;
gap> test( 1 );
Error ! at
Error( "!" );
Entering break read-eval-print loop,
you can 'quit;' to quit to outer loop,
or you can return to continue
brk> Where();
test( n + 1 ); called from
test( n + 1 ); called from
test( n + 1 ); called from
<function>( <arguments> ) called from read-eval-loop
brk> n;
4
brk> DownEnv();
brk> n;
3
brk> Where();
test( n + 1 ); called from
test( n + 1 ); called from
<function>( <arguments> ) called from read-eval-loop
brk> DownEnv( 2 );
brk> n;
1
brk> Where();
<function>( <arguments> ) called from read-eval-loop
brk> DownEnv( -2 );
brk> n;
3

For purposes of debugging, it can be helpful sometimes, to see what information is stored within an object. In GAP 3 this was possible using RecFields because the objects in question were represented via records. For component objects, GAP 4 permits the same by NamesOfComponents( object ), which will list all components present.

[Top] [Previous] [Up] [Next] [Index]

GAP 4 manual
February 2000