Function 如何在顶层打印函数调用和回溯?
我正在尝试获取函数调用的回溯。我想知道是否有人知道如何在顶层执行此操作。指令对跟踪函数非常有用,例如Function 如何在顶层打印函数调用和回溯?,function,debugging,ocaml,ocaml-toplevel,Function,Debugging,Ocaml,Ocaml Toplevel,我正在尝试获取函数调用的回溯。我想知道是否有人知道如何在顶层执行此操作。指令对跟踪函数非常有用,例如 # let rec f x = if x > 0 then f (x - 1) else "done";; val f : int -> string = <fun> # #trace f;; f is now traced. # f 12;; f <-- 12 f <-- 11 f <-- 10 ... 不要忘记,在重新定义函数后,需要再次调用#tr
# let rec f x = if x > 0 then f (x - 1) else "done";;
val f : int -> string = <fun>
# #trace f;;
f is now traced.
# f 12;;
f <-- 12
f <-- 11
f <-- 10
...
不要忘记,在重新定义函数后,需要再次调用#trace
,因为从顶层的角度来看,这是一个新函数,尽管它具有相同的名称
要取消跟踪函数f
请使用#取消跟踪f
,要取消跟踪当前跟踪的所有函数,请使用#取消跟踪所有
此外,您可能会发现有用的Printexc.get\u callstack
函数,如果您使用Printexc.record\u bactrace true
启用跟踪记录,则将显示当前的调用堆栈
#trace f;;
#trace g;;