One useful way to debug code suspected of being in error is to insert an explicit error message, such as error "debug me", and start stepping from there, as in the following demonstration.
i1 : load "Macaulay2Doc/demo2.m2" |
i2 : code f
o2 = /builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:6:7-12:13: --source code:
f = t -> (
x := 1;
error "debug me";
y := t+1;
z := 1/t;
w := x+t;
)
|
i3 : f 0
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:8:6:(3):[1]: error: debug me
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:8:6:(3):[1]: --entering debugger (type help to see debugger commands)
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:8:6-8:6: --source code:
error "debug me";
|
ii4 : help
--loading the Macaulay2 documentation from /builddir/build/BUILD/Macaulay2-1.5/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
oo4 = --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
|
ii5 : return
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:9:8:(3):[1]: --stepping limit reached
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:9:8:(3):[1]: --entering debugger (type help to see debugger commands)
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:9:8-9:13: --source code:
y := t+1;
|
ii6 : disassemble current oo6 = (local-assign 2 0 (2-OP + (fetch 0 0) 1)) |
ii7 : step(-3)
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:9:8:(3):[1]: --evaluating: (local-assign 2 0 (2-OP + (fetch 0 0) 1))
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:9:12:(3):[1]: --evaluating: (2-OP + (fetch 0 0) 1)
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:9:11:(3):[1]: --evaluating: (fetch 0 0)
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:9:13:(3):[1]: --stepping limit reached
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:9:13:(3):[1]: --entering debugger (type help to see debugger commands)
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:9:13-9:13: --source code:
y := t+1;
|
ii8 : step
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:10:8:(3):[1]: --stepping limit reached
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:10:8:(3):[1]: --entering debugger (type help to see debugger commands)
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:10:8-10:13: --source code:
z := 1/t;
|
ii9 : step
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:10:12:(3):[1]: error: division by zero
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:10:12:(3):[1]: --entering debugger (type help to see debugger commands)
/builddir/build/BUILD/Macaulay2-1.5/Macaulay2/packages/Macaulay2Doc/demo2.m2:10:11-10:13: --source code:
z := 1/t;
|
ii10 : t oo10 = 0 |