We have a Macaulay2 source file with a pair of functions in it that we can use for demonstrating the debugger. Let's load it so we can run the functions in it.
i1 : load "Macaulay2Doc/demo1.m2"
|
We can see what functions were provided to us with
listUserSymbols.
i2 : listUserSymbols
o2 = symbol class value
------ ----- -----
g : FunctionClosure -- g
------------------------------------------------------------------------
location of symbol
------------------
/home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/
------------------------------------------------------------------------
packages/Macaulay2Doc/demo1.m2:11:1-11:2
|
Let's peek at the code of the function
g.
i3 : code g
o3 = /home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:11:7-14:8: --source code:
g = y -> (
c := f(y-1);
d := f(y-2);
c+d)
|
We see that the function g calls a function
f, but
f is not visible to us (because
f is a local variable). In emacs'
Macaulay2 Interaction Mode, pressing return (
RET or
enter) after positioning the cursor on the output line displaying the file name and line number will bring up the source code in a new buffer.
The first few times we use g, it seems to work.
i4 : g 4
17
o4 = --
6
o4 : QQ
|
i5 : g 3
7
o5 = -
2
o5 : QQ
|
However, the following attempt results in an error, and the debugger starts up automatically.
i6 : g 2
/home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:12:(3):[2]: error: division by zero
/home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:12:(3):[2]: --entering debugger (type help to see debugger commands)
/home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:11-8:13: --source code:
b := 1/x;
|
We use
help, as instructed, to view the commands available in the debugger.
ii7 : help
--loading the Macaulay2 documentation from /home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/
--warning: symbol "hilbertBasis" in FourTiTwo.Dictionary is shadowed by a symbol in Polyhedra.Dictionary
-- use the synonym FourTiTwo$hilbertBasis
--warning: symbol "rays" in FourTiTwo.Dictionary is shadowed by a symbol in Polyhedra.Dictionary
-- use the synonym FourTiTwo$rays
--warning: symbol "generalEquations" in PHCpack#"private dictionary" is shadowed by a symbol in NAGtypes.Dictionary
-- no synonym is available
--warning: symbol "addSlackVariables" in PHCpack#"private dictionary" is shadowed by a symbol in NAGtypes.Dictionary
-- no synonym is available
--warning: symbol "tDegree" in NumericalAlgebraicGeometry#"private dictionary" is shadowed by a symbol in PHCpack.Dictionary
-- use the synonym NumericalAlgebraicGeometry$tDegree
--warning: symbol "gamma" in NumericalAlgebraicGeometry#"private dictionary" is shadowed by a symbol in PHCpack.Dictionary
-- use the synonym NumericalAlgebraicGeometry$gamma
--warning: symbol "tDegree" in NumericalAlgebraicGeometry.Dictionary is shadowed by a symbol in PHCpack.Dictionary
-- use the synonym NumericalAlgebraicGeometry$tDegree
--warning: symbol "gamma" in NumericalAlgebraicGeometry.Dictionary is shadowed by a symbol in PHCpack.Dictionary
-- use the synonym NumericalAlgebraicGeometry$gamma
--warning: symbol "tDegree" in NumericalAlgebraicGeometry#"private dictionary" is shadowed by a symbol in PHCpack.Dictionary
-- use one of the synonyms NAG$tDegree, NumericalAlgebraicGeometry$tDegree
--warning: symbol "gamma" in NumericalAlgebraicGeometry#"private dictionary" is shadowed by a symbol in PHCpack.Dictionary
-- use one of the synonyms NAG$gamma, NumericalAlgebraicGeometry$gamma
--warning: symbol "tDegree" in NumericalAlgebraicGeometry.Dictionary is shadowed by a symbol in PHCpack.Dictionary
-- use one of the synonyms NAG$tDegree, NumericalAlgebraicGeometry$tDegree
--warning: symbol "gamma" in NumericalAlgebraicGeometry.Dictionary is shadowed by a symbol in PHCpack.Dictionary
-- use one of the synonyms NAG$gamma, NumericalAlgebraicGeometry$gamma
--warning: symbol "vertices" in SimplicialComplexes.Dictionary is shadowed by a symbol in Graphs.Dictionary
-- use the synonym SimplicialComplexes$vertices
--warning: symbol "Certification" in Core.Dictionary is shadowed by a symbol in RandomObjects#"private dictionary"
-- use the synonym Core$Certification
--warning: symbol "Certification" in Core.Dictionary is shadowed by a symbol in RandomObjects.Dictionary
-- use the synonym Core$Certification
--warning: symbol "nextPrime" in RandomSpaceCurves.Dictionary is shadowed by a symbol in RandomPlaneCurves.Dictionary
-- use the synonym RandomSpaceCurves$nextPrime
--warning: symbol "PushForward" in PackageDictionary is shadowed by a symbol in Schubert2#"private dictionary"
-- use the synonym Package$PushForward
--warning: symbol "PushForward" in PackageDictionary is shadowed by a symbol in Schubert2.Dictionary
-- use the synonym Package$PushForward
oo7 = --debugging control:
return -- bypass current expression, return null, stop
return x -- bypass current expression, return x, stop
step -- step 1 line
step n -- step n lines
step (-n) -- trace n microsteps
end (or eof char) -- enter debugger one level up
continue -- leave the debugger, continuing execution
-- with current expression
break -- leave the debugger, returning to top level
--debugging information:
listLocalSymbols -- display local symbols and their values
listUserSymbols -- display user symbols and their values
current -- the current expression; initially, the one
-- that produced an error
code current -- source code of current expression
value current -- execute current expression, obtain value
disassemble current -- display microcode of current expression
currentString -- the string being evaluated by 'value', if
-- an error occurred within it
-- emacs commands in *M2* buffer:
RET -- on an file/position line, go to source
|
As suggested, we can use
listLocalSymbols to list the local symbols and their values.
ii8 : listLocalSymbols
oo8 = symbol class value location of symbol
------ ----- ----- ------------------
x : ZZ -- 0 /home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:6:6-6:7
a : String -- "hi there" /home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:7:6-7:7
b : Nothing -- null /home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:6-8:7
f : FunctionClosure -- {*Function[/home/charles/local/src/Macaulay2/release-b. /home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:6:1-6:2
|
We see the the value of
x is 0, and that explains the error message about division by zero. The other local symbols are the ones defined in the body of the function
f, whose code can now be displayed with
code.
ii9 : code f
oo9 = /home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:6:8-9:8: --source code:
f := x -> (
a := "hi there";
b := 1/x;
b+1)
|
We can use
step with argument 0 to bypass the current expression.
ii10 : step 0
/home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:12:(3):[2]: --stepping limit reached
/home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:12:(3):[2]: --entering debugger (type help to see debugger commands)
/home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:11-8:13: --source code:
b := 1/x;
|
If we decide the problem is one level up, we can use
end or the end-of-file character (which often is CTRL-D) to quit this instance of the debugger. In this case, the debugger will be entered again (triggered by the same error indication that caused it to be entered originally) at the point inside the function
g from which the function
f was called.
ii11 : end
/home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:13:11:(3):[1]: --entering debugger (type help to see debugger commands)
/home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:13:11-13:15: --source code:
d := f(y-2);
|
We can use
listLocalSymbols again to see the local variables of
g.
ii12 : listLocalSymbols
oo12 = symbol class value location of symbol
------ ----- ----- ------------------
y : ZZ -- 2 /home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:11:5-11:6
c : QQ -- 2 /home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:12:6-12:7
d : Nothing -- null /home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:13:6-13:7
f : FunctionClosure -- {*Function[/home/charles/local/src/Macaulay2/release-b. /home/charles/local/src/Macaulay2/release-branches/1.5/M2/Macaulay2/packages/Macaulay2Doc/demo1.m2:6:1-6:2
|
After we are done debugging, we can quit the debugger entirely and return to top level with
break.