debugging 用dune调试

wj8zmpe1  于 2023-06-23  发布在  其他
关注(0)|答案(2)|浏览(118)

我知道OCaml调试工具(先用ocamlc -g <file>编译,然后运行ocamldebug <output>),以及顶层(both covered here)中的函数调用跟踪功能。但是,我似乎找不到任何关于dune的调试版本的信息。这可能吗?有人能给我指个方向吗?谢谢你!

elcex8rz

elcex8rz1#

-g标志默认存在于所有构建概要文件中,所以简单的回答是您不需要做任何事情。作为一个专业提示,如果你想看看什么标志设置默认使用

dune printenv .

或者对于给定的建筑轮廓,例如,对于release

dune printenv --profile release .

在一般情况下,使用envlibraryexecutableexecutables节接受并具有相应范围的flagsocamlc_flagsocamlopt_flags字段添加标志。如果您希望您的标志被全局应用,则需要将相应的标志字段添加到env节中,例如:

(env
 (release
  (ocamlopt_flags (:standard -O3))))

这里:standard扩展为标准标志集。
还需要知道的是,OCaml本地可执行文件(使用ocamlopt编译为机器代码的可执行文件)不能与ocamldebug一起工作。您可以使用gdb,OCaml支持得很好,也可以使用字节码可执行文件。

qacovj5a

qacovj5a2#

您可以在字节码中构建dune项目并在ocamldebug中执行它。
在您选择的目录中,写入以下dune文件:

;; This declares the hello_world executable implemented by hello_world.ml
;; to be build as native (.exe) or bytecode (.bc) version.
(executable
 (name hello_world)
 (modes byte exe))

这个hello_world.ml文件:

print_endline "Hello, world!"

并构建它:

dune build hello_world.bc # (*.bc for bytecode, *.exe for native)

可执行文件将构建为_build/default/hello_world.bc。然后可执行文件可以在ocamldebug中运行。

dune build hello_world.bc
ocamldebug _build/default/hello_world.bc

需要注意的是,ocamlddebug 5.0.0及以下版本不支持派生多个域进行并行编程。

对于执行,可以使用dune exec ./hello_world.bc在一个步骤中构建和运行可执行文件。

相关问题