I have looked through the SMLNJ User Guide and can't find anything about debugging capabilities. I'd love to just see a stack trace, or step through a function. Is this possible. Are there other implementations for similar variants of SML that do provide this feature?
The Edit, Compile, Debug Cycle in SML To test ML functions, go to the sml window. Enter the command use "filename. sml"; to load and compile the file you've just edited. You can interactively test each function as you add it.
There's currently no step-based debugger.
You can get stack backtraces by doing the following:
- CM.make "$smlnj-tdp/back-trace.cm";
[library $smlnj-tdp/back-trace.cm is stable]
[library $smlnj-tdp/plugins.cm is stable]
[library $SMLNJ-LIB/Util/smlnj-lib.cm is stable]
[library $smlnj/compiler/current.cm is stable]
[library $smlnj/compiler/x86.cm is stable]
[library $smlnj/viscomp/core.cm is stable]
[library $smlnj/viscomp/parser.cm is stable]
[library $smlnj/viscomp/basics.cm is stable]
[library $smlnj/viscomp/elaborate.cm is stable]
[library $smlnj/viscomp/elabdata.cm is stable]
[library $smlnj/MLRISC/MLRISC.cm is stable]
[library $SMLNJ-MLRISC/MLRISC.cm is stable]
[library $Lib.cm(=$SMLNJ-MLRISC)/Lib.cm is stable]
[library $Control.cm(=$SMLNJ-MLRISC)/Control.cm is stable]
[library $Graphs.cm(=$SMLNJ-MLRISC)/Graphs.cm is stable]
[library $smlnj/MLRISC/Control.cm is stable]
[library $smlnj/viscomp/debugprof.cm is stable]
[library $smlnj/viscomp/execute.cm is stable]
[library $smlnj/internal/smlnj-version.cm is stable]
[library $smlnj/viscomp/x86.cm is stable]
[New bindings added.]
val it = true : bool
- SMLofNJ.Internals.TDP.mode := true;
[autoloading]
[autoloading done]
val it = () : unit
-
Then, you can load some code and instead of just printing the exception, you'll get a simulated stack backtrace. You do have to recompile your code after following the above steps, or this won't work!
- exception Foo;
exception Foo
- fun otherFun() = raise Foo;
val otherFun = fn : unit -> 'a
- fun raiseAtZero(n) = if (n > 0) then raiseAtZero(n-1) else otherFun();
val raiseAtZero = fn : int -> 'a
- raiseAtZero 10;
stdIn:9.1-9.15 Warning: type vars not generalized because of
value restriction are instantiated to dummy types (X1,X2,...)
*** BACK-TRACE ***
GOTO stdIn:7.5-7.27: otherFun[2]
(from: stdIn:8.60-8.70: raiseAtZero[2])
CALL-( stdIn:8.5-8.70: raiseAtZero[2]
(from: stdIn:9.1-9.15: it)
GOTO stdIn:5.5-5.27: otherFun[2]
(from: stdIn:6.60-6.70: raiseAtZero[2])
CALL-( stdIn:6.5-6.70: raiseAtZero[2]
(from: stdIn:6.71-6.86: it)
uncaught exception Foo
raised at: stdIn:7.24-7.27
-
There is now a source level debugger in PolyML: http://www.polyml.org/documentation/Tutorials/Debugging.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With