等同于ocamldebug中ocamltop的`#use`指令?

时间:2013-09-27 09:15:46

标签: debugging printing ocaml printers coq

在ocamltop中(加载我的文件后),我可以运行以下命令

#cd "/afs/csail.mit.edu/u/j/jgross/coq-HoTT/";;
#directory "/afs/csail.mit.edu/u/j/jgross/coq-HoTT/";;
#directory "/afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev";;
#use "dev/include";;
#trace <some_function>

但我无法追踪未导出的函数,因此我想通过ocamldebug逐步执行函数。但是,当我尝试打印我想看到的内容时,我会得到f : Term.constr = <abstr>之类的内容。所以我想安装include文件中的打印机,它以

开头
#cd ".";;
#use "base_include";;

#install_printer  (* pp_stdcmds *) pppp;;

#install_printer  (* pattern *) pppattern;;
#install_printer  (* glob_constr *) ppglob_constr;;

#install_printer  (* constr *) ppconstr;;
#install_printer  (* constr_substituted *) ppsconstr;;

base_include看起来大致相似

#cd".";;
#directory "parsing";;
#directory "interp";;
...

#directory "+camlp4";; (* lazy solution: add both of camlp4/5 so that *)
#directory "+camlp5";; (* Gramext is found in top_printers.ml *)

#use "top_printers.ml";;
#use "vm_printers.ml";;

#install_printer  (* identifier *) ppid;;
...

(* Open main files *)

open Names
open Term
open Typeops
open Term_typing
open Univ
...

所以在ocamldebug中,我尝试

(ocd) directory /afs/csail.mit.edu/u/j/jgross/coq-HoTT/
Directories : /afs/csail.mit.edu/u/j/jgross/coq-HoTT/ ...
(ocd) directory /afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev
Directories : /afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev ...
(ocd) use /afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev/include
Unknown command.
(ocd) source /afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev/include
Syntax error.
(ocd) source "/afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev/include"
Syntax error.
(ocd) load_printer /afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev/include
Error during code loading: /afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev/include is not a bytecode object file
(ocd) load_printer top_printers.ml
Error during code loading: /afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev/top_printers.ml is not a bytecode object file
(ocd) load_printer top_printers
Cannot find file top_printers
(ocd) shell ls /afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev/
base_db           dynlink.cmx        ocamldebug-coq             set_raw_db         vm_printers.cmi
base_include      dynlink.ml         ocamldebug-coq.template    TODO               vm_printers.cmo
db                dynlink.ml.d       ocamldoc                   tools              vm_printers.ml
db_printers.ml    dynlink.o          ocamlopt_shared_os5fix.sh  top_printers.cmi   vm_printers.ml.d
db_printers.ml.d  header             printers.cma               top_printers.cmo
doc               include            printers.mllib             top_printers.ml
dynlink.cmi       macosify_accel.sh  printers.mllib.d           top_printers.ml.d
dynlink.cmo       Makefile.oug       README                     v8-syntax
(ocd) load_printer top_printers.cmi
Error during code loading: /afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev/top_printers.cmi is not a bytecode object file
(ocd) load_printer top_printers.cmo
Error during code loading: error while linking /afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev/top_printers.cmo.
Reference to undefined global `Pp'
(ocd) directory +camlp5
...
(ocd) directory +camlp4
...
(ocd) load_printer top_printers.cmo
Error during code loading: error while linking /afs/csail.mit.edu/u/j/jgross/coq-HoTT/dev/top_printers.cmo.
Reference to undefined global `Pp'

那么如何加载这些打印机呢? (作为参考,目录结构是https://github.com/HoTT/coq的目录结构。)

1 个答案:

答案 0 :(得分:0)

似乎你正试图在ocamldebug中使用顶级指令(以#开头的行),这些指令对这些指令一无所知。您必须使用调试器命令与ocamldebug通信,有关详细信息,请参阅ocamldebug documentation.

加载和安装打印机看起来像这样:

directory dependencies
load_printer "printers.cmo"
install_printer Printers.pp_thing

请注意显式模块名称 - 没有#use而没有open。另请注意,ocamldebug将在其目录列表中搜索printers.cmo的依赖项。如果您收到未定义的全局错误,则可能需要在该列表中添加一些条目。

一旦一切正常,你将不想再次输入所有垃圾。将它全部放在一个文件中,比如printers.debug,然后使用source命令加载它:

source printers.debug