Debugging sasa ocaml Algorithms
This tutorial propose various ways to debug sasa
Algorithms (others
than from code review or printf debugging). rdbg
is (currently) not
able to inspect the ocaml
runtime system, but the usual ocaml
debugging tools can be used.
Set the seed
In order to debug, it is generally easier if the randomness is
frozen. You can do that using the -seed
option of sasa
. This is
good to know when you encounter a sporadic behavior that you want to
replay from the debugger.
Each time you launch sasa
with no seed, a random one is chosen and
saved into the <graph-name>.seed
file, as well as in the rif
file.
You can use this seed to replay a simulation. The --replay
option
do this automatically by reading the <graph-name>.seed
file is it
exists.
As far as custom daemons are concerned, Lutin also has a -seed
option and a --replay
option.
Using the ocaml
toplevel #trace
directive
Since rdbg
is a wrapper around an ocaml
top-level, you can use its
directives, and in particular the #trace
one.
For example, if your algorithm is implemented in a file named p.ml
,
in order to see the calls the function step_f
, you can do the
following:
(rdbg) #trace P.step_f
However, this trace mode is not always convenient to debug programs,
and it is sometimes more handy to use ocamldebug
.
Using ocamldebug
To use ocamldebug
, you can use the --ocamldebug
(-ocd
) option of
rdbg
:
cd test/unison/
rdbg --sasa -ocd -sut "sasa ring.dot -sd -seed 42"
(ocd) break @ unison 23
(ocd) run
nb: rdbg --sasa -ocd
launches ocamldebug luretteSession/luretteSession<some
integer>
. This is good to know if you need to relaunch ocamldebug
(or to launch it via emacs
).
Printing 's Algo.neighbor
values from ocamldebug
If you want to print values of variables of type 's Algo.neighbor
,
you can use the Algo.fmt_print_neighbor
function. To be able to use
it from ocamldebug
, you first need to load and install the
Algo.fmt_print_neighbor
printer:
dir $OPAM_SWITCH_PREFIX/lib/sasacore
dir $OPAM_SWITCH_PREFIX/lib/sasa
dir $OPAM_SWITCH_PREFIX/lib/algo
dir $OPAM_SWITCH_PREFIX/lib/lutils
dir $OPAM_SWITCH_PREFIX/lib/ocamlgraph/
load_printer str.cma
load_printer nums.cma
load_printer graph.cma
load_printer lutils.cma
load_printer sasacore.cma
load_printer algo.cma
install_printer Algo.fmt_print_neighbor
nb: you can put the instructions above can be in the .ocamldebug
resource file.
(ocd) print nl