1
Debugging from Coq toplevel using Caml trace mechanism
2
======================================================
4
1. Launch bytecode version of Coq (coqtop.byte or coqtop -byte)
5
2. Access Ocaml toplevel using vernacular command 'Drop.'
6
3. Install load paths and pretty printers for terms, idents, ... using
7
Ocaml command '#use "base_include";;' (use '#use "include";;' for a rawer
9
4. Use #trace to tell which function(s) to trace
10
5. Go back to Coq toplevel with 'go();;'
11
6. Test your Coq command and observe the result of tracing your functions
12
7. Freely switch from Coq to Ocaml toplevels with 'Drop.' and 'go();;'
14
Hints: To remove high-level pretty-printing features (coercions,
15
notations, ...), use "Set Printing All". It will affect the #trace
18
Debugging from Caml debugger
19
============================
21
Needs tuareg mode in Emacs
22
Coq must be configured with -debug and -local (./configure -debug -local)
25
2. give the binary name bin/coqtop.byte
26
3. give ../dev/ocamldebug-coq
27
4. source db (to get pretty-printers)
28
5. add breakpoints with C-x C-a C-b from the buffer displaying the ocaml
30
6. get more help from ocamldebug manual
37
print x (abbreviated into p x)
41
- To debug a failure/error/anomaly, add a breakpoint in
42
Vernac.vernac_com at the with clause of the "try ... interp com
43
with ..." block, then go "back" a few steps to find where the
44
failure/error/anomaly has been raised
45
- Alternatively, for an error or an anomaly, add breakpoints in the middle
46
of each of error* functions or anomaly* functions in lib/util.ml
47
- If "source db" fails, recompile printers.cma with
48
"make dev/printers.cma" and try again
50
Global gprof-based profiling
51
============================
53
Coq must be configured with option -profile
55
1. Run native Coq which must end normally (use Quit or option -batch)
56
2. gprof ./coqtop gmon.out
58
Per function profiling
59
======================
61
1. To profile function foo in file bar.ml, add the following lines, just
62
after the definition of the function:
64
let fookey = Profile.declare_profile "foo";;
65
let foo a b c = Profile.profile3 fookey foo a b c;;
67
where foo is assumed to have three arguments (adapt using
68
Profile.profile1, Profile. profile2, etc).
70
This has the effect to cumulate the time passed in foo under a
71
line of name "foo" which is displayed at the time coqtop exits.