Goto Chapter: Top 1 2 Ind
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 

1 Getting started using debugger
 1.1 Creating Breakpoints
 1.2 Calling Functions

1 Getting started using debugger

Debugger is a GAP package which advanced some advanced debugging functionality to GAP. It does not replace GAP's builtin break loop, but provides new ways to access the break loop.

In this chapter we describe a couple of different uses of debugger. First, we explain in Section 1.1 how to set breakpoints.

Then we show in Section 1.2 how to create a function which will be called every before every line of GAP code.

1.1 Creating Breakpoints

Suppose you want to enter the break loop at a particular line of your existing code. We can use AddBreakpoint (2.1-1), which lets you set a filename and line to break at. When this line is reached, GAP will enter the break loop. For example:

AddBreakpoint("mycode.g", 54);
AddBreakpoint("lib/grp.g", 128);

All functions in the debugger package do not require a full filename, but will instead look for filenames which end with the given string. Once in the breakloop, use return; to continue execution. At any point, call ClearAllBreakpoints (2.1-3) to remove all breakpoints. Like in standard debuggers, while in the break loop we can use the functions BreakNextLine (2.1-5), BreakNextEnterFunction (2.1-7) and BreakNextLeaveFunction (2.1-9) to re-enter the break loop at the next line, next time we enter a function or next time we leave a function. The function BreakEveryLine (2.1-6) will make GAP enter the break loop after each line of code is executed.

1.2 Calling Functions

Instead of entering the break loop, we can instead call a function when a particular line is reached, or after every line. Each function in the debugger package optionally takes a function to be called, instead of entering the break loop. For example, consider that we want to find exactly which part of GAP sets the size of a group G. We can call:

func := function(file,line)
  if HasSize(G) then Error("Size set!"); fi;
end;
BreakEveryLine(func);

This will call func before every line of GAP code is executed, entering the break loop when the size of G is set.

 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 
Goto Chapter: Top 1 2 Ind

generated by GAPDoc2HTML