Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn on `exception stack trace` for OCaml `Toplevel`?

in Toplevel, how to turn on the stack trace for exceptions?

simple question, don't know how to ask more in details.

like image 291
Jackson Tale Avatar asked Mar 02 '13 01:03

Jackson Tale


People also ask

How to trace a function in OCaml?

Tutorial: How to trace a function in OCaml. Use #trace. For example, to trace function f:

How to debug OCaml programs in interactive toplevel?

Tracing functions calls, which works in the interactive toplevel. The OCaml debugger, which allows analysing programs compiled with ocamlc. Tracing functions calls in the toplevel The simplest way to debug programs in the toplevel is to follow the function calls, by “tracing” the faulty function:

How do I raise an exception in OCaml?

This constructor is pre-defined in the standard library and is one of the more common exceptions that OCaml programmers use. There is a convenient function failwith : string -> 'a in the standard library that raises Failure. That is, failwith s is equivalent to raise (Failure s). The expression e is what might raise an exception.

How do I run OCaml From a toplevel?

The ~/.ocamlinit file is executed as soon as you start up the toplevel. For regular ocaml, you want to insert the #use "topfind;;" line in there. Note also the ;; that follows every phrase in the toplevel.


1 Answers

This used to not be easily possible (only code compiled outside the toplevel would support backtraces), but since OCaml 4.03.0 (released in April 2016) the toplevel supports backtraces, thanks to the contributions of whitequark and Jake Donham.

Just run the toplevel with OCAMLRUNPARAM=b ocaml to get backtraces. Of course, compiled code that you want to link and use from the toplevel should be compiled with -g to contain backtrace information -- otherwise you will only see the part of the call stack that calls functions defined from the toplevel.

like image 57
gasche Avatar answered Oct 25 '22 23:10

gasche